Skip to content

Commit 9fabfe6

Browse files
authored
refactor: replace version subcommand with --version flag (#12)
Use cobra's built-in Version field and SetVersionTemplate instead of a separate 'version' subcommand. This follows the more common CLI convention of using a --version/-v flag.
1 parent 0214727 commit 9fabfe6

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

internal/cli/root.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ to define and manage system resources in an idempotent way.
3838
3939
Resources include files, directories, packages, services, cron jobs,
4040
exec commands, and hostname configuration.`,
41+
Version: version,
4142
SilenceUsage: true,
4243
}
4344

45+
rootCmd.SetVersionTemplate(fmt.Sprintf("hostcfg %s\n commit: %s\n built: %s\n", version, commit, date))
46+
4447
// Global flags
4548
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "",
4649
"Path to config file or directory (default: hostcfg.hcl or current directory)")
@@ -56,25 +59,11 @@ exec commands, and hostname configuration.`,
5659
rootCmd.AddCommand(NewApplyCmd())
5760
rootCmd.AddCommand(NewValidateCmd())
5861
rootCmd.AddCommand(NewFactsCmd())
59-
rootCmd.AddCommand(NewVersionCmd())
6062
rootCmd.AddCommand(NewUpdateCmd())
6163

6264
return rootCmd
6365
}
6466

65-
// NewVersionCmd creates the version command
66-
func NewVersionCmd() *cobra.Command {
67-
return &cobra.Command{
68-
Use: "version",
69-
Short: "Print version information",
70-
Run: func(cmd *cobra.Command, args []string) {
71-
fmt.Printf("hostcfg %s\n", version)
72-
fmt.Printf(" commit: %s\n", commit)
73-
fmt.Printf(" built: %s\n", date)
74-
},
75-
}
76-
}
77-
7867
// Execute runs the CLI
7968
func Execute() {
8069
rootCmd := NewRootCmd()

0 commit comments

Comments
 (0)