Skip to content

Commit c94be10

Browse files
authored
Use enum raw values instead of description. (#801)
Signed-off-by: Ross Goldberg <[email protected]>
1 parent 4f680a7 commit c94be10

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

Sources/ArgumentParser/Parsable Properties/Flag.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ extension Flag where Value == Bool? {
250250
exclusivity: exclusivity,
251251
help: help)
252252
}
253-
254253
}
255254

256255
extension Flag where Value == Bool {
@@ -556,7 +555,6 @@ extension Flag {
556555
key: parentKey, value: value, origin: origin, values: &values,
557556
exclusivity: exclusivity)
558557
}))
559-
560558
}
561559
return ArgumentSet(args)
562560
})

Sources/ArgumentParser/Parsable Types/EnumerableFlag.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,10 @@ extension EnumerableFlag {
8181
nil
8282
}
8383
}
84+
85+
extension EnumerableFlag
86+
where Self: RawRepresentable, Self: CustomStringConvertible {
87+
public var description: String {
88+
String(describing: rawValue)
89+
}
90+
}

Sources/ArgumentParser/Parsing/InputKey.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// Represents the path to a parsed field, annotated with ``Flag``, ``Option``
1313
/// or ``Argument``.
1414
///
15-
/// Fields that are directly declared on a ``ParsableComand`` have a path of
15+
/// Fields that are directly declared on a ``ParsableCommand`` have a path of
1616
/// length 1, while fields that are declared indirectly (and included via an
1717
/// option group) have longer paths.
1818
struct InputKey: Hashable {

Tests/ArgumentParserUnitTests/CompletionScriptTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ extension CompletionScriptTests {
4848
}
4949
}
5050

51-
enum Kind: String, ExpressibleByArgument, EnumerableFlag {
51+
enum Kind:
52+
String,
53+
ExpressibleByArgument,
54+
EnumerableFlag,
55+
CustomStringConvertible
56+
{
5257
case one, two
5358
case three = "custom-three"
5459
}

Tests/ArgumentParserUnitTests/Snapshots/testBase_Bash().bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ _base-test() {
158158
local -i positional_number
159159
local -a unparsed_words=("${COMP_WORDS[@]:1:${COMP_CWORD}}")
160160

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

Tests/ArgumentParserUnitTests/Snapshots/testBase_Fish().fish

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function __base-test_should_offer_completions_for -a expected_commands -a expect
55

66
switch $unparsed_tokens[1]
77
case 'base-test'
8-
__base-test_parse_subcommand 2 'name=' 'kind=' 'other-kind=' 'path1=' 'path2=' 'path3=' 'one' 'two' 'three' 'kind-counter' 'rep1=' 'r/rep2=' 'h/help'
8+
__base-test_parse_subcommand 2 'name=' 'kind=' 'other-kind=' 'path1=' 'path2=' 'path3=' 'one' 'two' 'custom-three' 'kind-counter' 'rep1=' 'r/rep2=' 'h/help'
99
switch $unparsed_tokens[1]
1010
case 'sub-command'
1111
__base-test_parse_subcommand 0 'h/help'
@@ -76,7 +76,7 @@ complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"
7676
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'path3' -rfka 'c1_fish c2_fish c3_fish'
7777
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'one'
7878
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'two'
79-
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'three'
79+
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'custom-three'
8080
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'kind-counter'
8181
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l 'rep1' -rfka ''
8282
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -s 'r' -l 'rep2' -rfka ''

Tests/ArgumentParserUnitTests/Snapshots/testBase_Zsh().zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ _base-test() {
5252
'--path3:path3:{__base-test_complete "${___path3[@]}"}'
5353
'--one'
5454
'--two'
55-
'--three'
55+
'--custom-three'
5656
'*--kind-counter'
5757
'*--rep1:rep1:'
5858
'*'{-r,--rep2}':rep2:'

0 commit comments

Comments
 (0)