Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Do not provide fallbacks for mutually exclusive options #8

Closed
felixSchl opened this issue Apr 13, 2016 · 2 comments · Fixed by #27
Closed

Do not provide fallbacks for mutually exclusive options #8

felixSchl opened this issue Apr 13, 2016 · 2 comments · Fixed by #27

Comments

@felixSchl
Copy link
Owner

The problem:

Usage: foo (-a | -b)

Options:
  -a FILE  [default: qux]

Then:

  • $ prog -a baz produces: {"-a": baz, "-b": false} (good)
  • $ prog -b produces: {"-a": qux, "-b": true} (bad: I cannot tell which one was user-provided)

Should be:

  • $ prog -a baz produces: {"-a": baz} (good)
  • $ prog -b produces: {"-b": true} (good)
@felixSchl
Copy link
Owner Author

An alternative option, which is clearer to implement would be to either

a) indicate the source of the value: environment, argv, default
b) provide a secondary lookup args._ (or similar) that only shows the values provided explicitly.

@felixSchl
Copy link
Owner Author

To get this done, first refactor the transformer to always transform into unique keys, but with rich set of information and then optionally reduce to key => val later.

felixSchl added a commit that referenced this issue May 8, 2016
*** BREAKING CHANGE ***

This is a fairly large re-think of how argument values are fetched from
the their various input sources. Before, values would be loaded during
a step after parsing, where the matched usage branch would be completely
unrolled, unified and then populated. This had the disadvantage that one
could not tell which of the mutually exclusive branches produced a
result, since one value might arrive from ARGV and another one from the
[default: ...] tag, or the environment, etc. (See #8)

Now, values are loaded at parse-time, removing these issues. Further,
"empty" values are elided from the output, representing the user *not
trying* to match these keys (as opposed to choosing to set them
explicitly). For example, the user might pass the value 'false' to an
option and that value will be retained. If the option however yields
false because there was no user input and because 'false' is its' empty
fall-back, the value will be omitted. The same goes for matching
repeating elements into an array. At least one element needs to be
matched before a value will be yielded.

The diff of 'testcases.docopt' should highlight these changes better
than any amount of explanatory text could.

This patch also removes the "ScoredResult" type as it is no longer
needed. Scoring is based on the "Origin" of a value now. This somewhat
simplifies the code.

Lastly, there's now a recursive step inside `genExhaustiveParser` that
recursively evaluates missing elements until all options have been
exhausted or failed.
felixSchl added a commit that referenced this issue May 8, 2016
*** BREAKING CHANGE ***

This is a fairly large re-think of how argument values are fetched from
the their various input sources. Before, values would be loaded during
a step after parsing, where the matched usage branch would be completely
unrolled, unified and then populated. This had the disadvantage that one
could not tell which of the mutually exclusive branches produced a
result, since one value might arrive from ARGV and another one from the
[default: ...] tag, or the environment, etc. (See #8)

Now, values are loaded at parse-time, removing these issues. Further,
"empty" values are elided from the output, representing the user *not
trying* to match these keys (as opposed to choosing to set them
explicitly). For example, the user might pass the value 'false' to an
option and that value will be retained. If the option however yields
false because there was no user input and because 'false' is its' empty
fall-back, the value will be omitted. The same goes for matching
repeating elements into an array. At least one element needs to be
matched before a value will be yielded.

The diff of 'testcases.docopt' should highlight these changes better
than any amount of explanatory text could.

This patch also removes the "ScoredResult" type as it is no longer
needed. Scoring is based on the "Origin" of a value now. This somewhat
simplifies the code.

Lastly, there's now a recursive step inside `genExhaustiveParser` that
recursively evaluates missing elements until all options have been
exhausted or failed.
felixSchl added a commit that referenced this issue May 9, 2016
*** BREAKING CHANGE ***

This is a fairly large re-think of how argument values are fetched from
the their various input sources. Before, values would be loaded during
a step after parsing, where the matched usage branch would be completely
unrolled, unified and then populated. This had the disadvantage that one
could not tell which of the mutually exclusive branches produced a
result, since one value might arrive from ARGV and another one from the
[default: ...] tag, or the environment, etc. (See #8)

Now, values are loaded at parse-time, removing these issues. Further,
"empty" values are elided from the output, representing the user *not
trying* to match these keys (as opposed to choosing to set them
explicitly). For example, the user might pass the value 'false' to an
option and that value will be retained. If the option however yields
false because there was no user input and because 'false' is its' empty
fall-back, the value will be omitted. The same goes for matching
repeating elements into an array. At least one element needs to be
matched before a value will be yielded.

The diff of 'testcases.docopt' should highlight these changes better
than any amount of explanatory text could.

This patch also removes the "ScoredResult" type as it is no longer
needed. Scoring is based on the "Origin" of a value now. This somewhat
simplifies the code.

Lastly, there's now a recursive step inside `genExhaustiveParser` that
recursively evaluates missing elements until all options have been
exhausted or failed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant