Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix help message with @OptionGroup ParsableCommand #613

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions Sources/ArgumentParser/Parsing/ArgumentDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
struct DecodedArguments {
var type: ParsableArguments.Type
var value: ParsableArguments
var isOptionGroup: Bool = false

var commandType: ParsableCommand.Type? {
type as? ParsableCommand.Type
if isOptionGroup { return nil }
return type as? ParsableCommand.Type
}

var command: ParsableCommand? {
value as? ParsableCommand
if isOptionGroup { return nil }
return value as? ParsableCommand
}
}

Expand Down Expand Up @@ -182,7 +185,7 @@ struct SingleValueDecoder: Decoder {
}

func saveValue<T: ParsableArguments>(_ value: T, type: T.Type = T.self) {
underlying.previouslyDecoded.append(DecodedArguments(type: type, value: value))
underlying.previouslyDecoded.append(DecodedArguments(type: type, value: value, isOptionGroup: true))
}

struct SingleValueContainer: SingleValueDecodingContainer {
Expand Down
25 changes: 25 additions & 0 deletions Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,31 @@ extension HelpGenerationTests {

""")
}

struct ParsableCommandOption : ParsableCommand {
struct Group: ParsableCommand {
@Option
var opt: Int = 0
}
@OptionGroup
var options: Group
@Argument
var arg: String = ""
}

func testHelpWithParsableCommandOption() {
AssertHelp(.default, for: ParsableCommandOption.self, equals: """
USAGE: parsable-command-option [--opt <opt>] [<arg>]

ARGUMENTS:
<arg>

OPTIONS:
--opt <opt> (default: 0)
-h, --help Show help information.

""")
}
}

extension HelpGenerationTests {
Expand Down