8000 feat: allow to override the path to the Symfony Console · tucksaun/symfonycli@a2d7850 · GitHub
[go: up one dir, main page]

Skip to content

Commit a2d7850

Browse files
committed
feat: allow to override the path to the Symfony Console
When running `symfony console` we are currently looking for a `bin/console` or a `app/console` file to run. What if the user renamed the file? or if they have a non "stantard" project structure? This PR intends to introduce a way one can override the path to the console by defining `SYMFONY_CONSOLE_PATH` environment variable.
1 parent 4d31489 commit a2d7850

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

commands/completion_posix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func autocompleteSymfonyConsoleWrapper(context *console.Context, words complete.
5050
// Composer does not support those options yet, so we only use them for Symfony Console
5151
args = append(args, "-a1", fmt.Sprintf("-s%s", console.GuessShell()))
5252

53-
if executor, err := php.SymfonyConsoleExecutor(args); err == nil {
53+
if executor, err := php.SymfonyConsoleExecutor(terminal.Logger, args); err == nil {
5454
os.Exit(executor.Execute(false))
5555
}
5656

local/php/symfony.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,31 @@ import (
2424
"path/filepath"
2525

2626
"github.com/pkg/errors"
27+
"github.com/rs/zerolog"
28+
"github.com/symfony-cli/symfony-cli/envs"
2729
)
2830

2931
// SymfonyConsoleExecutor returns an Executor prepared to run Symfony Console.
3032
// It returns an error if no console binary is found.
31-
func SymfonyConsoleExecutor(args []string) (*Executor, error) {
33+
func SymfonyConsoleExecutor(logger zerolog.Logger, args []string) (*Executor, error) {
3234
dir, err := os.Getwd()
3335
if err != nil {
3436
return nil, errors.WithStack(err)
3537
}
3638

3739
for {
38-
for _, consolePath := range []string{"bin/console", "app/console"} {
40+
consolePaths := []string{"bin/console", "app/console"}
41+
if consolePath, isConsolePathSpecified := envs.LookupEnv(dir, "SYMFONY_CONSOLE_PATH"); isConsolePathSpecified {
42+
consolePaths = []string{consolePath}
43+
}
44+
45+
for _, consolePath := range consolePaths {
46+
logger.Debug().Str("consolePath", consolePath).Str("directory", dir).Msgf("Looking for Symfony console")
3947
consolePath = filepath.Join(dir, consolePath)
4048
if _, err := os.Stat(consolePath); err == nil {
4149
return &Executor{
4250
BinName: "php",
51+
Logger: logger,
4352
Args: append([]string{"php", consolePath}, args...),
4453
}, nil
4554
}

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ func main() {
7474
}
7575
// called via "symfony console"?
7676
if len(args) >= 2 && args[1] == "console" {
77-
if executor, err := php.SymfonyConsoleExecutor(args[2:]); err == nil {
78-
executor.Logger = terminal.Logger
77+
if executor, err := php.SymfonyConsoleExecutor(terminal.Logger, args[2:]); err == nil {
7978
executor.ExtraEnv = getCliExtraEnv()
8079
os.Exit(executor.Execute(false))
8180
}

0 commit comments

Comments
 (0)
0