…lines 1–7 unchanged (7 lines)
8// See https://swift.org/LICENSE.txt for license information
9//
10//===----------------------------------------------------------------------===//
11
12#if compiler(>=6.0)
13internal import ArgumentParserToolInfo
14internal import class Foundation.JSONEncoder
15#else
16import ArgumentParserToolInfo
17import class Foundation.JSONEncoder
18#endif
19
20internal struct DumpHelpGenerator {
21 private var toolInfo: ToolInfoV0
22
23 init(_ type: ParsableArguments.Type) {
24 self.init(commandStack: [type.asCommand])
25 }
26
27 init(commandStack: [ParsableCommand.Type]) {
28 self.toolInfo = ToolInfoV0(commandStack: commandStack)
29 }
30
31 func rendered() -> String {
32 let encoder = JSONEncoder()
33 encoder.outputFormatting = .prettyPrinted
34 encoder.outputFormatting.insert(.sortedKeys)
35 guard let encoded = try? encoder.encode(self.toolInfo) else { return "" }
36 return String(data: encoded, encoding: .utf8) ?? ""
37 }
38}
39
40extension BidirectionalCollection where Element == ParsableCommand.Type {
41 /// Returns the ArgumentSet for the last command in this stack, including
42 /// help and version flags, when appropriate.
…lines 43–219 unchanged (177 lines)