|
10 | 10 | // |
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 | import SwiftOptions |
13 | | -import TSCBasic |
14 | | -import TSCLibc |
15 | | -import TSCUtility |
| 13 | +import ArgumentParser |
16 | 14 |
|
17 | | -extension DriverKind: StringEnumArgument { |
18 | | - public static var completion: ShellCompletion { .none } |
19 | | -} |
20 | | - |
21 | | -struct Options { |
22 | | - var driverKind: DriverKind = .interactive |
23 | | - var showHidden: Bool = false |
24 | | -} |
| 15 | +extension DriverKind: ExpressibleByArgument, Decodable {} |
25 | 16 |
|
26 | | -let driverOptionTable = OptionTable() |
27 | | -let parser = ArgumentParser(commandName: "swift help", |
28 | | - usage: " ", |
29 | | - overview: "Swift help tool", |
30 | | - seeAlso: nil) |
31 | | -let binder = ArgumentBinder<Options>() |
32 | | -binder.bind(option: parser.add(option: "-show-hidden", |
33 | | - usage: "List hidden (unsupported) options"), |
34 | | - to: { $0.showHidden = $1 }) |
35 | | -binder.bind(option: parser.add(option: "-tool", kind: DriverKind.self, |
36 | | - usage: "The tool to list options of"), |
37 | | - to: { $0.driverKind = $1 }) |
| 17 | +struct SwiftHelp: ParsableCommand { |
| 18 | + @ArgumentParser.Option(name: .customLong("tool", withSingleDash: true), |
| 19 | + default: .interactive, |
| 20 | + help: "The tool to list options of") |
| 21 | + var tool: DriverKind |
38 | 22 |
|
39 | | -do { |
40 | | - let parseResult = try parser.parse(Array(CommandLine.arguments.dropFirst())) |
41 | | - var options = Options() |
42 | | - try binder.fill(parseResult: parseResult, into: &options) |
| 23 | + @Flag(name: .customLong("show-hidden", withSingleDash: true), |
| 24 | + help: "List hidden (unsupported) options") |
| 25 | + var showHidden: Bool |
43 | 26 |
|
44 | | - // Print the option table. |
45 | | - driverOptionTable.printHelp(driverKind: options.driverKind, |
46 | | - includeHidden: options.showHidden) |
47 | | -} catch { |
48 | | - stderrStream <<< "error: " <<< error.localizedDescription |
49 | | - stderrStream.flush() |
50 | | - exit(EXIT_FAILURE) |
| 27 | + func run() throws { |
| 28 | + let driverOptionTable = OptionTable() |
| 29 | + driverOptionTable.printHelp(driverKind: tool, includeHidden: showHidden) |
| 30 | + } |
51 | 31 | } |
| 32 | + |
| 33 | +SwiftHelp.main() |
0 commit comments