mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-16 17:45:39 -06:00
enhancement(cli): group commands by topic
This commit is contained in:
7
opencloud/pkg/command/command.go
Normal file
7
opencloud/pkg/command/command.go
Normal file
@@ -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.
|
||||
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
|
||||
|
||||
@@ -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
|
||||
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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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:])
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user