- Adds check to ensure that `wrapped(to:wrappingIndent:)` doesn't
attempt to retrieve a negative prefix.
- The Usage struct was composed of an array of strings which always
contained exact one string at runtime. This struct has been removed
and replaced with a single usage string.
- Removes HelpGenerator._screenWidthOverride in favor of explicitly
setting the screen width in generateHelp calls.
- Fixes#369
- Adds an error check for the return value of GetConsoleScreenBufferInfo
Windows. If GetConsoleScreenBufferInfo a default size of 80 by 25 is
used.
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.
* Correctly track used input origins for single-dash options
When capturing the values for an option with a single-dash with the .upToNextOption
parsing strategy, the parser was stopping its search for values when it encountered
the "unpacked" short option candidates. This change removes the single-dash option
before looking for values, which strips those short options (e.g. -h) from
consideration. Fixes#327.
The changes in #335 introduced a new library but failed to actually
build the library and update the dependency structure. Update the build
system to build and install the new target.
- Removes `HelpInfo` in favor of a recursively defined `CommandInfo`
which contains more raw metadata about the source command.
Additionally, introduces a top level `ToolInfo` type with a
serialization version to aid future tooling.
- Updates tests to match the new serialized format.
- Renames `DumpHelpInfoGenerator` to `DumpHelpGenerator` to align the
type with the `--dump-help` flag.
* Add dummy property as workaround for #338
The addition of _hiddenFromHelp to OptionGroup in 0.4.3 triggered
a Swift IRGen issue. Adding this dummy variable works around the
issue in at least some cases.
* Don't include _hiddenFromHelp props in other property wrappers
This resolves another crashing issue described in rdar://80796582,
where defining an OptionGroup that isn't used results in a runtime
segfault when compiled in release mode.
- Adds an overload of ArgumentDefinition.init with a generic constraint
on ExpressibleByArgument that propogates the conformance to the
construction of ArgumentDefinition.Help. This allows the
allValueStrings of the type conforming to ExpressibleByArgument to
become the allValues property of the help object.
If a command defines an @Argument property with the .unconditionalRemaining
parsing strategy, we need to stop parsing input when we encounter either a
positional argument or an unrecognized option/flag label. Note that this is
a change in behavior, as seen in the modified test.
- Removes unused codepaths.
- Simplifies synopsis string codepaths by removing optionality. This
complexity is moved to the caller who is now responsible for filtering
out hidden arguments and options. This change is desirable as it
allows the caller to determine if the argument should be hidden. For
example, while it makes sense to hide arguments in help text, it may
not make sense to hide them when dumping the arguments for another
tool to consume.
- Removes one layer of help properties by directly including the members
of ArgumentHelp in ArgumentDefinition.Help. This also results in the
discussion field which previously existed in both structures, now
having a single source of truth. Adds helper method for setting each
of these members using an instance of ArgumentHelp. Makes previously
optional Strings into plain Strings and updates points of use to check
for the empty string case.
This fixes a bug where an @Option array defined with the .upToNextOption
parsing strategy would only capture the last "group" of elements. e.g. in:
example --test one two --test three four
the `--test` property would only have the value `["three", "four"]`.
Fixes rdar://73908471
Fixes “Internal error. Invalid state while parsing command-line arguments.” that is encountered when an unparsed value is optional.
Root causes:
- `ParsedArgumentsContainer.decodeNil` returns false for optional values because it only does a `!contains(key)` check. This should instead return nil if the value of the element is nil.
- The decoder did not know about unparsed input origins that and would result in unexpected behavior when decoding nil default values.
- The `value` of `Mirror.Child` is defined as `Any` but this is confusing because the value could be `Optional<Any>` which is not equal to `nil` even when the `Optional` case is `.none`.
Co-authored-by: Mike <mike.wermuth@icloud.com>
On this platform, the TIOCGWINSZ ioctl identifier is a complex macro.
Since we don't have a C bridging header obviously available to get the
flattened value, supply is the flattened value obtained elsewhere. This
is of course brittle but this is the simplest way around this for now.
Additionally, ensure we support the platform architecture name, where
the x86_64 architecture is called amd64 instead.
Fixes an issue where the inversion of a flag would not be hidden whe the ArgumentHelp shouldDisplay value is false.
Added a unit test to check for this behavior.
We're newly able to decode actual optional types due to allowing
unparsed variable properties. "Normal" optional values are still
wrapped in non-optional property wrappers, so ArgumentDecoder didn't
need to handle optional values until now. Fixes#285
ArgumentParser is configured not to emit detailed synopsis when it would contain more than a dozen entries. This makes sense; however, eliding all information makes the synopsis rather useless.
While commands may have dozens of options, in most cases, only a few of them are required — so we can keep the synopsis short but still useful by only displaying the required parts.
* Include all positional arguments in shortened synopsis
* Allow variable properties in parsable types
This captures the default value for non-parsable properties
when building the ArgumentSet, which in turn get set as initial
values before decoding.