Skip to content

Commit

Permalink
Alias --version to the version command (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
felicianotech committed Jan 20, 2022
1 parent 383017a commit 7739354
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sonar/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ import (

var cfgFile string
var dockerPassword string
var versionFl bool

var rootCmd = &cobra.Command{
Use: "sonar",
Short: "A Docker utility tool",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if versionFl {
versionCmd.Run(cmd, []string{"--short"})
} else {
cmd.Help()
}
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -32,6 +40,7 @@ func init() {

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/sonar.yml)")
rootCmd.PersistentFlags().StringVar(&dockerPassword, "password", "", "Docker password")
rootCmd.Flags().BoolVar(&versionFl, "version", false, "runs version --short")
viper.BindPFlag("pass", rootCmd.PersistentFlags().Lookup("password"))
}

Expand Down

0 comments on commit 7739354

Please sign in to comment.