-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
OptionParser should be able to parse options partially #5845
Comments
It seems in the linked methods this is implemented in such a way that global options need come first, then the command and then command-specific options. This means only I don't think it would particularly useful if you had to know for each flag if it belongs before or after the command when calling a program. |
@straight-shoota this is very standard behaviour. Almost all programs with subcommands have this. Including |
#4809 ? |
@RX14 The crystal compiler has no global flags (except But yes, this is used for example with If it is sufficiently implemented by #4809, it is probably fine. I just wanted to note that this behaviour can be confusing and should be avoided when possible. But I'm not really sure if the OP had this in mind. Otherwise the given example code is just bad at illustrating it because the global options |
Python standard library's module |
@straight-shoota sorry for delay.
You got it right, the intention was to have global options (come before any command) and command options (come after a command). |
A different use of ordered mode is to explicitly turn option flags into regular positional arguments. This is useful for
Here Following #11537 we could expose this feature as a constructor parameter called OptionParser.parse(@options, ordered: true) do |opts|
opts.on("-h", "--help") { ... }
opts.unknown_args do |before, after|
case before.shift?
when "eval"
# here `@options` contains the rest of the arguments, including the `--` if any
OptionParser.parse(@options, ordered: true) do |opts|
opts.on("-h", "--help") { ... }
opts.unknown_args do |before, after|
program_source = before.join " "
program_args = after
# ...
end
end
end
end
end |
Had that implemented, it would be possible to write commands with own options clearly:
E.g. Ruby and Elixir have such ability.
The text was updated successfully, but these errors were encountered: