Add an option validation on cli commands#2278
Conversation
Frenzie
left a comment
There was a problem hiding this comment.
Interesting idea, although given the fairly limited number of options I'm not entirely convinced that it's actually more helpful than the usage notice. :-)
cli/_cli.php
Outdated
| if (0 === count($possibleOption)) { | ||
| fail(sprintf('FreshRSS error: unknown option: %s'), $unknownOption); | ||
| } else { | ||
| fail(sprintf('FreshRSS error: unknown option: %s. Do you mean %s?', $unknownOption, array_shift($possibleOption))); |
There was a problem hiding this comment.
I'd say "Did you mean" or perhaps "The most similar command/option/flag is:".
Side note, what if there are multiple results with a low Levenshtein distance?
There was a problem hiding this comment.
Noted.
In the case of multiple results, the first one is displayed
|
I can remove the the suggestion part. It was just an experiment. |
|
You could also consider printing both, so you'd get something like this: |
|
Considering how the cli is build, it won't be possible to have both |
|
I think usage info is more useful personally. Any thoughts @Alkarex ? |
|
I can do that but that means a lot of changes |
|
I don't think suggestion is very useful though. :-) (At least not when there are fewer than 10 options.) |
42152ac to
8de7b2b
Compare
|
@Frenzie I've changed the behavior to display wrong parameters AND the usage. Let me know what you think! |
| return true; | ||
| } | ||
|
|
||
| fwrite(STDERR, sprintf("FreshRSS error: unknown options: %s\n", implode (', ', $unknownOptions))); |
There was a problem hiding this comment.
I suppose you could consider giving fail() an argument regarding whether to die or not (true by default), or create a non-die()ing duplicate like a warning() function. But that might be premature abstraction.
There was a problem hiding this comment.
That's a good point. Maybe we should do that if we intend to add more warnings.
|
@aledeg Could you please fix the Travis white-space error? :-) |
|
@Alkarex. Will do! |
If an option used on cli is not recognized, the command aborts and displays an error message. If the typed option is similar to one of the recognized options, a hint is displayed. At the moment, there is a limitation on long options. Short options are not validated at the moment. See FreshRSS#2046
8de7b2b to
fea1119
Compare
|
@Alkarex it's all good! |
|
As far as I have tested this merge request, it fixes the bug mentioned in #2046. Thanks @aledeg for fixing this. I still have 2 remarks:
>php cli/do-install.php --default_user myuser --language fr --api-enabled --db-type sqlite
FreshRSS looks to be already installed! Please use `./cli/reconfigure.php` instead.
>echo $?
1 |
If an option used on cli is not recognized, the command aborts and displays an error message. If the typed option is similar to one of the recognized options, a hint is displayed. At the moment, there is a limitation on long options. Short options are not validated at the moment. See FreshRSS#2046
If an option used on cli is not recognized, the command
aborts and displays an error message.
If the typed option is similar to one of the recognized
options, a hint is displayed.
At the moment, there is a limitation on long options.
Short options are not validated at the moment.
See #2046