8000 Add autocompletion support for `pie` wrapper · tucksaun/symfonycli@3c26afe · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c26afe

Browse files
committed
Add autocompletion support for pie wrapper
1 parent b3e8467 commit 3c26afe

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

commands/completion_posix.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,37 @@ func init() {
4545
console.CompletionTemplates = completionTemplates
4646
}
4747

48-
func autocompleteSymfonyConsoleWrapper(context *console.Context, words complete.Args) []string {
49-
args := buildSymfonyAutocompleteArgs("console", words)
48+
func autocompleteApplicationConsoleWrapper(context *console.Context, words complete.Args) []string {
49+
return autocompleteSymfonyConsoleWrapper(words, "console", func(args []string) (*Executor, error) {
50+
return php.SymfonyConsoleExecutor(terminal.Logger, args)
51+
})
52+
}
53+
54+
func autocompletePieWrapper(context *console.Context, words complete.Args) []string {
55+
return autocompleteSymfonyConsoleWrapper(words, "console", func(args []string) (*Executor, error) {
56+
return php.Pie("", args, []string{}, context.App.Writer, context.App.ErrWriter, io.Discard, terminal.Logger)
57+
})
58+
}
59+
60+
// autocompleteSymfonyConsoleWrapper bridges the symfony-cli/console (Go)
61+
// autocompletion with a symfony/console (PHP) one.
62+
func autocompleteSymfonyConsoleWrapper(words complete.Args, commandName string, executor func(args []string) (*Executor, error)) []string {
63+
args := buildSymfonyAutocompleteArgs(commandName, words)
5064
// Composer does not support those options yet, so we only use them for Symfony Console
5165
args = append(args, "-a1", fmt.Sprintf("-s%s", console.GuessShell()))
5266

53-
if executor, err := php.SymfonyConsoleExecutor(terminal.Logger, args); err == nil {
67+
if executor, err := executor(args); err == nil {
5468
os.Exit(executor.Execute(false))
5569
}
5670

5771
return []string{}
5872
}
5973

74+
// autocompleteComposerWrapper is a bridget between Go autocompletion and
75+
// Composer one. It does does use the generic one because Composer does not
76+
// support multiple shell yet.
6077
func autocompleteComposerWrapper(context *console.Context, words complete.Args) []string {
6178
args := buildSymfonyAutocompleteArgs("composer", words)
62-
// Composer does not support multiple shell yet, so we only use the default one
6379
args = append(args, "-sbash")
6480

6581
res := php.Composer("", args, []string{}, context.App.Writer, context.App.ErrWriter, io.Discard, terminal.Logger)

commands/wrappers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
// we use an alias to avoid the command being shown in the help but
4444
// still be available for completion
4545
Aliases: []*console.Alias{{Name: "pie"}},
46+
ShellComplete: autocompletePieWrapper,
4647
Action: func(c *console.Context) error {
4748
return console.IncorrectUsageError{ParentError: errors.New(`This command can only be run as "symfony pie"`)}
4849
},
@@ -56,7 +57,7 @@ var (
5657
Action: func(c *console.Context) error {
5758
return errors.New(`No Symfony console detected to run "symfony console"`)
5859
},
59-
ShellComplete: autocompleteSymfonyConsoleWrapper,
60+
ShellComplete: autocompleteApplicationConsoleWrapper,
6061
}
6162
phpWrapper = &console.Command{
6263
Usage: "Runs the named binary using the configured PHP version",

0 commit comments

Comments
 (0)
0