enhancement(cli): group commands by topic

This commit is contained in:
Florian Schade
2025-12-11 14:40:46 +01:00
parent 879de39129
commit 9904e5b932
9 changed files with 36 additions and 22 deletions

View File

@@ -0,0 +1,7 @@
package command
const (
CommandGroupServer = "Server"
CommandGroupServices = "Service"
CommandGroupStorage = "Storage"
)

View File

@@ -33,8 +33,9 @@ import (
// DecomposedfsCommand is the entrypoint for the groups command.
func DecomposedfsCommand(cfg *config.Config) *cobra.Command {
decomposedCmd := &cobra.Command{
Use: "decomposedfs",
Short: `cli tools to inspect and manipulate a decomposedfs storage.`,
Use: "decomposedfs",
Short: `cli tools to inspect and manipulate a decomposedfs storage.`,
GroupID: CommandGroupStorage,
}
decomposedCmd.AddCommand(metadataCmd(cfg), checkCmd(cfg))
return decomposedCmd

View File

@@ -1,9 +0,0 @@
package helper
import (
"fmt"
)
func SubcommandDescription(serviceName string) string {
return fmt.Sprintf("%s service commands", serviceName)
}

View File

@@ -17,10 +17,11 @@ import (
)
// InitCommand is the entrypoint for the init command
func InitCommand(cfg *config.Config) *cobra.Command {
func InitCommand(_ *config.Config) *cobra.Command {
initCmd := &cobra.Command{
Use: "init",
Short: "initialise an OpenCloud config",
Use: "init",
Short: "initialise an OpenCloud config",
GroupID: CommandGroupServer,
RunE: func(cmd *cobra.Command, args []string) error {
insecureFlag := cmd.Flag("insecure").Value.String()
insecure := false

View File

@@ -40,8 +40,9 @@ type EntryInfo struct {
// PosixfsCommand is the entrypoint for the posixfs command.
func PosixfsCommand(cfg *config.Config) *cobra.Command {
posixCmd := &cobra.Command{
Use: "posixfs",
Short: `cli tools to inspect and manipulate a posixfs storage.`,
Use: "posixfs",
Short: `cli tools to inspect and manipulate a posixfs storage.`,
GroupID: CommandGroupStorage,
}
posixCmd.AddCommand(consistencyCmd(cfg))

View File

@@ -24,6 +24,14 @@ func Execute() error {
for _, commandFactory := range register.Commands {
command := commandFactory(cfg)
if command.GroupID != "" && !app.ContainsGroup(command.GroupID) {
app.AddGroup(&cobra.Group{
ID: command.GroupID,
Title: command.GroupID,
})
}
app.AddCommand(command)
}
app.SetArgs(os.Args[1:])

View File

@@ -18,6 +18,7 @@ func Server(cfg *config.Config) *cobra.Command {
PreRunE: func(cmd *cobra.Command, args []string) error {
return configlog.ReturnError(parser.ParseConfig(cfg, false))
},
GroupID: CommandGroupServer,
RunE: func(cmd *cobra.Command, args []string) error {
// Prefer the in-memory registry as the default when running in single-binary mode
r := runtime.New(cfg)

View File

@@ -1,7 +1,8 @@
package command
import (
"github.com/opencloud-eu/opencloud/opencloud/pkg/command/helper"
"fmt"
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
"github.com/opencloud-eu/opencloud/pkg/config"
"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.
func ServiceCommand(cfg *config.Config, serviceName string, subCommands []*cobra.Command, f func(*config.Config)) *cobra.Command {
command := &cobra.Command{
Use: serviceName,
Short: helper.SubcommandDescription(serviceName),
Use: serviceName,
Short: fmt.Sprintf("%s service commands", serviceName),
GroupID: CommandGroupServices,
RunE: func(cmd *cobra.Command, args []string) error {
configlog.Error(parser.ParseConfig(cfg, true))
f(cfg)

View File

@@ -4,11 +4,12 @@ import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
"github.com/opencloud-eu/opencloud/pkg/config"
"github.com/opencloud-eu/opencloud/pkg/registry"
"github.com/opencloud-eu/opencloud/pkg/version"
"github.com/spf13/cobra"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/tw"
@@ -22,8 +23,9 @@ const (
// VersionCommand is the entrypoint for the version command.
func VersionCommand(cfg *config.Config) *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "print the version of this binary and all running service instances",
Use: "version",
Short: "print the version of this binary and all running service instances",
GroupID: CommandGroupServer,
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Version: " + version.GetString())
fmt.Printf("Edition: %s\n", version.Edition)