-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
player/command: implement skippable arguments in commands #13624
Conversation
bc6d551
to
80bc73d
Compare
Download the artifacts for this pull request: |
80bc73d
to
6890757
Compare
Optional arguments already exist, but they're not exactly skippable. If you exclude one of these arguments, everything else afterwards also needs to be excluded. In c678033, the arguments of loadfile were changed so a new index argument (optional) must always exist before you can pass the options argument. This naturally breaks the old syntax and to be fair, it is a bit weird to do something like "loadfile file.mkv append -1 options=value". So let's make the old commands compatibile again by making the index argument skippable and adding functionality to support this. The actual command itself (cmd_loadfile) is responsible for handling this sanely.
6890757
to
8cb5da6
Compare
Honestly adding this seems weird. Why not just revert the incompatible change? |
What do you mean? Skipping default/implied values (like lots of cli tools do) sounds reasonable to me in certain cases if it makes sense for the command. Named arguments do exist and would indeed not have any issues in the first place, but one would need to be using
How would you implement the index needed for |
I would suggest implementing a general mechanism of keyword arguments in commands (something like |
On its own, this is probably OK if someone wanted to add this so you could use named arguments in more contexts.
I would be opposed to this however. It would break everything for mostly purely theoretical gain. The |
That's not my plan. I meant to suggest marking the maximum number of arguments of all current commands so that the existing commands won't be broken, and the parser can use this information to determine from which position it considers to be keyword arguments. So to use the keyword arguments for existing commands with optional positional arguments, all positional arguments must have some dummy values before the keyword arguments can be specified. |
Sorry I interpreted that as eventually removing the old syntax for the original optional positional arguments at some undefined point in the future. So the proposal would be to have the old syntax live forever for those arguments essentially and only the new optional positional arguments would have to conform to the new syntax? There's an argument for user-friendliness to be had here though. Having a simple string that's just parsed as a command without needing to do any other leg work is nice. Like |
Another idea is to keep the existing command syntax and introduce a new command |
AFAICT, this PR accepts both of these forms as valid, and "does the right thing":
and
This is a very non-generic thing. It only works in this case because the options value can never be parsed as an integer (because it has "="), But this doesn't scale. What if the optional arg after index was an arbitrary string where "-1" would be a valid value? you wouldn't be able to tell whether that This is not a good design IMHO, and it's definitely not generic for arbitrary type of the skippable argument. |
Strings indeed can't work like this so nevermind. |
If nothing else works, a new command called |
Optional arguments already exist, but they're not exactly skippable. If you exclude one of these arguments, everything else afterwards also needs to be excluded. In c678033, the arguments of loadfile were changed so a new index argument (optional) must always exist before you can pass the options argument. This naturally breaks the old syntax and to be fair, it is a bit weird to do something like "loadfile file.mkv append -1 options=value".
So let's make the old commands compatibile again by making the index argument skippable and adding functionality to support this. The actual command itself (cmd_loadfile) is responsible for handling this sanely.
TODO: