Commit Graph
8 Commits
Author SHA1 Message Date
Nate Cook 774de9c409 Fix help display for non-String RawRepresentables (#494)
RawRepresentable types that have a non-String raw value are having
values displayed in the help screen by converting the RawRep value
into a string. However, these values are by default parsed by their
raw value, so we should use that for display instead.

This is accomplished by adding a defaultValueDescription
implementation for all ExpressibleByArgument-conforming RawValue
types, and then basing the allValues implementation on that.
This generalizes the existing overloads for String-based RawRep types,
while also allowing users who customize their ExpressibleByArgument
implementation to provide the correct help value for clients.
2022-09-20 14:25:03 -05:00
konomae 68b94a4c73 List valid options in error messages for enum array argument (#445)
When an array of argument values fails to parse, no custom error message is
provided, and a list of valid candidate values is available, include the
list as part of the error message.

Addresses #401.
2022-05-17 11:36:30 -05:00
Kth dd6efd05cb Fix error message for @Option array without values (#435) 2022-04-03 23:58:31 -05:00
Daniel Duan 90f76c14b4 List valid options in error messages (#382)
When an option value fails to parse, no custom error message is
provided, and a list of valid candidate values is available, include the
list as part of the error message.

Addresses #344.
2022-01-05 11:02:31 -06:00
Mike Lewis c0f9a5feee Allow normal Swift default property initialization syntax (#170)
* Allow normal Swift default property initialization syntax

This change allows the normal `var foo = "blah"` default initialization 
syntax for `Option`s, as a parallel initialization method as using the 
`default` parameter.

* Add simple tests for default property initialization

* Centralize some constructor logic into a private `init`

Preparing for another no-initial value `init` to be added and the existing one with a `default` parameter to be deprecated

* Deprecate previous `Option.init` with `default` parameter

It's replaced with an `init` containing no default value parameter, which will be used when the user does not provide any value.

Also add a (most likely unnecessary) sanity test to make sure initializations without a default value still work.
Also copy out documentation to allow clean removal of the older `init` when the time comes.

* Document added test cases

* Correct punctuation

* Extend standard default initialization syntax to `Option`s with `transform` parameters

* Actually replace previous `init` with private version

This mirrors the non-transform variants, and should have been included in the previous commits

* Clean up usage of default parameter values

Private `init` doesn't need defaults, and the deprecated public ones shouldn't have it to avoid confusion with the new methods

* Clean up documentation

Treat new initializers as the originally intended way to allow for clean removal of the deprecated methods
Also add some additional documentation to the deprecated methods to help point users in the right direction

* Extend standard default initialization to `Argument`s

* Extend standard default initialization to `Flag`s

* Default flags with inversions to nil/required

* Extend standard default initialization to no-inversion boolean `Flags`

Prints a warning when that default value is `true` instead of `false`, as the flag value will be pinned regardless of user input

* Eliminate deprecation spam from default value initialization

All examples and unit tests have been transitioned to the new syntax, with the exception of `SourceCompatEndToEndTests`, which should not have the old style removed until it is no longer valid source.

* Add source compatibility tests for new default syntax and associated changes

* Update top-level documentation
2020-06-22 23:12:51 -05:00
Nate Cook 1fa25574f8 Show option-based errors before unexpected positional errors (#187)
This pushes any errors indicated by unexpected arguments after parsing
out to the same late position. We were previously stopping immediately
when the command is a leaf node; that isn't necessary and created an
awkward second error path.
2020-06-15 14:32:36 -05:00
Nate Cook ef76d22b8b Convert deprecations from pre-0.1.0 to unavailable (#177) 2020-06-03 11:18:42 -05:00
Elliott Williams 34300696f5 Prefix test target names with "ArgumentParser" (#74)
* Prefix testing and test helper targets with ArgumentParser

* Replace SAP with ArgumentParser in imports and CMakeLists
2020-03-10 12:44:07 -05:00