Skip to content

Consistently use enum raw value instead of description on the command line #801

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Sources/ArgumentParser/Parsable Properties/Flag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ extension Flag where Value == Bool? {
exclusivity: exclusivity,
help: help)
}

}

extension Flag where Value == Bool {
Expand Down Expand Up @@ -556,7 +555,6 @@ extension Flag {
key: parentKey, value: value, origin: origin, values: &values,
exclusivity: exclusivity)
}))

}
return ArgumentSet(args)
})
Expand Down
7 changes: 7 additions & 0 deletions Sources/ArgumentParser/Parsable Types/EnumerableFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ extension EnumerableFlag {
nil
}
}

extension EnumerableFlag
where Self: RawRepresentable, Self: CustomStringConvertible {
public var description: String {
String(describing: rawValue)
}
}
2 changes: 1 addition & 1 deletion Sources/ArgumentParser/Parsing/InputKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// Represents the path to a parsed field, annotated with ``Flag``, ``Option``
/// or ``Argument``.
///
/// Fields that are directly declared on a ``ParsableComand`` have a path of
/// Fields that are directly declared on a ``ParsableCommand`` have a path of
/// length 1, while fields that are declared indirectly (and included via an
/// option group) have longer paths.
struct InputKey: Hashable {
Expand Down
7 changes: 6 additions & 1 deletion Tests/ArgumentParserUnitTests/CompletionScriptTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ extension CompletionScriptTests {
}
}

enum Kind: String, ExpressibleByArgument, EnumerableFlag {
enum Kind:
String,
ExpressibleByArgument,
EnumerableFlag,
CustomStringConvertible
{
case one, two
case three = "custom-three"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ _base-test() {
local -i positional_number
local -a unparsed_words=("${COMP_WORDS[@]:1:${COMP_CWORD}}")

local -a flags=(--one --two --three --kind-counter -h --help)
local -a flags=(--one --two --custom-three --kind-counter -h --help)
local -a options=(--name --kind --other-kind --path1 --path2 --path3 --rep1 -r --rep2)
__base-test_offer_flags_options 2

Expand Down
4 changes: 2 additions & 2 deletions Tests/ArgumentParserUnitTests/Snapshots/testBase_Fish().fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function __base-test_should_offer_completions_for -a expected_commands -a expect

switch $unparsed_tokens[1]
case 'base-test'
__base-test_parse_subcommand 2 'name=' 'kind=' 'other-kind=' 'path1=' 'path2=' 'path3=' 'one' 'two' 'three' 'kind-counter' 'rep1=' 'r/rep2=' 'h/help'
__base-test_parse_subcommand 2 'name=' 'kind=' 'other-kind=' 'path1=' 'path2=' 'path3=' 'one' 'two' 'custom-three' 'kind-counter' 'rep1=' 'r/rep2=' 'h/help'
switch $unparsed_tokens[1]
case 'sub-command'
__base-test_parse_subcommand 0 'h/help'
Expand Down Expand Up @@ -76,7 +76,7 @@ complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'path3' -rfka 'c1_fish c2_fish c3_fish'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'one'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'two'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'three'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'custom-three'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'kind-counter'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'rep1' -rfka ''
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -s 'r' -l 'rep2' -rfka ''
Expand Down
2 changes: 1 addition & 1 deletion Tests/ArgumentParserUnitTests/Snapshots/testBase_Zsh().zsh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ _base-test() {
'--path3:path3:{__base-test_complete "${___path3[@]}"}'
'--one'
'--two'
'--three'
'--custom-three'
'*--kind-counter'
'*--rep1:rep1:'
'*'{-r,--rep2}':rep2:'
Expand Down