1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-06-30 21:28:28 +00:00

go: go get -u ./... && go mod vendor && go mod tidy

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2023-10-07 09:59:06 -04:00
parent a9c6969125
commit e73ff94ef9
Signed by: vbatts
GPG key ID: E30EFAA812C6E5ED
162 changed files with 1835 additions and 2997 deletions

View file

@ -332,11 +332,18 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
return a.rootCommand.Run(cCtx, arguments...)
}
// This is a stub function to keep public API unchanged from old code
//
// Deprecated: use App.Run or App.RunContext
// RunAsSubcommand is for legacy/compatibility purposes only. New code should only
// use App.RunContext. This function is slated to be removed in v3.
func (a *App) RunAsSubcommand(ctx *Context) (err error) {
return a.RunContext(ctx.Context, ctx.Args().Slice())
a.Setup()
cCtx := NewContext(a, nil, ctx)
cCtx.shellComplete = ctx.shellComplete
a.rootCommand = a.newRootCommand()
cCtx.Command = a.rootCommand
return a.rootCommand.Run(cCtx, ctx.Args().Slice()...)
}
func (a *App) suggestFlagFromError(err error, command string) (string, error) {

View file

@ -135,6 +135,7 @@ func (c *Command) setup(ctx *Context) {
if scmd.HelpName == "" {
scmd.HelpName = fmt.Sprintf("%s %s", c.HelpName, scmd.Name)
}
scmd.separator = c.separator
newCmds = append(newCmds, scmd)
}
c.Subcommands = newCmds

View file

@ -56,6 +56,7 @@ func (cCtx *Context) Set(name, value string) error {
// IsSet determines if the flag was actually set
func (cCtx *Context) IsSet(name string) bool {
if fs := cCtx.lookupFlagSet(name); fs != nil {
isSet := false
fs.Visit(func(f *flag.Flag) {
@ -72,7 +73,23 @@ func (cCtx *Context) IsSet(name string) bool {
return false
}
return f.IsSet()
if f.IsSet() {
return true
}
// now redo flagset search on aliases
aliases := f.Names()
fs.Visit(func(f *flag.Flag) {
for _, alias := range aliases {
if f.Name == alias {
isSet = true
}
}
})
if isSet {
return true
}
}
return false
@ -204,9 +221,10 @@ func (cCtx *Context) checkRequiredFlags(flags []Flag) requiredFlagsErr {
var flagPresent bool
var flagName string
for _, key := range f.Names() {
flagName = key
flagNames := f.Names()
flagName = flagNames[0]
for _, key := range flagNames {
if cCtx.IsSet(strings.TrimSpace(key)) {
flagPresent = true
}

View file

@ -153,9 +153,14 @@ func prepareFlags(
// flagDetails returns a string containing the flags metadata
func flagDetails(flag DocGenerationFlag) string {
description := flag.GetUsage()
value := flag.GetValue()
if value != "" {
description += " (default: " + value + ")"
if flag.TakesValue() {
defaultText := flag.GetDefaultText()
if defaultText == "" {
defaultText = flag.GetValue()
}
if defaultText != "" {
description += " (default: " + defaultText + ")"
}
}
return ": " + description
}

View file

@ -52,7 +52,7 @@ func (b *boolValue) String() string {
func (b *boolValue) IsBoolFlag() bool { return true }
func (b *boolValue) Count() int {
if b.count != nil {
if b.count != nil && *b.count > 0 {
return *b.count
}
return 0
@ -130,6 +130,11 @@ func (f *BoolFlag) Apply(set *flag.FlagSet) error {
if count == nil {
count = new(int)
}
// since count will be incremented for each alias as well
// subtract number of aliases from overall count
*count -= len(f.Aliases)
if dest == nil {
dest = new(bool)
}

View file

@ -117,13 +117,8 @@ func (cCtx *Context) Generic(name string) interface{} {
}
func lookupGeneric(name string, set *flag.FlagSet) interface{} {
f := set.Lookup(name)
if f != nil {
parsed, err := f.Value, error(nil)
if err != nil {
return nil
}
return parsed
if f := set.Lookup(name); f != nil {
return f.Value
}
return nil
}

View file

@ -90,13 +90,8 @@ func (cCtx *Context) Path(name string) string {
}
func lookupPath(name string, set *flag.FlagSet) string {
f := set.Lookup(name)
if f != nil {
parsed, err := f.Value.String(), error(nil)
if err != nil {
return ""
}
return parsed
if f := set.Lookup(name); f != nil {
return f.Value.String()
}
return ""
}

View file

@ -87,10 +87,8 @@ func (cCtx *Context) String(name string) string {
}
func lookupString(name string, set *flag.FlagSet) string {
f := set.Lookup(name)
if f != nil {
parsed := f.Value.String()
return parsed
if f := set.Lookup(name); f != nil {
return f.Value.String()
}
return ""
}

View file

@ -145,11 +145,6 @@ func (f *TimestampFlag) Apply(set *flag.FlagSet) error {
f.defaultValue = f.Value.clone()
if f.Destination != nil {
f.Destination.SetLayout(f.Layout)
f.Destination.SetLocation(f.Timezone)
}
if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found {
if err := f.Value.Set(val); err != nil {
return fmt.Errorf("could not parse %q as timestamp value from %s for flag %s: %s", val, source, f.Name, err)
@ -157,6 +152,10 @@ func (f *TimestampFlag) Apply(set *flag.FlagSet) error {
f.HasBeenSet = true
}
if f.Destination != nil {
*f.Destination = *f.Value
}
for _, name := range f.Names() {
if f.Destination != nil {
set.Var(f.Destination, name, f.Usage)

View file

@ -141,7 +141,7 @@ USAGE:
DESCRIPTION:
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}}
COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
@ -357,9 +357,8 @@ func (a *App) RunAndExitOnError()
code in the cli.ExitCoder
func (a *App) RunAsSubcommand(ctx *Context) (err error)
This is a stub function to keep public API unchanged from old code
Deprecated: use App.Run or App.RunContext
RunAsSubcommand is for legacy/compatibility purposes only. New code should
only use App.RunContext. This function is slated to be removed in v3.
func (a *App) RunContext(ctx context.Context, arguments []string) (err error)
RunContext is like Run except it takes a Context that will be passed to

View file

@ -42,6 +42,7 @@ var helpCommand = &Command{
// 3 $ app foo
// 4 $ app help foo
// 5 $ app foo help
// 6 $ app foo -h (with no other sub-commands nor flags defined)
// Case 4. when executing a help command set the context to parent
// to allow resolution of subsequent args. This will transform
@ -77,6 +78,8 @@ var helpCommand = &Command{
HelpPrinter(cCtx.App.Writer, templ, cCtx.Command)
return nil
}
// Case 6, handling incorporated in the callee itself
return ShowSubcommandHelp(cCtx)
},
}
@ -206,9 +209,15 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) {
func DefaultCompleteWithFlags(cmd *Command) func(cCtx *Context) {
return func(cCtx *Context) {
if len(os.Args) > 2 {
lastArg := os.Args[len(os.Args)-2]
var lastArg string
// TODO: This shouldnt depend on os.Args rather it should
// depend on root arguments passed to App
if len(os.Args) > 2 {
lastArg = os.Args[len(os.Args)-2]
}
if lastArg != "" {
if strings.HasPrefix(lastArg, "-") {
if cmd != nil {
printFlagSuggestions(lastArg, cmd.Flags, cCtx.App.Writer)
@ -292,8 +301,12 @@ func ShowSubcommandHelp(cCtx *Context) error {
if cCtx == nil {
return nil
}
HelpPrinter(cCtx.App.Writer, SubcommandHelpTemplate, cCtx.Command)
// use custom template when provided (fixes #1703)
templ := SubcommandHelpTemplate
if cCtx.Command != nil && cCtx.Command.CustomHelpTemplate != "" {
templ = cCtx.Command.CustomHelpTemplate
}
HelpPrinter(cCtx.App.Writer, templ, cCtx.Command)
return nil
}

View file

@ -88,7 +88,7 @@ USAGE:
DESCRIPTION:
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}}
COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}