8000 refactor: add Executor.CommandLine · symfony-cli/symfony-cli@09df7fa · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit 09df7fa

Browse files
committed
refactor: add Executor.CommandLine
1 parent f74ffa9 commit 09df7fa

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

local/php/composer.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,17 @@ func Composer(dir string, args, env []string, stdout, stderr, logger io.Writer,
8989
error: errors.Wrap(err, "unable to find composer, get it at https://getcomposer.org/download/"),
9090
}
9191
}
92-
fmt.Fprintf(logger, " (running %s %s)\n\n", path, strings.TrimSpace(strings.Join(args, " ")))
92+
e.Args = append([]string{"php", path}, args...)
93+
fmt.Fprintf(logger, " (running %s)\n\n", e.CommandLine())
94+
} else {
95+
e.Args = append([]string{"php", path}, args...)
9396
}
9497

95-
e.Args = append([]string{"php", path}, args...)
9698
ret := e.Execute(false)
9799
if ret != 0 {
98100
return ComposerResult{
99101
code: ret,
100-
error: errors.Errorf("unable to run %s %s", path, strings.Join(args, " ")),
102+
error: errors.Errorf("unable to run %s", e.CommandLine()),
101103
}
102104
}
103105
return ComposerResult{}

local/php/executor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ func GetBinaryNames() []string {
7474
return []string{"php", "pecl", "pear", "php-fpm", "php-cgi", "php-config", "phpdbg", "phpize"}
7575
}
7676

77+
func (e Executor) CommandLine() string {
78+
return strings.TrimSpace(strings.Join(e.Args, " "))
79+
}
80+
7781
func (e *Executor) lookupPHP(cliDir string, forceReload bool) (*phpstore.Version, string, bool, error) {
7882
phpStore := phpstore.New(cliDir, forceReload, nil)
7983
v, source, warning, err := phpStore.BestVersionForDir(e.scriptDir)

local/php/executor_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ func (s *ExecutorSuite) TestNotEnoughArgs(c *C) {
112112
c.Assert((&Executor{BinName: "php"}).Execute(true), Equals, 1)
113113
}
114114

115+
func (s *ExecutorSuite) TestCommandLineFormatting(c *C) {
116+
c.Assert((&Executor{}).CommandLine(), Equals, "")
117+
118+
c.Assert((&Executor{Args: []string{"php"}}).CommandLine(), Equals, "php")
119+
120+
c.Assert((&Executor{Args: []string{"php", "-dmemory_limit=-1", "/path/to/composer.phar"}}).CommandLine(), Equals, "php -dmemory_limit=-1 /path/to/composer.phar")
121+
}
122+
115123
func (s *ExecutorSuite) TestForwardExitCode(c *C) {
116124
defer restoreExecCommand()
117125
fakeExecCommand("exit-code", "5")

0 commit comments

Comments
 (0)
0