Commit Graph
14 Commits
Author SHA1 Message Date
Nate Cook f674173291 Don't let .allUnrecognized consume built-in flags (#550)
Arguments declared with the `.allUnrecognized` parsing strategy
currently capture built-in flags, which isn't intended. This
fixes that issue by looking for built-in flags in the captured
portion of the input before decoding.

Fixes rdar://104990388
2023-02-08 21:02:46 -08:00
Nate Cook a8b48bc389 Add two new ArgumentArrayParsingStrategy options (#496)
This adds two new parsing options for argument arrays, and renames
`.unconditionalRemaining` to `.captureForPassthrough`.

- `.allUnrecognized` collects all the inputs that weren't used during
parsing. This essentially suppresses all "unrecognized flag/option"
and "unexpected argument" errors, and makes those extra inputs
available to the client.
- `.postTerminator` collects all inputs that follow the `--`
terminator, before trying to parse any other positional arguments.
This is a non-standard, but sometimes useful parsing strategy.
2022-10-07 16:18:52 -05:00
Nate Cook 6f30db08e6 Don't trigger help for unconditional remaining commands (#417) 2022-03-12 12:33:19 -06:00
Matt Zanchelli 9e14482156 Correct Typos (#388) 2022-01-11 16:47:13 -06:00
Nate Cook 2a4664a40b Add support for joined short options (#240)
This supports joined arguments, like '-Ddebug' or '-v4'. Joined arguments
need to be explicitly declared as `.customShort("D", allowingJoined: true)`.
2021-01-16 00:18:23 -06:00
Nate Cook db24cb1275 Improve parsing performance (#234)
* Convert some linear operations to constant time

* Temporary test command for performance testing

* Improve SplitArguments docs

* Re-enable split arguments unit test

* Restore repeat example
2020-09-01 09:31:42 -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
Nate Cook 8883f06b4e Don't consume the terminator during parsing. (#168)
Fixes #130.
2020-05-28 01:13:15 -05:00
John Mueller afeb2009f8 Fix short names with equals sign (#141)
If an argument has a single dash and single character, followed by a value, treat it as a short name.
    `-c=1`      ->  `Name.short("c")`
Otherwise, treat it as a long name with single dash.
    `-count=1`  ->  `Name.longWithSingleDash("count")`
2020-05-14 10:09:30 -05:00
Nate Cook 9e77589d85 Don't repeat single-dash arguments with unconditionalRemaining arrays (#95)
This fixes #88.
2020-03-20 13:23:49 -05:00
Nate Cook 1e05511552 Add a catch-all argument parsing strategy (#29)
* Add a catch-all argument parsing strategy

We don't currently have a way for `@Argument` arrays to capture
command-line inputs that look like options. This capability is
important for tools like SwiftPM that need to forward input to
another command.

This introduces an `ArgumentArrayParsingStrategy` enum with a
`remaining` case that  matches the current behavior, as well as an
`unconditionalRemaining` case that captures all remaining input. The
two array-based `@Argument` initializers gain defaulted parameters for
the parsing strategy.

* Address feedback from @danieleggert

- Added a bit of a warning for the unconditional parsing strategy
- Switched to a better way of getting the original input
- Changed to pulling the "earliest" element when combining positional and
  unused values, rather than combining and sorting. This felt more
  efficient than reconstructing a SplitArguments instance or combining
  and sorting.

* Add parameter docs for argument parsing strategy

* Expand documentation and tests to cover `--` terminator

* Fix case name in API documentation
2020-03-09 17:12:42 -05:00
Šimon Javora 6b3a0a12a3 Clean up InputOrigin by removing unused code. (#21) 2020-03-03 12:54:15 -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