Visitar URL original
Help with flag format · Issue #2320 · urfave/cli · GitHub
Skip to content

Help with flag format #2320

Open
Open

Description

@gmonk

I noticed the flag format has changed and seems to duplicate. Is there a way to format v3 to look more like v2 ?

v3
--interface string, -i string [ --interface string, -i string ] Select active interface to use
--help, -h show help

v2
--interface value, -i value Select active interface to use
--help, -h show help

Thanks

Activity

  1. added
    area/v2relates to / is being considered for v2
    status/triagemaintainers still need to look into this
    on Apr 28, 2026
  2. yxshee commented on Oct 31, 2026

    @yxshee
    Contributor

    The repeated part is on purpose. In v3, flags that can be given more than once (StringSliceFlag, IntSliceFlag, map flags and so on) get the flag's names repeated in brackets in help, e.g. --interface string, -i string [ --interface string, -i string ], to show that you can repeat them. It comes from the default cli.FlagStringer.

    If you want the v2 look back, wrap the default stringer and drop that suffix:

    def := cli.FlagStringer
    cli.FlagStringer = func(f cli.Flag) string {
    	s := def(f)
    	if mv, ok := f.(cli.DocGenerationMultiValueFlag); ok && mv.IsMultiValueFlag() {
    		names, usage, _ := strings.Cut(s, "\t")
    		names, _, _ = strings.Cut(names, " [ ")
    		return names + "\t" + usage
    	}
    	return s
    }

    With that, v3.14.0 prints --interface string, -i string Select active interface to use.

    The other difference, string instead of value, comes from the flag's type name. You can override it per flag by putting the placeholder in backticks in Usage, for example Usage: "Select the active interface `value`".

    To change a single flag instead of all of them, call SetStringer on it.

    (This one is about v3, so the area/v2 label looks off.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2kind/questionsomeone asking a questionstatus/triagemaintainers still need to look into this

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions