enhancement(cli): group commands by topic
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
package command
|
||||||
|
|
||||||
|
const (
|
||||||
|
CommandGroupServer = "Server"
|
||||||
|
CommandGroupServices = "Service"
|
||||||
|
CommandGroupStorage = "Storage"
|
||||||
|
)
|
||||||
@@ -33,8 +33,9 @@ import (
|
|||||||
// DecomposedfsCommand is the entrypoint for the groups command.
|
// DecomposedfsCommand is the entrypoint for the groups command.
|
||||||
func DecomposedfsCommand(cfg *config.Config) *cobra.Command {
|
func DecomposedfsCommand(cfg *config.Config) *cobra.Command {
|
||||||
decomposedCmd := &cobra.Command{
|
decomposedCmd := &cobra.Command{
|
||||||
Use: "decomposedfs",
|
Use: "decomposedfs",
|
||||||
Short: `cli tools to inspect and manipulate a decomposedfs storage.`,
|
Short: `cli tools to inspect and manipulate a decomposedfs storage.`,
|
||||||
|
GroupID: CommandGroupStorage,
|
||||||
}
|
}
|
||||||
decomposedCmd.AddCommand(metadataCmd(cfg), checkCmd(cfg))
|
decomposedCmd.AddCommand(metadataCmd(cfg), checkCmd(cfg))
|
||||||
return decomposedCmd
|
return decomposedCmd
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package helper
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SubcommandDescription(serviceName string) string {
|
|
||||||
return fmt.Sprintf("%s service commands", serviceName)
|
|
||||||
}
|
|
||||||
@@ -17,10 +17,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// InitCommand is the entrypoint for the init command
|
// InitCommand is the entrypoint for the init command
|
||||||
func InitCommand(cfg *config.Config) *cobra.Command {
|
func InitCommand(_ *config.Config) *cobra.Command {
|
||||||
initCmd := &cobra.Command{
|
initCmd := &cobra.Command{
|
||||||
Use: "init",
|
Use: "init",
|
||||||
Short: "initialise an OpenCloud config",
|
Short: "initialise an OpenCloud config",
|
||||||
|
GroupID: CommandGroupServer,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
insecureFlag := cmd.Flag("insecure").Value.String()
|
insecureFlag := cmd.Flag("insecure").Value.String()
|
||||||
insecure := false
|
insecure := false
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ type EntryInfo struct {
|
|||||||
// PosixfsCommand is the entrypoint for the posixfs command.
|
// PosixfsCommand is the entrypoint for the posixfs command.
|
||||||
func PosixfsCommand(cfg *config.Config) *cobra.Command {
|
func PosixfsCommand(cfg *config.Config) *cobra.Command {
|
||||||
posixCmd := &cobra.Command{
|
posixCmd := &cobra.Command{
|
||||||
Use: "posixfs",
|
Use: "posixfs",
|
||||||
Short: `cli tools to inspect and manipulate a posixfs storage.`,
|
Short: `cli tools to inspect and manipulate a posixfs storage.`,
|
||||||
|
GroupID: CommandGroupStorage,
|
||||||
}
|
}
|
||||||
|
|
||||||
posixCmd.AddCommand(consistencyCmd(cfg))
|
posixCmd.AddCommand(consistencyCmd(cfg))
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ func Execute() error {
|
|||||||
|
|
||||||
for _, commandFactory := range register.Commands {
|
for _, commandFactory := range register.Commands {
|
||||||
command := commandFactory(cfg)
|
command := commandFactory(cfg)
|
||||||
|
|
||||||
|
if command.GroupID != "" && !app.ContainsGroup(command.GroupID) {
|
||||||
|
app.AddGroup(&cobra.Group{
|
||||||
|
ID: command.GroupID,
|
||||||
|
Title: command.GroupID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
app.AddCommand(command)
|
app.AddCommand(command)
|
||||||
}
|
}
|
||||||
app.SetArgs(os.Args[1:])
|
app.SetArgs(os.Args[1:])
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ func Server(cfg *config.Config) *cobra.Command {
|
|||||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return configlog.ReturnError(parser.ParseConfig(cfg, false))
|
return configlog.ReturnError(parser.ParseConfig(cfg, false))
|
||||||
},
|
},
|
||||||
|
GroupID: CommandGroupServer,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
// Prefer the in-memory registry as the default when running in single-binary mode
|
// Prefer the in-memory registry as the default when running in single-binary mode
|
||||||
r := runtime.New(cfg)
|
r := runtime.New(cfg)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/opencloud-eu/opencloud/opencloud/pkg/command/helper"
|
"fmt"
|
||||||
|
|
||||||
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
|
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/config"
|
"github.com/opencloud-eu/opencloud/pkg/config"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/config/configlog"
|
"github.com/opencloud-eu/opencloud/pkg/config/configlog"
|
||||||
@@ -268,8 +269,9 @@ var serviceCommands = []register.Command{
|
|||||||
// ServiceCommand composes a cobra command from the given inputs.
|
// ServiceCommand composes a cobra command from the given inputs.
|
||||||
func ServiceCommand(cfg *config.Config, serviceName string, subCommands []*cobra.Command, f func(*config.Config)) *cobra.Command {
|
func ServiceCommand(cfg *config.Config, serviceName string, subCommands []*cobra.Command, f func(*config.Config)) *cobra.Command {
|
||||||
command := &cobra.Command{
|
command := &cobra.Command{
|
||||||
Use: serviceName,
|
Use: serviceName,
|
||||||
Short: helper.SubcommandDescription(serviceName),
|
Short: fmt.Sprintf("%s service commands", serviceName),
|
||||||
|
GroupID: CommandGroupServices,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
configlog.Error(parser.ParseConfig(cfg, true))
|
configlog.Error(parser.ParseConfig(cfg, true))
|
||||||
f(cfg)
|
f(cfg)
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
|
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/config"
|
"github.com/opencloud-eu/opencloud/pkg/config"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/registry"
|
"github.com/opencloud-eu/opencloud/pkg/registry"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/version"
|
"github.com/opencloud-eu/opencloud/pkg/version"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
"github.com/olekukonko/tablewriter/tw"
|
"github.com/olekukonko/tablewriter/tw"
|
||||||
@@ -22,8 +23,9 @@ const (
|
|||||||
// VersionCommand is the entrypoint for the version command.
|
// VersionCommand is the entrypoint for the version command.
|
||||||
func VersionCommand(cfg *config.Config) *cobra.Command {
|
func VersionCommand(cfg *config.Config) *cobra.Command {
|
||||||
versionCmd := &cobra.Command{
|
versionCmd := &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "print the version of this binary and all running service instances",
|
Short: "print the version of this binary and all running service instances",
|
||||||
|
GroupID: CommandGroupServer,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
fmt.Println("Version: " + version.GetString())
|
fmt.Println("Version: " + version.GetString())
|
||||||
fmt.Printf("Edition: %s\n", version.Edition)
|
fmt.Printf("Edition: %s\n", version.Edition)
|
||||||
|
|||||||
Reference in New Issue
Block a user