mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-23 22:29:59 -05:00
fix: list service child commands the service is called without arguments
This commit is contained in:
@@ -22,18 +22,9 @@ func Execute() error {
|
||||
Short: "opencloud",
|
||||
})
|
||||
|
||||
for _, fn := range register.Commands {
|
||||
cmd := fn(cfg)
|
||||
// if the command has a RunE function, it is a subcommand of root
|
||||
// if not it is a consumed root command from the services
|
||||
// wee need to overwrite the RunE function to get the help output there
|
||||
if cmd.RunE == nil {
|
||||
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
cmd.Help()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
app.AddCommand(cmd)
|
||||
for _, commandFactory := range register.Commands {
|
||||
command := commandFactory(cfg)
|
||||
app.AddCommand(command)
|
||||
}
|
||||
app.SetArgs(os.Args[1:])
|
||||
ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP)
|
||||
|
||||
@@ -52,7 +52,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var svccmds = []register.Command{
|
||||
var serviceCommands = []register.Command{
|
||||
func(cfg *config.Config) *cobra.Command {
|
||||
return ServiceCommand(cfg, cfg.Activitylog.Service.Name, activitylog.GetCommands(cfg.Activitylog), func(c *config.Config) {
|
||||
cfg.Activitylog.Commons = cfg.Commons
|
||||
@@ -265,9 +265,9 @@ var svccmds = []register.Command{
|
||||
},
|
||||
}
|
||||
|
||||
// ServiceCommand is the entry point for the all service commands.
|
||||
func ServiceCommand(cfg *config.Config, serviceName string, subcommands []*cobra.Command, f func(*config.Config)) *cobra.Command {
|
||||
svcCommand := &cobra.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),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@@ -276,12 +276,21 @@ func ServiceCommand(cfg *config.Config, serviceName string, subcommands []*cobra
|
||||
return nil
|
||||
},
|
||||
}
|
||||
svcCommand.AddCommand(subcommands...)
|
||||
return svcCommand
|
||||
|
||||
// if a service should have multiple child commands,
|
||||
// we expect that at least one argument is needed;
|
||||
// this helps cobra to force display all available child commands.
|
||||
if len(subCommands) > 0 {
|
||||
command.Args = cobra.MinimumNArgs(1)
|
||||
}
|
||||
|
||||
command.AddCommand(subCommands...)
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
func init() {
|
||||
for _, c := range svccmds {
|
||||
for _, c := range serviceCommands {
|
||||
register.AddCommand(c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package register
|
||||
|
||||
import (
|
||||
"github.com/opencloud-eu/opencloud/pkg/config"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/opencloud-eu/opencloud/pkg/config"
|
||||
)
|
||||
|
||||
var (
|
||||
// Commands defines the slice of commands.
|
||||
Commands = []Command{}
|
||||
// Commands define the slice of commands.
|
||||
Commands []Command
|
||||
)
|
||||
|
||||
// Command defines the register command.
|
||||
|
||||
Reference in New Issue
Block a user