create cli command to print the version and the build commit and date
Pantani danpantani@gmail.com
Wed, 17 Mar 2021 09:07:03 -0300
1 files changed,
31 insertions(+),
8 deletions(-)
jump to
M
cli/node/main.go
→
cli/node/main.go
@@ -34,6 +34,22 @@ modeSync = "sync"
modeCoord = "coord" ) +var ( + // Version represents the program based on the git tag + Version = "v0.1.0" + // Build represents the program based on the git commit + Build = "dev" + // Date represents the date of application was built + Date = "" +) + +func cmdVersion(c *cli.Context) error { + fmt.Printf("Version = \"%v\"\n", Version) + fmt.Printf("Build = \"%v\"\n", Build) + fmt.Printf("Date = \"%v\"\n", Date) + return nil +} + func cmdGenBJJ(c *cli.Context) error { sk := babyjub.NewRandPrivKey() skBuf := [32]byte(sk)@@ -346,8 +362,8 @@
func main() { app := cli.NewApp() app.Name = "hermez-node" - app.Version = "0.1.0-alpha" - app.Flags = []cli.Flag{ + app.Version = Version + flags := []cli.Flag{ &cli.StringFlag{ Name: flagMode, Usage: fmt.Sprintf("Set node `MODE` (can be \"%v\" or \"%v\")", modeSync, modeCoord),@@ -362,16 +378,22 @@ }
app.Commands = []*cli.Command{ { + Name: "version", + Aliases: []string{}, + Usage: "Show the application version and build", + Action: cmdVersion, + }, + { Name: "importkey", Aliases: []string{}, Usage: "Import ethereum private key", Action: cmdImportKey, - Flags: []cli.Flag{ + Flags: append(flags, &cli.StringFlag{ Name: flagSK, Usage: "ethereum `PRIVATE_KEY` in hex", Required: true, - }}, + }), }, { Name: "genbjj",@@ -385,30 +407,31 @@ Aliases: []string{},
Usage: "Wipe the SQL DB (HistoryDB and L2DB) and the StateDBs, " + "leaving the DB in a clean state", Action: cmdWipeSQL, - Flags: []cli.Flag{ + Flags: append(flags, &cli.BoolFlag{ Name: flagYes, Usage: "automatic yes to the prompt", Required: false, - }}, + }), }, { Name: "run", Aliases: []string{}, Usage: "Run the hermez-node in the indicated mode", Action: cmdRun, + Flags: flags, }, { Name: "discard", Aliases: []string{}, Usage: "Discard blocks up to a specified block number", Action: cmdDiscard, - Flags: []cli.Flag{ + Flags: append(flags, &cli.Int64Flag{ Name: flagBlock, Usage: "last block number to keep", Required: false, - }}, + }), }, }