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

Free Non Strict Options for a Command #1793

Closed
kudla opened this issue Jul 12, 2023 · 4 comments
Closed

Free Non Strict Options for a Command #1793

kudla opened this issue Jul 12, 2023 · 4 comments
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this

Comments

@kudla
Copy link

kudla commented Jul 12, 2023

Hi!
Please how could the flags be defined for the app level. Yet for the command level to let provide any flag without strict advance definition.

So that the application options would be available by name and the command options would be available as raw slice separated of command arguments. Something like this?

&cli.App{
		Name:  "app",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:    "appOption",
				Aliases: []string{"o"},
			},
		},
		Commands: []*cli.Command{
			{
				Name:      "task",
				Action:    func(cCtx *cli.Context) error {
                                    appOption := cCtx.String("appOption")
                                    comOptions := cCtx.RestOfOptions()
                                    comArgs := cCtx.Args().Slice()
                                    return nil
                                },
			},
		},
	}
app -o app-level-options task --what ever -bc task-arguments next

Thx.

@kudla kudla added area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this labels Jul 12, 2023
@dearchap
Copy link
Contributor

@kudla You can try setting the Command.SkipFlagParsing to true https://github.com/urfave/cli/blob/v2-maint/command.go#L45 This will allow you to get all the rest of the options in cCtx.Args().

@kudla
Copy link
Author

kudla commented Jul 13, 2023

That's great . Thank you @dearchap
What about partial definition ? E.g. some specific options would adjust the behavior of application it self yet all the rest options would be fed as is to a downstream application.

@dearchap
Copy link
Contributor

@kudla There is no support for that in the urfave/cli library. Its either all or nothing. Anything else you have to implement yourself.

@kudla
Copy link
Author

kudla commented Jul 17, 2023

Thanks @dearchap. I wen exactly the same direction

@kudla kudla closed this as completed Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

2 participants