Remove executable from args in root

This commit is contained in:
Evan Fiordeliso 2023-11-10 00:58:09 -05:00
parent def39983fd
commit 31e40ecc82
3 changed files with 15 additions and 11 deletions

View File

@ -37,10 +37,11 @@ func (c *Command) ApplyOptions(options ...Option) {
} }
func (c *Command) Execute(args []string) { func (c *Command) Execute(args []string) {
if len(args) == 0 { if c.isRoot {
return args = args[1:]
} }
if len(args) > 0 {
for _, subcommand := range c.Subcommands { for _, subcommand := range c.Subcommands {
if subcommand.Name == args[0] { if subcommand.Name == args[0] {
subcommand.Execute(args[1:]) subcommand.Execute(args[1:])
@ -54,6 +55,7 @@ func (c *Command) Execute(args []string) {
} }
} }
} }
}
if c.Run != nil { if c.Run != nil {
c.Run(args) c.Run(args)

View File

@ -2,4 +2,4 @@ module go.fifitido.net/cmd/examples/hello-world
go 1.21.3 go 1.21.3
require go.fifitido.net/cmd v0.0.0-20231110043437-c32ce2efcd5f require go.fifitido.net/cmd v0.0.0-20231110054944-def39983fdfa

View File

@ -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 h1:v+sjO+t6cGEtDhStOnuypYBrkOMO4suiDVxL93rOUCs=
go.fifitido.net/cmd v0.0.0-20231110043437-c32ce2efcd5f/go.mod h1:8SaDxCG1m6WwShUlZApSbNleCvV7oTfqZIyYu4aAqO0= 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=