-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
How to put generic arguments before flags in v2 #1481
Comments
Hi @yirez-tc Why would you put flags/options at the end ? The usual way of running a cli would be the other way around, flags/options first and then arguments. I can think about few examples from the linux world:
or
or
I'm not saying that it should not be possible, but the standard way is options first, then args. |
Hey @abousselmi , We can make do with putting it at the end but there was a specific requirement for a cli tool we were building. It had several flags and one of the flags was to be the first argument implicitly since it will be used the most often. The intention was to be a bit like an sql command. something like below where |
Hey @yirez-tc , The CLI help is pretty clear about the order of flags and args. You cannot have args before global options or command options.
To achieve what you are asking, you can do something like :
Then you can create an alias and execute it like this:
which gives you the requested behavior, using only flags, with no args around
|
Both
and
work equally well. I guess the limitation in this package is due to the behavior of |
use gopkg.in/alecthomas/kingpin.v2 |
Duplicate of #1113 |
I've been trying to place generic arguments first when running a cli command, like this:
testrun aaa -lang spanish
Following along the spanish example in the tutorial here
What I get back is everything has become an argument. If I do it the other way round, with the argument at the back everything works fine. Is there a flag I'm missing to set for it to work in the initial way. I put up a stackoverflow question up too but didn't get any responses to that.
urfave/cli version: v2.14.1
golang
v: 1.18
stackoverflow question link: https://stackoverflow.com/questions/73587275/urfave-cli-argument-placement-prevents-flag-parsing
The text was updated successfully, but these errors were encountered: