Skip to content

Commit d0f9af8

Browse files
committed
Automatically use the way the binary is invoked to generate autocompletion script
1 parent 32bbb92 commit d0f9af8

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

Diff for: binary.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,28 @@ func CurrentBinaryPath() (string, error) {
4343
return argv0, nil
4444
}
4545

46+
func CurrentBinaryInvocation() (string, error) {
47+
if len(os.Args) == 0 || os.Args[0] == "" {
48+
return "", errors.New("no binary invokation found")
49+
}
50+
51+
return os.Args[0], nil
52+
}
53+
4654
func (c *Context) CurrentBinaryPath() string {
47-
path, _ := CurrentBinaryPath()
55+
path, err := CurrentBinaryPath()
56+
if err != nil {
57+
panic(err)
58+
}
4859

4960
return path
5061
}
62+
63+
func (c *Context) CurrentBinaryInvocation() string {
64+
invocation, err := CurrentBinaryInvocation()
65+
if err != nil {
66+
panic(err)
67+
}
68+
69+
return invocation
70+
}

Diff for: resources/completion.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# versions are used)
2929
_{{ .App.HelpName }}_console() {
3030
# shellcheck disable=SC2068
31-
{{ .CurrentBinaryPath }} console $@
31+
{{ .CurrentBinaryInvocation }} console $@
3232
}
3333

3434
_complete_{{ .App.HelpName }}() {

Diff for: resources/completion.fish

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ function __complete_{{ .App.HelpName }}
2727
set -lx COMP_LINE (commandline -cp)
2828
test -z (commandline -ct)
2929
and set COMP_LINE "$COMP_LINE "
30-
{{ .CurrentBinaryPath }} self:autocomplete
30+
{{ .CurrentBinaryInvocation }} self:autocomplete
3131
end
3232

3333
# this wrapper function allows us to call Symfony autocompletion letting it
3434
# knows how to call the `bin/console` using the Symfony CLI binary (to ensure
3535
# the right env and PHP versions are used)
3636
function __complete_{{ .App.HelpName }}_console
37-
set -x _SF_CMD "{{ .CurrentBinaryPath }}" "console"
37+
set -x _SF_CMD "{{ .CurrentBinaryInvocation }}" "console"
3838
_sf_console
3939
end
4040

Diff for: resources/completion.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# versions are used)
3232
_{{ .App.HelpName }}_console() {
3333
# shellcheck disable=SC2068
34-
{{ .CurrentBinaryPath }} console $@
34+
{{ .CurrentBinaryInvocation }} console $@
3535
}
3636

3737
_complete_{{ .App.HelpName }}() {

0 commit comments

Comments
 (0)