Commit Graph
9 Commits
Author SHA1 Message Date
Nate Cook b80fb05f45 Add API for titling an option group (#492)
This change lets you provide a title for option groups, which is used
when generating the help screen. Titled option groups, when they exist,
are placed between the ARGUMENTS and OPTIONS section of the help.
Multiple option groups with the same title are coalesced into a single
group.

For example, this command declaration:

    struct Extras: ParsableArguments {
      @Flag(help: "Print extra output while processing.")
      var verbose: Bool = false

      @Flag(help: "Include details no one asked for.")
      var oversharing: Bool = false
    }

    @main
    struct Example: ParsableCommand {
      @OptionGroup(title: "Extras")
      var extras: Extras

      @Argument var name: String?
      @Option var title: String?
    }

yields this help screen:

    USAGE: example [--verbose] [--oversharing] [<name>] [--title <title>]

    ARGUMENTS:
      <name>

    EXTRAS:
      --verbose               Print extra output while processing.
      --oversharing           Include details no one asked for.

    OPTIONS:
      --title <title>
      -h, --help              Show help information.
2022-09-26 18:47:40 -05:00
Luciano Almeida 78213f3192 Improving edit distance string extension (#446) 2022-06-04 22:26:16 -05:00
Nate Cook 5540737e97 Add customization point for command usage text (#400) 2022-02-11 13:41:27 -06:00
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
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
Aleksey Mashanov df24620865 Fix invalid indention of strings with short lines (#148) 2020-05-16 12:39:56 -05:00
Yu Ao 2f7e13ae2a Simplify the implementation of String.convertedToSnakeCase (#81)
* Add tests for String.convertedToSnakeCase

* Simplify the implementation of String.convertedToSnakeCase
2020-03-16 09:41:24 -05:00
Klaas Pieter Annema fd5b49c8dc Provide suggestions for unknown options (#10)
* Add String#editDistance(to:)

Uses levenshtein distance to determine how much two strings differ.

See: https://en.wikipedia.org/wiki/Levenshtein_distance

* Simplify unknownOptionMessage

The logic of Name#synopsisString was repeated in unknownOptionMessage.
This change sit so that unknownOptionMessage defer to Name's
implementation instead.

* Provide suggestions for unknown options
2020-03-02 11:21:03 -06:00
Nate Cook f6ac7b8118 Initial import of ArgumentParser 2020-02-27 15:45:22 -06:00