diff --git a/cmd/local/longhornctl-local.go b/cmd/local/longhornctl-local.go index c10abf11..6c6b8013 100644 --- a/cmd/local/longhornctl-local.go +++ b/cmd/local/longhornctl-local.go @@ -61,6 +61,12 @@ func newCmdLonghornctlLocal() *cobra.Command { localsubcmd.NewCmdGet(globalOpts), }, }, + { + Message: "Other Commands:", + Commands: []*cobra.Command{ + localsubcmd.NewCmdVersion(), + }, + }, } groups.Add(cmd) diff --git a/cmd/local/subcmd/check.go b/cmd/local/subcmd/check.go index 253671b5..af9362f2 100644 --- a/cmd/local/subcmd/check.go +++ b/cmd/local/subcmd/check.go @@ -1,4 +1,4 @@ -package cmd +package subcmd import ( "os" diff --git a/cmd/local/subcmd/get.go b/cmd/local/subcmd/get.go index 80402483..0aece40d 100644 --- a/cmd/local/subcmd/get.go +++ b/cmd/local/subcmd/get.go @@ -1,4 +1,4 @@ -package cmd +package subcmd import ( "os" diff --git a/cmd/local/subcmd/install.go b/cmd/local/subcmd/install.go index 97419505..3de369d3 100644 --- a/cmd/local/subcmd/install.go +++ b/cmd/local/subcmd/install.go @@ -1,4 +1,4 @@ -package cmd +package subcmd import ( "fmt" diff --git a/cmd/local/subcmd/trim.go b/cmd/local/subcmd/trim.go index a2a7934c..8d0527ee 100644 --- a/cmd/local/subcmd/trim.go +++ b/cmd/local/subcmd/trim.go @@ -1,4 +1,4 @@ -package cmd +package subcmd import ( "os" diff --git a/cmd/local/subcmd/version.go b/cmd/local/subcmd/version.go new file mode 100644 index 00000000..9f5b0265 --- /dev/null +++ b/cmd/local/subcmd/version.go @@ -0,0 +1,23 @@ +package subcmd + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/longhorn/cli/meta" + "github.com/longhorn/cli/pkg/consts" +) + +func NewCmdVersion() *cobra.Command { + cmd := &cobra.Command{ + Use: consts.SubCmdVersion, + Short: fmt.Sprintf("Print %s version", consts.CmdLonghornctlLocal), + + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(meta.Version) + }, + } + + return cmd +} diff --git a/cmd/remote/longhornctl.go b/cmd/remote/longhornctl.go index 6a0e8438..2789949e 100644 --- a/cmd/remote/longhornctl.go +++ b/cmd/remote/longhornctl.go @@ -63,6 +63,12 @@ func newCmdLonghornctl() *cobra.Command { subcmd.NewCmdGet(globalOpts), }, }, + { + Message: "Other Commands:", + Commands: []*cobra.Command{ + subcmd.NewCmdVersion(globalOpts), + }, + }, } groups.Add(cmd) diff --git a/cmd/remote/subcmd/version.go b/cmd/remote/subcmd/version.go new file mode 100644 index 00000000..341ce21a --- /dev/null +++ b/cmd/remote/subcmd/version.go @@ -0,0 +1,24 @@ +package subcmd + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/longhorn/cli/meta" + "github.com/longhorn/cli/pkg/consts" + "github.com/longhorn/cli/pkg/types" +) + +func NewCmdVersion(globalOpts *types.GlobalCmdOptions) *cobra.Command { + cmd := &cobra.Command{ + Use: consts.SubCmdVersion, + Short: fmt.Sprintf("Print %s version", consts.CmdLonghornctlRemote), + + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(meta.Version) + }, + } + + return cmd +} diff --git a/pkg/consts/cmd.go b/pkg/consts/cmd.go index 5fb199a3..ee0de4cc 100644 --- a/pkg/consts/cmd.go +++ b/pkg/consts/cmd.go @@ -21,6 +21,9 @@ const ( // The third layer of subcommands (action to the previous layers) SubCmdStop = "stop" + + // Other subcommands + SubCmdVersion = "version" ) const (