Skip to content

Commit

Permalink
Merge pull request #3 from PagoPlus/feat/add-command-to-get-app-versi…
Browse files Browse the repository at this point in the history
…on#86b3a5vwk

[FEAT] add command to get app version (CU #86b3a5vwk)
  • Loading branch information
fermuch authored Jan 8, 2025
2 parents eaf00ee + ebc8082 commit ce67167
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ builds:
goarch:
- amd64
- arm64
tool: "tinygo"
hooks:
pre:
- mkdir -p {{ dir .Path }}
binary: numscript
ldflags:
- -X main.Version=v{{ .Version }}
Expand Down
29 changes: 26 additions & 3 deletions internal/numscript/numscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ type RunInputOpts struct {
Balances interpreter.Balances `json:"balances"`
}

var Version string

func version() string {
if Version == "" {
return "dev"
} else {
return Version
}
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Shows the app version",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(version())
},
}

func SeverityToString(s analysis.Severity) string {
switch s {
case analysis.ErrorSeverity:
Expand Down Expand Up @@ -157,9 +176,10 @@ var runCmd = &cobra.Command{
}

var rootCmd = &cobra.Command{
Use: "numscript",
Short: "Numscript cli",
Long: "Numscript cli",
Use: "numscript",
Short: "Numscript cli",
Long: "Numscript cli",
Version: version(),
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
Expand All @@ -173,8 +193,11 @@ func main() {
}
}()

rootCmd.SetVersionTemplate(rootCmd.Version)

rootCmd.AddCommand(checkCmd)
rootCmd.AddCommand(runCmd)
rootCmd.AddCommand(versionCmd)

rootCmd.Execute()
}

0 comments on commit ce67167

Please sign in to comment.