From 234268028ee9ef7c164c9e333847a42750a70866 Mon Sep 17 00:00:00 2001 From: Pantani Date: Wed, 17 Mar 2021 09:07:03 -0300 Subject: [PATCH] create cli command to print the version and the build commit and date --- cli/node/main.go | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/cli/node/main.go b/cli/node/main.go index 9a3f2b6..217aa85 100644 --- a/cli/node/main.go +++ b/cli/node/main.go @@ -34,6 +34,22 @@ const ( 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 getConfig(c *cli.Context) (*Config, error) { 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), @@ -361,17 +377,23 @@ func main() { } 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 @@ func main() { 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, - }}, + }), }, }