11package cli
22
33import (
4+ "fmt"
45 "os"
56 "path/filepath"
67
1920
2021// rootCmd represents the base command when called without any subcommands
2122var rootCmd = & cobra.Command {
22- Use : "local-data" ,
23- Short : "Manage a local Hadoop (HDFS + YARN) + Hive stack" ,
23+ Use : "local-data" ,
24+ Version : "dev" ,
25+ Short : "Manage a local Hadoop (HDFS + YARN) + Hive stack" ,
2426 Long : `local-data: manage a local Hadoop (HDFS + YARN) + Hive stack.
2527
2628A modular CLI to manage HDFS/YARN/Hive/Spark in one place with runtime
@@ -30,6 +32,14 @@ config overlays and profile-based configuration.`,
3032 // Run: func(cmd *cobra.Command, args []string) { },
3133}
3234
35+ func SetVersion (v string ) {
36+ if v == "" {
37+ return
38+ }
39+ rootCmd .Version = v
40+ rootCmd .SetVersionTemplate ("{{.Version}}\n " )
41+ }
42+
3343// Execute adds all child commands to the root command and sets flags appropriately.
3444// This is called by main.main(). It only needs to happen once to the rootCmd.
3545func Execute () error {
@@ -47,6 +57,16 @@ func init() {
4757 rootCmd .AddCommand (service .NewStatusCmd (getPaths ))
4858 rootCmd .AddCommand (NewLogsCmd (getPaths ))
4959
60+ // Version command (explicit, for script-friendly `local-data version`)
61+ rootCmd .AddCommand (& cobra.Command {
62+ Use : "version" ,
63+ Short : "Print the local-data CLI version" ,
64+ Args : cobra .NoArgs ,
65+ Run : func (cmd * cobra.Command , args []string ) {
66+ fmt .Fprintln (os .Stdout , rootCmd .Version )
67+ },
68+ })
69+
5070 // Add wrapper commands
5171 rootCmd .AddCommand (wrappers .NewHDFSCmd (getPaths ))
5272 rootCmd .AddCommand (wrappers .NewHiveCmd (getPaths ))
0 commit comments