Skip to content

Commit 7e04f56

Browse files
authored
Rename ...using_command fish function, set $cmd in local scope (#377)
__fish_* should not be used by external projects. set -l cmd in case user has a global or universal `cmd` defined.
1 parent d7f6384 commit 7e04f56

File tree

3 files changed

+49
-49
lines changed

3 files changed

+49
-49
lines changed

Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ struct FishCompletionsGenerator {
22
static func generateCompletionScript(_ type: ParsableCommand.Type) -> String {
33
let programName = type._commandName
44
let helper = """
5-
function __fish_\(programName)_using_command
6-
set cmd (commandline -opc)
5+
function _swift_\(programName)_using_command
6+
set -l cmd (commandline -opc)
77
if [ (count $cmd) -eq (count $argv) ]
88
for i in (seq (count $argv))
99
if [ $cmd[$i] != $argv[$i] ]
@@ -14,7 +14,7 @@ struct FishCompletionsGenerator {
1414
end
1515
return 1
1616
end
17-
17+
1818
"""
1919

2020
let completions = generateCompletions(commandChain: [programName], [type])
@@ -37,7 +37,7 @@ struct FishCompletionsGenerator {
3737
}
3838
}
3939

40-
let prefix = "complete -c \(programName) -n '__fish_\(programName)_using_command"
40+
let prefix = "complete -c \(programName) -n '_swift_\(programName)_using_command"
4141
/// We ask each suggestion to produce 2 pieces of information
4242
/// - Parameters
4343
/// - ancestors: a list of "ancestor" which must be present in the current shell buffer for

Tests/ArgumentParserExampleTests/MathExampleTests.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ _math
545545
"""
546546

547547
private let fishCompletionScriptText = """
548-
function __fish_math_using_command
549-
set cmd (commandline -opc)
548+
function _swift_math_using_command
549+
set -l cmd (commandline -opc)
550550
if [ (count $cmd) -eq (count $argv) ]
551551
for i in (seq (count $argv))
552552
if [ $cmd[$i] != $argv[$i] ]
@@ -557,33 +557,33 @@ function __fish_math_using_command
557557
end
558558
return 1
559559
end
560-
complete -c math -n '__fish_math_using_command math' -f -l version -d 'Show the version.'
561-
complete -c math -n '__fish_math_using_command math' -f -s h -l help -d 'Show help information.'
562-
complete -c math -n '__fish_math_using_command math' -f -a 'add' -d 'Print the sum of the values.'
563-
complete -c math -n '__fish_math_using_command math' -f -a 'multiply' -d 'Print the product of the values.'
564-
complete -c math -n '__fish_math_using_command math' -f -a 'stats' -d 'Calculate descriptive statistics.'
565-
complete -c math -n '__fish_math_using_command math' -f -a 'help' -d 'Show subcommand help information.'
566-
complete -c math -n '__fish_math_using_command math add' -f -l hex-output -s x -d 'Use hexadecimal notation for the result.'
567-
complete -c math -n '__fish_math_using_command math add' -f -s h -l help -d 'Show help information.'
568-
complete -c math -n '__fish_math_using_command math multiply' -f -l hex-output -s x -d 'Use hexadecimal notation for the result.'
569-
complete -c math -n '__fish_math_using_command math multiply' -f -s h -l help -d 'Show help information.'
570-
complete -c math -n '__fish_math_using_command math stats' -f -s h -l help -d 'Show help information.'
571-
complete -c math -n '__fish_math_using_command math stats' -f -a 'average' -d 'Print the average of the values.'
572-
complete -c math -n '__fish_math_using_command math stats' -f -a 'stdev' -d 'Print the standard deviation of the values.'
573-
complete -c math -n '__fish_math_using_command math stats' -f -a 'quantiles' -d 'Print the quantiles of the values (TBD).'
574-
complete -c math -n '__fish_math_using_command math stats' -f -a 'help' -d 'Show subcommand help information.'
575-
complete -c math -n '__fish_math_using_command math stats average' -f -r -l kind -d 'The kind of average to provide.'
576-
complete -c math -n '__fish_math_using_command math stats average --kind' -f -k -a 'mean median mode'
577-
complete -c math -n '__fish_math_using_command math stats average' -f -l version -d 'Show the version.'
578-
complete -c math -n '__fish_math_using_command math stats average' -f -s h -l help -d 'Show help information.'
579-
complete -c math -n '__fish_math_using_command math stats stdev' -f -s h -l help -d 'Show help information.'
580-
complete -c math -n '__fish_math_using_command math stats quantiles' -f -r -l file
581-
complete -c math -n '__fish_math_using_command math stats quantiles --file' -f -a '(for i in *.{txt,md}; echo $i;end)'
582-
complete -c math -n '__fish_math_using_command math stats quantiles' -f -r -l directory
583-
complete -c math -n '__fish_math_using_command math stats quantiles --directory' -f -a '(__fish_complete_directories)'
584-
complete -c math -n '__fish_math_using_command math stats quantiles' -f -r -l shell
585-
complete -c math -n '__fish_math_using_command math stats quantiles --shell' -f -a '(head -100 /usr/share/dict/words | tail -50)'
586-
complete -c math -n '__fish_math_using_command math stats quantiles' -f -r -l custom
587-
complete -c math -n '__fish_math_using_command math stats quantiles --custom' -f -a '(command math ---completion stats quantiles -- --custom (commandline -opc)[1..-1])'
588-
complete -c math -n '__fish_math_using_command math stats quantiles' -f -s h -l help -d 'Show help information.'
560+
complete -c math -n '_swift_math_using_command math' -f -l version -d 'Show the version.'
561+
complete -c math -n '_swift_math_using_command math' -f -s h -l help -d 'Show help information.'
562+
complete -c math -n '_swift_math_using_command math' -f -a 'add' -d 'Print the sum of the values.'
563+
complete -c math -n '_swift_math_using_command math' -f -a 'multiply' -d 'Print the product of the values.'
564+
complete -c math -n '_swift_math_using_command math' -f -a 'stats' -d 'Calculate descriptive statistics.'
565+
complete -c math -n '_swift_math_using_command math' -f -a 'help' -d 'Show subcommand help information.'
566+
complete -c math -n '_swift_math_using_command math add' -f -l hex-output -s x -d 'Use hexadecimal notation for the result.'
567+
complete -c math -n '_swift_math_using_command math add' -f -s h -l help -d 'Show help information.'
568+
complete -c math -n '_swift_math_using_command math multiply' -f -l hex-output -s x -d 'Use hexadecimal notation for the result.'
569+
complete -c math -n '_swift_math_using_command math multiply' -f -s h -l help -d 'Show help information.'
570+
complete -c math -n '_swift_math_using_command math stats' -f -s h -l help -d 'Show help information.'
571+
complete -c math -n '_swift_math_using_command math stats' -f -a 'average' -d 'Print the average of the values.'
572+
complete -c math -n '_swift_math_using_command math stats' -f -a 'stdev' -d 'Print the standard deviation of the values.'
573+
complete -c math -n '_swift_math_using_command math stats' -f -a 'quantiles' -d 'Print the quantiles of the values (TBD).'
574+
complete -c math -n '_swift_math_using_command math stats' -f -a 'help' -d 'Show subcommand help information.'
575+
complete -c math -n '_swift_math_using_command math stats average' -f -r -l kind -d 'The kind of average to provide.'
576+
complete -c math -n '_swift_math_using_command math stats average --kind' -f -k -a 'mean median mode'
577+
complete -c math -n '_swift_math_using_command math stats average' -f -l version -d 'Show the version.'
578+
complete -c math -n '_swift_math_using_command math stats average' -f -s h -l help -d 'Show help information.'
579+
complete -c math -n '_swift_math_using_command math stats stdev' -f -s h -l help -d 'Show help information.'
580+
complete -c math -n '_swift_math_using_command math stats quantiles' -f -r -l file
581+
complete -c math -n '_swift_math_using_command math stats quantiles --file' -f -a '(for i in *.{txt,md}; echo $i;end)'
582+
complete -c math -n '_swift_math_using_command math stats quantiles' -f -r -l directory
583+
complete -c math -n '_swift_math_using_command math stats quantiles --directory' -f -a '(__fish_complete_directories)'
584+
complete -c math -n '_swift_math_using_command math stats quantiles' -f -r -l shell
585+
complete -c math -n '_swift_math_using_command math stats quantiles --shell' -f -a '(head -100 /usr/share/dict/words | tail -50)'
586+
complete -c math -n '_swift_math_using_command math stats quantiles' -f -r -l custom
587+
complete -c math -n '_swift_math_using_command math stats quantiles --custom' -f -a '(command math ---completion stats quantiles -- --custom (commandline -opc)[1..-1])'
588+
complete -c math -n '_swift_math_using_command math stats quantiles' -f -s h -l help -d 'Show help information.'
589589
"""

Tests/ArgumentParserUnitTests/CompletionScriptTests.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ _escaped-command
243243
"""
244244

245245
private let fishBaseCompletions = """
246-
function __fish_base_using_command
247-
set cmd (commandline -opc)
246+
function _swift_base_using_command
247+
set -l cmd (commandline -opc)
248248
if [ (count $cmd) -eq (count $argv) ]
249249
for i in (seq (count $argv))
250250
if [ $cmd[$i] != $argv[$i] ]
@@ -255,16 +255,16 @@ function __fish_base_using_command
255255
end
256256
return 1
257257
end
258-
complete -c base -n '__fish_base_using_command base' -f -r -l name -d 'The user\\'s name.'
259-
complete -c base -n '__fish_base_using_command base' -f -r -l kind
260-
complete -c base -n '__fish_base_using_command base --kind' -f -k -a 'one two custom-three'
261-
complete -c base -n '__fish_base_using_command base' -f -r -l other-kind
262-
complete -c base -n '__fish_base_using_command base --other-kind' -f -k -a '1 2 3'
263-
complete -c base -n '__fish_base_using_command base' -f -r -l path1
264-
complete -c base -n '__fish_base_using_command base --path1' -f -a '(for i in *.{}; echo $i;end)'
265-
complete -c base -n '__fish_base_using_command base' -f -r -l path2
266-
complete -c base -n '__fish_base_using_command base --path2' -f -a '(for i in *.{}; echo $i;end)'
267-
complete -c base -n '__fish_base_using_command base' -f -r -l path3
268-
complete -c base -n '__fish_base_using_command base --path3' -f -k -a 'a b c'
269-
complete -c base -n '__fish_base_using_command base' -f -s h -l help -d 'Show help information.'
258+
complete -c base -n '_swift_base_using_command base' -f -r -l name -d 'The user\\'s name.'
259+
complete -c base -n '_swift_base_using_command base' -f -r -l kind
260+
complete -c base -n '_swift_base_using_command base --kind' -f -k -a 'one two custom-three'
261+
complete -c base -n '_swift_base_using_command base' -f -r -l other-kind
262+
complete -c base -n '_swift_base_using_command base --other-kind' -f -k -a '1 2 3'
263+
complete -c base -n '_swift_base_using_command base' -f -r -l path1
264+
complete -c base -n '_swift_base_using_command base --path1' -f -a '(for i in *.{}; echo $i;end)'
265+
complete -c base -n '_swift_base_using_command base' -f -r -l path2
266+
complete -c base -n '_swift_base_using_command base --path2' -f -a '(for i in *.{}; echo $i;end)'
267+
complete -c base -n '_swift_base_using_command base' -f -r -l path3
268+
complete -c base -n '_swift_base_using_command base --path3' -f -k -a 'a b c'
269+
complete -c base -n '_swift_base_using_command base' -f -s h -l help -d 'Show help information.'
270270
"""

0 commit comments

Comments
 (0)