Skip to content

Commit

Permalink
Add jkl version flags to output only the version or git commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanfetch committed Jan 4, 2023
1 parent 5491d71 commit 1fa1cd6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,27 @@ func RunCLI(args []string, output, errOutput io.Writer) error {
rootCmd.CompletionOptions.DisableDefaultCmd = true // Until completion behavior is tested
rootCmd.PersistentFlags().BoolVarP(&debugFlagEnabled, "debug", "D", false, "Enable debug output (also enabled by setting the JKL_DEBUG environment variable to any value).")

var versionOnly, commitOnly bool
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display the jkl version and git commit",
Long: "Display the jkl version and git commit",
Aliases: []string{"ver", "v"},
Run: func(cmd *cobra.Command, args []string) {
if versionOnly {
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", Version)
return
}
if commitOnly {
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", GitCommit)
return
}
fmt.Fprintf(cmd.OutOrStdout(), "%s version %s, git commit %s\n", callMeProgName, Version, GitCommit)
},
}
versionCmd.Flags().BoolVarP(&versionOnly, "version-only", "v", false, "Only output the jkl version.")
versionCmd.Flags().BoolVarP(&commitOnly, "commit-only", "c", false, "Only output the jkl git commit.")
versionCmd.MarkFlagsMutuallyExclusive("version-only", "commit-only")
rootCmd.AddCommand(versionCmd)

var installCmd = &cobra.Command{
Expand Down

0 comments on commit 1fa1cd6

Please sign in to comment.