Commit Graph
27 Commits
Author SHA1 Message Date
Nate Cook 2161ea4a6f Merge branch 'main' into feature/interactive 2023-02-09 22:54:44 -08:00
Rauhul Varma bc29743b72 Update tests with easier to read diff output (#529)
- Renames AssertEqualStringsIgnoringTrailingWhitespace to
  AssertEqualStrings and updates the implementation to require matching
  trailing whitespace.
- Updates AssertEqualStrings to include much easier to read diff output
  when CollectionDifference is available. This should add developers
  when tests fail by providing more clear errors.
2022-11-21 22:29:52 -08:00
Nate Cook 3469a65d52 Skip unsupported tests on Windows (#510) 2022-10-26 10:37:54 -05:00
Nate Cook 541f7c6e66 Fix post-merge issues 2022-10-13 22:41:03 -05:00
Nate Cook b92507afd3 Merge branch 'main' into feature/interactive
# Conflicts:
#	CHANGELOG.md
#	Tests/ArgumentParserEndToEndTests/DefaultSubcommandEndToEndTests.swift
#	Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift
#	Tests/ArgumentParserUnitTests/NameSpecificationTests.swift
#	Tests/ArgumentParserUnitTests/ParsableArgumentsValidationTests.swift
2022-10-10 10:43:27 -05:00
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
Nate Cook d7aa4401fe Declare Hashable conformance for ArgumentVisibility (#481)
In addition to being useful, this allows us to drop the `@testable`
annotation for the ArgumentParser import in ArgumentParserTestHelpers,
which resolves #463.
2022-09-01 15:23:45 -05:00
Rauhul Varma e978a3831f Default to single page manuals (#472)
- Changes the generate-manual --single-page argument to --multi-page, so
  generate-manual with create a single manual page with all subcommand
  information by default instead of many distinct files.
2022-08-26 00:03:35 -07:00
Kth d1d0eb4baa [GSoC] Partial initialization for ParsableCommand (#451)
* Initial proof of concept
2022-07-14 22:53:20 -05:00
Rauhul Varma 48a799e04a Add experimental manual page generation (#332)
- Adds a swift package manager command plugin called
  GenerateManualPlugin. The plugin can be invoked from the command line
  using `swift package experimental-generate-manual`. The plugin is
  prefixed for now with "experimental-" to indicate it is not mature and
  may see breaking changes to its CLI and output in the future. The
  plugin can be can be used to generate a manual in MDoc syntax for any
  swift-argument-parser tool that can be executed via
  `tool --experimental-dump-info`.
- The plugin works by converting the `ToolInfoV0` structure from the
  `ArgumentParserToolInfo` library into MDoc AST nodes using a custom
  (SwiftUI-esk) result builder DSL. The MDoc AST is then lowered to a
  string and written to disk.
- The MDoc AST included is not general purpose and doesn't represent the
  true language exactly, so it is private to the underlying
  `generate-manual` tool. In the future it would be interesting to
  finish fleshing out this MDoc library and spin it out, however this is
  not a priority.
- Next steps include:
  - Improving the command line interface for the plugin.
  - Adding support for "extended discussions" to Commands and exposing
    this information in manuals.
  - Further improve the escaping logic to properly escape MDoc macros
    that might happen to appear in user's help strings.
  - Ingesting external content a-la swift-docc so the entire tool
    documentation does not need to be included in the binary itself.
  - Bug fixes and addressing developer/user feedback.

Built with love,
@rauhul
2022-06-06 11:09:34 -05:00
Nate Cook 1141ed1e1b Support an async entry point for commands (#404)
Adds a new `AsyncParsableCommand` protocol, which provides a
`static func main() async` entry point and can call through to the root
command's or a subcommand's asynchronous `run()` method. For this
asynchronous execution, the root command must conform to `AsyncParsableCommand`,
but its subcommands can be a mix of asynchronous and synchronous commands.

Due to an issue in Swift 5.5, you can only use `@main` on an
`AsyncParsableCommand` root command starting in Swift 5.6.
This change also includes a workaround for clients that are using Swift 5.5.
Declare a separate type that conforms to `AsyncMainProtocol` and add the `@main`
attribute to that type.

```
@main enum Main: AsyncMain {
    typealias Command = <#command#>
}
```
2022-03-14 18:14:09 -05:00
Rauhul Varma 88af18f986 Change ArgumentVisibility into a struct (#413)
- Changes ArgumentVisibility from an enum to a struct. This will allow
  ArgumentParser to add cases in the future without breaking clients
  that could have been exhaustively switching across all cases. It also
  allows us to implement protocol conformances on the internal type and
  avoid exposing them on the public type.
2022-02-15 12:55:27 -06:00
Rauhul Varma e3673688cf Add abillity to generate hidden help (#410)
- Updates helpMessage(columns:) and helpMessage(for:columns:) with an
  includeHidden argument defaulted to false to allow for clients to
  programmatically generate hidden help.
2022-02-12 16:11:07 -08:00
Rauhul Varma 63e6c57b63 Provide non-experimental help-hidden flags (#409) 2022-02-12 16:50:09 -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
Jake Petroules b2e411887e Fix compile failure on iOS for Mac Catalyst support (#372) 2021-11-08 19:50:43 -06: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
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
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
Gwen Mittertreiner cb1f0456ac Fix CMake build on Linux (#238)
- TestHelpers has a implicit dependency on Foundation through
  ArgumentParser, so it needs to link against Foundation
- The find package calls should be REQUIRED and CONFIG so they can take
  advantage of CMake configs
2020-09-19 22:07:31 -05:00
Nate CookandErik Little aad1ac085b Make ParsableCommand.run() a mutating method (#163)
Co-authored-by: Erik Little <nuclear.ace@gmail.com>
2020-06-02 14:07:16 -05:00
Nate Cook 6c6b77c713 Test source compatibility for property wrappers (#172)
* Eliminate #file warnings

* Test source compatibility for property wrappers

This adds compilation tests for all the property wrappers, including
all the various permutations of their default parameter values.
2020-06-01 16:14:15 -05:00
Nate Cook 44fb59ef87 Add APIs for generating the help screen (#142)
* Add public API for generating help text

* Add tests for `helpMessage()`

* Update documentation

* Use new rendered method instead of property
2020-05-14 12:43:21 -05:00
Nate Cook 0b8a81924d Eliminate deprecated Process method calls.
Fixes #84.
2020-03-31 14:58:49 -05:00
Nate Cook ddc828f8cb Add an API for converting an error to an exit code (#79)
* Add an API for converting an error to an exit code

* Make ExitCode more useful as a value type

* Update tests to use ExitCode values

* Typo fix

* Add a test for ExitCode.isSuccess

* Switch to just using ExitCode for tests
2020-03-21 12:44:32 -05:00
Elliott Williams 34300696f5 Prefix test target names with "ArgumentParser" (#74)
* Prefix testing and test helper targets with ArgumentParser

* Replace SAP with ArgumentParser in imports and CMakeLists
2020-03-10 12:44:07 -05:00