Skip to content

Commit df75d70

Browse files
authored
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.
1 parent 020800d commit df75d70

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Sources/ArgumentParser/Usage/DumpHelpGenerator.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fileprivate extension CommandInfoV0 {
107107
let arguments = commandStack
108108
.allArguments()
109109
.mergingCompositeArguments()
110-
.map(ArgumentInfoV0.init)
110+
.compactMap(ArgumentInfoV0.init)
111111

112112
self = CommandInfoV0(
113113
superCommands: superCommands,
@@ -121,9 +121,10 @@ fileprivate extension CommandInfoV0 {
121121
}
122122

123123
fileprivate extension ArgumentInfoV0 {
124-
init(argument: ArgumentDefinition) {
124+
init?(argument: ArgumentDefinition) {
125+
guard let kind = ArgumentInfoV0.KindV0(argument: argument) else { return nil }
125126
self.init(
126-
kind: ArgumentInfoV0.KindV0(argument: argument),
127+
kind: kind,
127128
shouldDisplay: argument.help.shouldDisplay,
128129
isOptional: argument.help.options.contains(.isOptional),
129130
isRepeating: argument.help.options.contains(.isRepeating),
@@ -138,7 +139,7 @@ fileprivate extension ArgumentInfoV0 {
138139
}
139140

140141
fileprivate extension ArgumentInfoV0.KindV0 {
141-
init(argument: ArgumentDefinition) {
142+
init?(argument: ArgumentDefinition) {
142143
switch argument.kind {
143144
case .named:
144145
switch argument.update {
@@ -150,7 +151,7 @@ fileprivate extension ArgumentInfoV0.KindV0 {
150151
case .positional:
151152
self = .positional
152153
case .default:
153-
preconditionFailure("argument.kind must not be .default")
154+
return nil
154155
}
155156
}
156157
}

0 commit comments

Comments
 (0)