Skip to content

Commit

Permalink
fix: expose version
Browse files Browse the repository at this point in the history
Signed-off-by: cpendery <[email protected]>
  • Loading branch information
cpendery committed Mar 15, 2024
1 parent 69f4b30 commit 692c2af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ var (
RunE: rootExec,
SilenceUsage: true,
}
rootShell string
rootShell string
Version string = ""
versionFlag bool
)

func init() {
rootCmd.Flags().StringVarP(&rootShell, "shell", "s", "", fmt.Sprintf("the shell to create completions for, valid shells: %q", shell.ValidShells))
rootCmd.Flags().BoolVar(&versionFlag, "version", false, "print release version")
}

func rootExec(cmd *cobra.Command, args []string) error {
if versionFlag {
fmt.Println(Version)
return nil
}
if rootShell == "" || !slices.Contains(shell.ValidShells, rootShell) {
return fmt.Errorf("provide a valid shell to generate completions for via the --shell flag, received %s", rootShell)
}
Expand All @@ -40,7 +47,8 @@ func rootExec(cmd *cobra.Command, args []string) error {
return nil
}

func Execute() {
func Execute(version string) {
Version = version
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/cpendery/kaldo/cmd"
)

var Version string

func main() {
cmd.Execute()
cmd.Execute(Version)
}

0 comments on commit 692c2af

Please sign in to comment.