docopt/docopt — pull request #199 by masmu (2014-06-27 11:13:40+00:00)
Title: Added only_passed argument

I want to use docopt in conjunction with environment variables and config files.
So configuration options can come from different locations and i want to prioritize the options which come from docopt.

The problem is that docopt always returns all the arguments and options specified in the description, even when you did not pass them via command line.
I know that this is expected behavior.
But when you priorize docopts options most, you will automaticly overwrite all the options which came from the other locations, e.g. with default values or with None. In that case docopt will become unusable.

The solution is to offer the developer a way to just get the arguments and options which were really passed on commandline, despite all the other arguments specified in the description.

environ_config = os.environ()
...

file_config = ...

cli_passed_config = {}
cli_args = docopt(doc_string, version=version,
only_passed=cli_passed_config)

config = collections.ChainMap(
cli_passed_config,
environ_config,
file_config
)