Commit Graph
12 Commits
Author SHA1 Message Date
Rauhul Varma 607021b737 Unify @Argument and @Option initialization paths (#477)
- Fixes #466.
- Adds initializers to ArgumentDefinition generic over a Container type.
  The Container type must conform to a new internal protocol
  ArgumentDefinitionContainer which describes functionality like default
  set of help options for the argument defined by the property wrapper,
  etc.
- Adds overloads for Optional @Arguments and @Options with default
  values which emit deprecation warning to guide users towards using the
  non-Optional versions.
2022-09-10 18:40:31 -05:00
Rauhul Varma 185b45fa06 Combine HelpCommand and HelpHiddenCommand (#408) 2022-02-12 16:35:31 -06:00
Keith Smiley b547374049 Add --help-hidden for use with _hiddenFromHelp (#366)
Swift Package Manager adopted _hiddenFromHelp, the resulting help is
much more approachable for basic usage, but leaves no way to view
all the advanced options it accepts. This takes from swiftc's + clang's
playbook and adds a hidden `--help-hidden` flag that prints all help,
including those using `_hiddenFromHelp`
2022-02-11 14:25:22 -06:00
Kotaro Suto cfcb9cb0cd Add new built-in flag --dump-help (#310)
This commit will add a new builtin option named `--dump-help-info` which
outputs help information in JSON.
2021-07-07 13:09:21 -05:00
Mike WermuthandMike bafa74a9e4 Fix invalid state error when decoding an unparsed optional value (#290)
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>
2021-04-15 01:07:24 -05:00
Nate Cook 280700d361 Add completion script generation (#123)
Support for generating shell completion scripts for `ParsableCommand`
types, with customization points for `ExpressibleByArgument` types and
individual arguments and options. Zsh and Bash are supported in this
initial release.
2020-07-29 17:58:44 -05:00
John Mueller 501bf60536 Display help when no arguments results in error (#140)
If a command cannot successfully run with zero arguments, print the error and the full help message instead of the short usage message.

This closes #134.
2020-05-14 09:08:19 -05:00
1081d08b1d Improve errors messages thrown from a transform closure (#115)
* Add a test for @Option transfrom

* Updated `testValidation_Fail()` transform test

It now checks for the validation error text thrown from a `transform` closure.

* Improved transform `@Option` tests

Added a test for the defaut error message and renamed object to imply the tests are for `@Options` only

* Added a `CustomParserErrorConvertible` protocol

Opting in an error types to this will prevent automatic error messages from being generated.

* Add associated value to `.unableToParseValue`

Added a `customMessage` (`String?`) associated value to `ParseError.unableToParseValue(…)`. Setting this will by-pass any automatic error generation.

* Convert transform throws into `unableToParseValue`

Errors thrown by the `transform` closure are caught and convered into a `ParserError.unableToParseValue(…)` error. If the thrown error also confirms to `CustomParserErrorConvertible` the `customMessage` associated value is of `.unableToParseValue` is set, otherwise it is nil.

Implemented for `@Option` and `@Argument`.

* Added transform tests

Added `ParsableArguments` and `ParsableCommand` tests for single values and arrays.

Testing for correctly parsing and transforming values. Throwing a custom error and improved default error messages.

* Add default value to `unableToParseValue`

`customMessage` now has a default value of `nil`

* Removed `CustomParserErrorConvertible`

Updated `unableToParseValue` to take an optional `Error` assocated value. If this error is not nil `unableToParseValueMessage(…)` makes best-efforts to create a custom error message.

* Updated tests to new error mssages format

* Reverted public access of ValidationError.message

* Improved coding standards

`catch` brases on the same line and 2 space indents.

* Simplified `unableToParseValueMessage(…)` logic

Append custom error message to all “unableToParse” errors if it is not nil

* Added a “Handling Transform Errors” section

* Improved switch/case statements

* Added docs link to Handling Transform Errors

* Update Documentation/05 Validation and Errors.md

Co-Authored-By: Xiaodi Wu <13952+xwu@users.noreply.github.com>

* Update Documentation/05 Validation and Errors.md

Co-Authored-By: Xiaodi Wu <13952+xwu@users.noreply.github.com>

* Update Documentation/05 Validation and Errors.md

Co-Authored-By: Xiaodi Wu <13952+xwu@users.noreply.github.com>

* Update Documentation/05 Validation and Errors.md

Co-Authored-By: Xiaodi Wu <13952+xwu@users.noreply.github.com>

* Fixed comment and docs typos

Co-Authored-By: Xiaodi Wu <13952+xwu@users.noreply.github.com>

* Fixed minor code formatting etc.

Co-Authored-By: Nate Cook <natecook@apple.com>

* Improved Documentation

Reduced the code used in the transform closure. Also fixed typing and formatting.

* Added error examples

* Doc edits via code review

Co-Authored-By: Nate Cook <natecook@apple.com>

* Converted TransformEndToEndTests.swift to

2-space indentation

Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
Co-authored-by: Nate Cook <natecook@apple.com>
2020-04-21 09:31:57 -05:00
Nate Cook 31799bc1b4 Add built-in support for --version flag (#102)
* Add built-in support for --version flag

* Test that command-defined --version overrides the built-in.

* Document the `version:` parameter in CommandConfiguration

* Include --version in the generated help.
2020-03-30 12:36:21 -05:00
Guillaume Lessard 53a00f51fb Pass information to ParserError in order to show user a better error message (#52)
* revert some of the cleanup from 6b3a0a1

* Pass information to ParserError to diagnose mutually exclusive flags
2020-03-04 11:24:27 -06:00
Wildchild9 6f58e68a6a Fixed Various Grammar & Spelling Mistakes (#17)
* Corrected grammatical and spelling errors in files in Documentation.

* Correct various spelling, grammar, and formatting mistakes in code documentation.
2020-03-02 10:54:10 -06:00
Nate Cook f6ac7b8118 Initial import of ArgumentParser 2020-02-27 15:45:22 -06:00