Releases: apple/swift-argument-parser
ArgumentParser 0.2.2
Fixes
- Zsh completion scripts have improved documentation and better support
multi-word completion strings, escaped characters, non-standard executable
locations, and empty help strings.
ArgumentParser 0.2.1
Additions
- You can now generate Bash and Zsh shell completion scripts for commands,
either by using the--generate-completion-scriptflag when running a
command, or by calling the staticcompletionScript(for:)method on a root
ParsableCommandtype. See the guide to completion scripts for
information on customizing and installing the completion script for your
command.
Fixes
- Property wrappers without parameters can now be written without parentheses
— e.g.@Flag var verbose = false. - When displaying default values for array properties, the help screen now
correctly uses the element type'sExpressibleByArgumentconformance to
generate the description. - Running a project that defines a command as its own subcommand now fails with
a useful error message.
ArgumentParser 0.2.0
Additions
- You can now specify default values for array properties of parsable types.
The default values are overridden if the user provides at least one value
as part of the command-line arguments.
Changes
-
This release of
swift-argument-parserrequires Swift 5.2. -
Default values for all properties are now written using default initialization
syntax, including some values that were previously implicit, such as empty
arrays andfalsefor Boolean flags.Migration: Specify default values using typical Swift default value syntax
to remove the deprecation warnings:// old @Flag() var verbose: Bool // new @Flag() var verbose = false
Important: There is a semantic change for flags with inversions that do
not have a default value. In previous releases, these flags had a default
value offalse; starting in 0.2.0, these flags will have no default, and
will therefore be required by the user. Specify a default value offalseto
retain the old behavior.
Fixes
- Options with multiple names now consistently show the first-declared name
in usage and help screens. - Default subcommands are indicated in the help screen.
- User errors with options are now shown before positional argument errors,
eliminating some false negative reports. - CMake compatibility fixes.
ArgumentParser 0.1.0
Additions
- Error messages and help screens now include information about how to request
more help. - CMake builds now support installation.
Changes
-
The
static func main()method onParsableCommandno longer returns
Never. This allowsParsableCommandtypes to be designated as the entry
point for a Swift executable by using the@mainattribute.Migration: For most uses, this change is source compatible. If you have
usedmain()where a() -> Neverfunction is explicitly required, you'll
need to change your usage or capture the method in another function. -
Optionalno longer conforms toExpressibleByArgument, to avoid some
property declarations that don't make sense.Migration: This is source-compatible for all property declarations, with
deprecations for optional properties that define an explicit default. If
you're using optional values where anExpressibleByArgumenttype is
expected, such as a generic function, you will need to change your usage
or provide an explicit override. -
ParsableCommand'srun()method requirement is now amutatingmethod,
allowing mutations to a command's properties, such as sorting an array of
arguments, without additional copying.Migration: No changes are required for commands that are executed through
themain()method. If you manually parse a command and then call its
run()method, you may need to change the command from a constant to a
variable.
Removals
- The
@Flaginitializers that were deprecated in version 0.0.6 are now
marked as unavailable.
Fixes
@Optionproperties of an optional type that use atransformclosure now
correctly indicate their optionality in the usage string.- Correct wrapping and indentation are maintained for abstracts and discussions
with short lines. - Empty abstracts no longer add extra blank lines to the help screen.
- Help requests are still honored even when a parsed command fails validation.
- The
--terminator isn't consumed when parsing a command, so that it can be
parsed as a value when a subcommand includes an.unconditionalRemaining
argument array. - CMake builds work correctly again.
ArgumentParser 0.0.6
Additions
- Command definition validation now checks for name collisions between options
and flags. ValidationError.messageis now publicly accessible.- Added an
EnumerableFlagprotocol forCaseIterabletypes that are used to
provide the names for flags. When declaring conformance toEnumerableFlag,
you can override the name specification and help text for individual flags.
See #65 for more detail. - When a command that requires arguments is called with no arguments at all,
the error message includes the full help text instead of the short usage
string. This is intended to provide a better experience for first-time users. - Added a
helpMessage()method for generating the help text for a command
or subcommand.
Deprecations
-
@Flagproperties that useCaseIterable/Stringtypes as their values
are deprecated, and the related@Flaginitializers will be removed
in a future version.Migration: Add
EnumerableFlagconformance to the type of these kinds of
@Flagproperties.
Fixes
- Errors thrown while parsing in a
transformclosure are printed correclty
instead of a generalInvalid stateerror. - Improvements to the guides and in the error message when attempting to access
a value from an argument/option/flag definition. - Fixed issues in the CMake and Windows build configurations.
- You can now use an
=to join a value with an option's short name when calling
a command. This previously only worked for long names.
ArgumentParser 0.0.5
Additions
- You can now specify a version string in a
ParsableCommand's configuration.
The generated tool will then automatically respond to a--versionflag. - Command definitions are now validated at runtime in debug mode, to check
issues that can't be detected during compilation.
Fixes
- Deprecation warnings during compilation on Linux have been removed.
- The
validate()method is now called on each command in the matched command
stack, instead of only the last command in the stack.
ArgumentParser 0.0.4
Fixes
- Removed usage of 5.2-only syntax.
ArgumentParser 0.0.3
Additions
- You can specify the
.unconditionalRemainingparsing strategy for arrays of
positional arguments to accept dash-prefixed input, like
example --one two -three. - You can now provide a default value for a positional argument.
- You can now customize the display of default values in the extended help for
anExpressibleByArgumenttype. - You can call the static
exitCode(for:)method on any command to retrieve the
exit code for a given error.
Fixes
- Supporting targets are now prefixed to prevent conflicts with other libraries.
- The extension providing
init?(argument:)toRawRepresentabletypes is now
properly constrained. - The parser no longer treats passing the same exclusive flag more than once as
an error. ParsableArgumentstypes that are declared as@OptionGroup()properties on
commands can now also be declared on subcommands. Previosuly, the parent
command's declaration would prevent subcommands from seeing the user-supplied
arguments.- Default values are rendered correctly for properties with
Optionaltypes. - The output of help requests is now printed during the "exit" phase of execution,
instead of during the "run" phase. - Usage strings now correctly show that optional positional arguments aren't
required. - Extended help now omits extra line breaks when displaying arguments or commands
with long names that don't provide help text.
ArgumentParser 0.0.2
Additions
- The
EX_USAGEexit code is now used for validation errors. - The parser provides near-miss suggestions when a user provides an unknown option.
ArgumentParsernow builds on Windows.- You can throw an
ExitCodeerror to exit without printing any output. - You can now create optional Boolean flags with inversions that default to
nil:@Flag(inversion: .prefixedNo) var takeMyShot: Bool?
- You can now specify exclusivity for case-iterable flags and for Boolean flags with inversions.
Fixes
- Cleaned up a wide variety of documentation typos and shortcomings.
- Improved different kinds of error messages:
- Duplicate exclusive flags now show the duplicated arguments.
- Subcommand validation errors print the correct usage string.
- In the help screen:
- Removed the extra space before the default value for arguments without descriptions.
- Removed the default value note when the default value is an empty string.
- Default values are now shown for Boolean options.
- Case-iterable flags are now grouped correctly.
- Case-iterable flags with default values now show the default value.
- Arguments from parent commands that are included via
@OptionGroupin subcommands are no longer duplicated.
- Case-iterable flags created with the
.chooseFirstexclusivity parameter now correctly ignore additional flags.
ArgumentParser 0.0.1
Initial release.