Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backport v1.7.x): add version subcommand #28

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/local/longhornctl-local.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func newCmdLonghornctlLocal() *cobra.Command {
localsubcmd.NewCmdGet(globalOpts),
},
},
{
Message: "Other Commands:",
Commands: []*cobra.Command{
localsubcmd.NewCmdVersion(),
},
},
}
groups.Add(cmd)

Expand Down
2 changes: 1 addition & 1 deletion cmd/local/subcmd/check.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package subcmd

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion cmd/local/subcmd/get.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package subcmd

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion cmd/local/subcmd/install.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package subcmd

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/local/subcmd/trim.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package subcmd

import (
"os"
Expand Down
23 changes: 23 additions & 0 deletions cmd/local/subcmd/version.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions cmd/remote/longhornctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func newCmdLonghornctl() *cobra.Command {
subcmd.NewCmdGet(globalOpts),
},
},
{
Message: "Other Commands:",
Commands: []*cobra.Command{
subcmd.NewCmdVersion(globalOpts),
},
},
}
groups.Add(cmd)

Expand Down
24 changes: 24 additions & 0 deletions cmd/remote/subcmd/version.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions pkg/consts/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const (

// The third layer of subcommands (action to the previous layers)
SubCmdStop = "stop"

// Other subcommands
SubCmdVersion = "version"
)

const (
Expand Down