Skip to content

Commit

Permalink
adding version command
Browse files Browse the repository at this point in the history
  • Loading branch information
luthermonson committed Oct 16, 2020
1 parent 92fd4ea commit c978af6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ func Run(c *cli.Context) error {

func Commands() []*cli.Command {
return []*cli.Command{
Add(),
Backup(),
Check(),
Clean(),
Debug(),
Edit(),
List(),
Add(),
Remove(),
Debug(),
Backup(),
Restore(),
Edit(),
Clean(),
Version(),
}
}

Expand Down
19 changes: 19 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)

func Version() *cli.Command {
return &cli.Command{
Name: "version",
Usage: "",
Action: version,
}
}

func version(c *cli.Context) error {
logrus.Infof("goodhosts %s", c.Context.Value("version"))
return nil
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"
"io/ioutil"
"os"
Expand All @@ -12,13 +13,16 @@ import (
"github.com/urfave/cli/v2"
)

var version = "dev"

func main() {
app := &cli.App{
Name: "goodhosts",
Usage: "manage your hosts file goodly",
Action: cmd.DefaultAction,
Commands: cmd.Commands(),
Before: func(ctx *cli.Context) error {
ctx.Context = context.WithValue(ctx.Context, "version", version)
if ctx.Bool("debug") {
logrus.SetLevel(logrus.DebugLevel)
} else {
Expand Down

0 comments on commit c978af6

Please sign in to comment.