Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-document SkipFlagParsing #2068

Open
iTrooz opened this issue Mar 2, 2025 · 1 comment
Open

Re-document SkipFlagParsing #2068

iTrooz opened this issue Mar 2, 2025 · 1 comment
Labels
area/v3 relates to / is being considered for v3 status/triage maintainers still need to look into this

Comments

@iTrooz
Copy link

iTrooz commented Mar 2, 2025

Hey ! The documentation on SkipFlagParsing says "Treat all flags as normal arguments if true".

However, it seems to also disable the parsing of subcommands. Example:

func main() {
	app := &cli.Command{
		SkipFlagParsing: true,
		Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
			fmt.Println(c.Args())
			return ctx, nil
		},
		Action: func(ctx context.Context, c *cli.Command) error {
			fmt.Println("Hello")
			return nil
		},
		Commands: []*cli.Command{
			{
				Name:            "subcmd",
				SkipFlagParsing: false,
				Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
					fmt.Println(c.Args())
					return ctx, nil
				},
				Action: func(ctx context.Context, c *cli.Command) error {
					fmt.Println("subcmd Action")
					return nil
				},
			},
		},
	}

	err := app.Run(context.Background(), os.Args)
	if err != nil {
		log.Fatal(err)
	}
}

If I run go run . subcmd, toggling SkipFlagParsing would produce different results (a different Action gets executed). I think this should be reflected in the docs

@iTrooz iTrooz added area/v3 relates to / is being considered for v3 status/triage maintainers still need to look into this labels Mar 2, 2025
@iTrooz
Copy link
Author

iTrooz commented Mar 2, 2025

(Also, I spent 30 mins looking on search engines for this flag, maybe a section in the documentation about "how to stop parsing at a certain point" would help future users :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v3 relates to / is being considered for v3 status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

1 participant