From 31e40ecc826a60cddb166a6e1035012677d8fe38 Mon Sep 17 00:00:00 2001 From: Evan Fiordeliso Date: Fri, 10 Nov 2023 00:58:09 -0500 Subject: [PATCH] Remove executable from args in root --- command.go | 22 ++++++++++++---------- examples/hello-world/go.mod | 2 +- examples/hello-world/go.sum | 2 ++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/command.go b/command.go index 2ab1822..7717868 100644 --- a/command.go +++ b/command.go @@ -37,21 +37,23 @@ func (c *Command) ApplyOptions(options ...Option) { } func (c *Command) Execute(args []string) { - if len(args) == 0 { - return + if c.isRoot { + args = args[1:] } - for _, subcommand := range c.Subcommands { - if subcommand.Name == args[0] { - subcommand.Execute(args[1:]) - return - } - - for _, alias := range subcommand.Aliases { - if alias == args[0] { + if len(args) > 0 { + for _, subcommand := range c.Subcommands { + if subcommand.Name == args[0] { subcommand.Execute(args[1:]) return } + + for _, alias := range subcommand.Aliases { + if alias == args[0] { + subcommand.Execute(args[1:]) + return + } + } } } diff --git a/examples/hello-world/go.mod b/examples/hello-world/go.mod index 667afe3..f21ce5d 100644 --- a/examples/hello-world/go.mod +++ b/examples/hello-world/go.mod @@ -2,4 +2,4 @@ module go.fifitido.net/cmd/examples/hello-world go 1.21.3 -require go.fifitido.net/cmd v0.0.0-20231110043437-c32ce2efcd5f +require go.fifitido.net/cmd v0.0.0-20231110054944-def39983fdfa diff --git a/examples/hello-world/go.sum b/examples/hello-world/go.sum index 8622aee..116ba1d 100644 --- a/examples/hello-world/go.sum +++ b/examples/hello-world/go.sum @@ -1,2 +1,4 @@ go.fifitido.net/cmd v0.0.0-20231110043437-c32ce2efcd5f h1:v+sjO+t6cGEtDhStOnuypYBrkOMO4suiDVxL93rOUCs= go.fifitido.net/cmd v0.0.0-20231110043437-c32ce2efcd5f/go.mod h1:8SaDxCG1m6WwShUlZApSbNleCvV7oTfqZIyYu4aAqO0= +go.fifitido.net/cmd v0.0.0-20231110054944-def39983fdfa h1:Z62sZG2rnKMqa0jI+WD1t8vO9ESQsQa4j6ad9OFeREM= +go.fifitido.net/cmd v0.0.0-20231110054944-def39983fdfa/go.mod h1:8SaDxCG1m6WwShUlZApSbNleCvV7oTfqZIyYu4aAqO0=