Commit Graph
157 Commits
Author SHA1 Message Date
Rauhul Varma 00a86771ca Clean up help generation (#385)
- 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.
2022-01-10 16:02:50 -06:00
Rauhul Varma df75d7009e Fix dump help crash (#387)
- Fixes #375
- Fixes a bug with the experimental dump help generator which would
  occur when a ParsableCommand has non-Argument properties.
2022-01-10 15:58:49 -06:00
Rauhul Varma 020800d75c Handle failures getting terminal size on windows (#386)
- Fixes #369
- Adds an error check for the return value of GetConsoleScreenBufferInfo
  Windows. If GetConsoleScreenBufferInfo a default size of 80 by 25 is
  used.
2022-01-10 15:18:52 -06:00
yonihemi cca8f80939 Add SwiftWasm support (#363) 2022-01-06 09:56:44 -06: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
Nate Cook e73578df2d Update documentation cross-links (#383) 2022-01-03 15:59:54 -06:00
Ian Saultz 3bbfafecde Fix various broken links in documentation articles. (#362) 2021-12-16 08:09:09 -06:00
Aaron Gyes 7e04f56c1d Rename ...using_command fish function, set $cmd in local scope (#377)
__fish_* should not be used by external projects.
set -l cmd in case user has a global or universal `cmd` defined.
2021-12-10 13:31:20 -06:00
Craig Siemens d7f63849fb Updated the zsh completions to escape the command name for a custom completion. (#364) 2021-12-07 10:47:43 -06:00
Jake Petroules b2e411887e Fix compile failure on iOS for Mac Catalyst support (#372) 2021-11-08 19:50:43 -06:00
Yi Xie afe0b9588e Fix compile failure on iOS for Mac Catalyst support (#356)
* Fix compile failure on iOS

* Add sortedKeys API check for tvOS and watchOS
2021-09-13 16:24:33 -05:00
Nate Cook fd4c3b68a0 Prepare for 1.0 release (#355) 2021-09-10 19:04:33 -05:00
Nate Cook ddd45aa2e0 Remove unavailable symbols (#354) 2021-09-10 18:30:09 -05:00
Nate Cook b77ea81c44 Fix parsing for single-dash names with .upToNextOption parsing (#353)
* 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.
2021-09-10 17:54:35 -05:00
Nate Cook 397d704f05 Add DocC documentation bundle. (#347) 2021-09-10 12:50:42 -05:00
Rauhul Varma d4dd8e7c23 remove extra @_spi (#352) 2021-09-09 13:54:58 -05:00
Nate Cook 9b6827d348 Mark the dump help feature as experimental for now (#350)
* Mark `--dump-help` as experimental
* Mark the dumpHelp method as underscored
2021-09-01 16:42:17 -05:00
Saleem Abdulrasool eef1f7590a build: repair the build of ArgumentParser with CMake (#349)
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.
2021-08-30 18:17:52 -05:00
Rauhul Varma b3bef58985 Improvements to --dump-help (#335)
- 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.
2021-08-26 14:21:45 -05:00
Nate Cook 6619de698b Work around runtime issue introduced in 0.4.3 (#342)
* 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.
2021-07-30 12:15:08 -05:00
Rauhul Varma d4d1879c9d Propogate ExpressibleByArgument conformance (#341)
- 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.
2021-07-29 13:23:50 -05:00
Nate Cook 685341f629 Use standard path for --dump-help help/completions, remove completions (#339) 2021-07-20 12:59:36 -05:00
Saleem Abdulrasool 19a5e2aca4 build: update CMakeLists.txt for new source (#336)
Repair the build after #310 to allow building with CMake which is required for bootstrapping.
2021-07-09 10:28:53 -05: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
Nate Cook 23f7265cd6 Stop parsing earlier when a catch-all argument is present (#333)
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.
2021-07-02 17:39:30 -05:00
François Lamboley 37610bc875 Fix executable path when calling custom completion in bash (#323) 2021-06-10 11:07:02 -05:00
Gonzalo RH 530a754555 Included help message when a required value is missing. (#324) 2021-06-09 11:28:00 -05:00
François Lamboley e566395765 Fix custom completion args for bash (#320) 2021-06-04 09:53:48 -05:00
Saleem Abdulrasool 615c9464b8 build: update the build rules for ArgumentParser (#318) 2021-05-22 12:31:05 -07:00
Rauhul Varma f4353dbe3a Simplify synopsis string generation (#316)
- 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.
2021-05-22 10:59:37 -05:00
Rauhul Varma 860afdad31 Clean up internal property nesting (#315)
- 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.
2021-05-20 19:03:19 -05:00
Nate Cook 992a7451d5 Convert all public enums to structs (#299) 2021-05-15 10:30:48 -05:00
Nate Cook c002f406ac Capture values across multiple .upToNextOption option uses (#304)
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
2021-05-14 21:39:51 -05:00
Nate Cook 167704f261 Ignore extra help flags when given with the 'help' subcommand (#309) 2021-05-14 17:28:32 -05:00
Nate Cook 267f707294 Use custom help flags in completion scripts (#308)
* Standardize the help and version flag generation
* Simplify some help generation code
* Support custom help flags in completion scripts
2021-05-14 10:27:05 -05:00
Miguel A. Perez Ojito ee32b80940 Hide option group with new OptionGroup constructor (#301) 2021-04-24 21:28:10 -05:00
Miguel A. Perez Ojito f314199a3d Exclude supercommands from help (#300)
* Ability to exclude super commands from --help
2021-04-21 12:17:32 -05:00
Nate Cook cdb0e71584 Convert realValue method to function, update docs (#298) 2021-04-15 01:28:48 -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
3405691582 b936799bca OpenBSD support. (#291)
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.
2021-03-29 12:46:26 -05:00
Mike Wermuth 080372b7cd Hide flag inversion when help is hidden (#289)
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.
2021-03-12 01:07:12 -06:00
Nate Cook 380eb72378 Don't error when decoding optional unparsed values (#286)
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
2021-03-06 19:02:45 -06:00
Alfredo Delli Bovi 4793b0f4b9 Include help text in error message when validation fails (#283) 2021-03-06 13:11:58 -06:00
Alfredo Delli Bovi 26744de9d8 Fix zsh dashes in command names (#284) 2021-03-06 13:10:43 -06:00
Nate Cook e5178a971d Remove special casing for CustomNSError (#276)
The error code in CustomNSError is actually _not_ appropriate to use as
the command's exit code.
2021-02-18 14:03:13 -06:00
Karoy Lorentey 5bfb39ac07 Generate useful synopsis for commands with many options (#275)
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
2021-02-16 09:30:31 -06:00
Kenny 267558bb4d Beautify NSError cases when thrown 💄 (#272) 2021-02-15 17:17:13 -06:00
Nate Cook e99a8ef488 Allow variable properties in parsable types (#268)
* 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.
2021-02-15 15:28:13 -06:00
Nate Cook 26114e5f96 Remove extraneous debugging statement (#273) 2021-02-11 10:53:39 -06:00
Nate Cook 605a2330c5 Suppress hidden arguments from completion scripts (#271) 2021-02-11 10:41:46 -06:00