Feature Request: ignore (or extract) not specified extra options instead of fail
See original GitHub issueHi there,
It would be great to be able to ignore not specified options when parsing arguments.
My use case is that some runtime invokes my python script with additional options for which I don’t have any control. I’d just like to ignore them.
For instance, if I use the naval fate example from README.md, I’d like the following command to be valid:
naval_fate.py ship shoot 1 2 --unwanted-option
naval_fate.py ship --unwanted-option shoot 1 2
naval_fate.py --unwanted-option ship shoot 1 2
Another idea would be to, instead of ignoring them, simply extract them in another dict as the argparse library do via the parse_known_args
method.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
Indexer errors and warnings - Azure Cognitive Search
Indexing stops when the error count exceeds 'maxFailedItems'. If you want indexers to ignore these errors (and skip over "failed documents") ...
Read more >brew(1) – The Missing Package Manager for macOS (or Linux)
--eval-all : Evaluate all available formulae and casks, whether installed or not, to show their options. --command : Show options for the specified...
Read more >Karate | Test Automation Made Simple.
Features. Java knowledge is not required and even non-programmers can write tests; Scripts are plain-text, require no compilation step or IDE, and teams...
Read more >curl.1 the man page
If this option is set, the default capath value will be ignored. ... This is a request, not an order; the server may...
Read more >Host agent configuration - IBM
Monitor extra file systems; Specify host tags; Extract the installed packages ... It enables the Instana agent to download agent updates and extra...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Imagine I have a script that censors bad words and raises an error when bad words are present in file :
python censor_bad_words.py <filename> [--language=<lang>]
and another script which simply prints the content:
python print_file.py <filename> [--color=<col>]
Now, I want to build a script that does both: python print_censor_bad_words.py <filename> [–language=<lang>] [–color=<col>]
[From the two doc strings, I can programmatically create a combined doc for docopt.]
If I call:
python print_censor_bad_words.py my_file.txt --language=eng --color=blue
I could simply transfer all parameters of the call to sub-scripts:
censor_bad_words.py will complain that it does not know what --color is. print_file.py will complain that it does not know what --language is.
When a script is given all the mandatory arguments it needs, if an unknown/unwanted argument is passed, it can:
In docopt.py code: if matched and left == []: # better error message if left? return Dict((a.name, a.value) for a in (pattern.flat() + collected))
Programmer already had interrogations about what to do when there are unwanted arguments left.
“Would you apply it only on option -s short option, --long-option or would it also apply to <argument> or command too?” All arguments that do not match the definition are rejected. [ This is not he object of this request but it raises the question about what to do with the “left” arguments: a. just ignore them b. pass them to the script anyway (in order to enable non documented arguments that the developer may not want to support)
I assume a. ]
only optional option or mandatory one? As long as the script has the mandatory parameters that it wants, and it parses all the optional parameters that it knows, it is sufficient not to raise an error.
I bump into this when creating a C server that calls python scripts. I want a single python script as entry point as I do not want the client to execute any possible python script. In this script, there is argument that contains the name of the sub-script to be called. This script then calls the appropriate script with the remaining parameters. For this top-level, if I want to use docopt, I need a doc with only the sub-script name but then it refuses to execute as there are other parameters.