diff --git a/docs/build.rst b/docs/build.rst index 6a383fd13..4d187845f 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -46,7 +46,7 @@ Run-time dependencies: Build-time dependencies: * ``gcc`` or ``clang`` -* ``go >= 1.17`` (see :file:`go.mod` for go packages used during building) +* ``go >= 1.18`` (see :file:`go.mod` for go packages used during building) * ``pkg-config`` * For building on Linux in addition to the above dependencies you might also need to install the following packages, if they are not already installed by diff --git a/tools/cli/types.go b/tools/cli/types.go index 2e59c6bcb..deacf154e 100644 --- a/tools/cli/types.go +++ b/tools/cli/types.go @@ -241,7 +241,7 @@ func (self *OptionGroup) FindOption(name_with_hyphens string) *Option { // }}} type Command struct { - Name string + Name, ExeName string Usage, HelpText string Hidden bool AllowOptionsAfterArgs int @@ -357,7 +357,19 @@ func (self *Command) Root(args []string) *Command { return p } -func (self *Command) CommandStringForUsage(args []string) (*Command, error) { +func (self *Command) CommandStringForUsage(args []string) string { + names := make([]string, 0, 8) + p := self + for p != nil { + if p.Name != "" { + names = append(names, p.Name) + } else if p.ExeName != "" { + names = append(names, p.Name) + } + p = p.Parent + } + utils.Reverse(names) + return strings.Join(names, " ") } func (self *Command) ParseArgs(args []string) (*Command, error) { @@ -375,9 +387,7 @@ func (self *Command) ParseArgs(args []string) (*Command, error) { return nil, &ParseError{Message: "At least one arg must be supplied"} } ctx := Context{SeenCommands: make([]*Command, 0, 4)} - if self.Name == "" { - self.Name = args[0] - } + self.ExeName = args[0] err = self.parse_args(&ctx, args[1:]) if err != nil { return nil, err diff --git a/tools/utils/misc.go b/tools/utils/misc.go new file mode 100644 index 000000000..30a470d28 --- /dev/null +++ b/tools/utils/misc.go @@ -0,0 +1,23 @@ +// License: GPLv3 Copyright: 2022, Kovid Goyal, + +package utils + +import ( + "fmt" +) + +var _ = fmt.Print + +func Reverse[T any](s []T) { + for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { + s[i], s[j] = s[j], s[i] + } +} + +func Reversed[T any](s []T) []T { + ans := make([]T, len(s)) + for i, x := range s { + ans[len(s)-1-i] = x + } + return ans +}