mirror of
https://github.com/docker/compose.git
synced 2025-07-28 08:04:09 +02:00
Fix 2 corner cases with PATH settings
* windows PATH should use windows separator (;) * do not add separator if initial PATH is empty (was creating PATH=:/path) Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
5e809acd87
commit
b604ba6246
11
cli/main.go
11
cli/main.go
@ -24,6 +24,7 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -73,13 +74,21 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(errors.Wrap(err, "unable to get absolute bin path"))
|
fatal(errors.Wrap(err, "unable to get absolute bin path"))
|
||||||
}
|
}
|
||||||
if err := os.Setenv("PATH", fmt.Sprintf("%s%s%s", os.Getenv("PATH"), os.PathListSeparator, path)); err != nil {
|
|
||||||
|
if err := os.Setenv("PATH", appendPaths(os.Getenv("PATH"), path)); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
// Seed random
|
// Seed random
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func appendPaths(envPath string, path string) string {
|
||||||
|
if envPath == "" {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
return strings.Join([]string{envPath, path}, string(os.PathListSeparator))
|
||||||
|
}
|
||||||
|
|
||||||
func isContextAgnosticCommand(cmd *cobra.Command) bool {
|
func isContextAgnosticCommand(cmd *cobra.Command) bool {
|
||||||
if cmd == nil {
|
if cmd == nil {
|
||||||
return false
|
return false
|
||||||
|
@ -69,3 +69,8 @@ func TestCheckOwnCommand(t *testing.T) {
|
|||||||
assert.Assert(t, !isContextAgnosticCommand(cmd.LogsCommand()))
|
assert.Assert(t, !isContextAgnosticCommand(cmd.LogsCommand()))
|
||||||
assert.Assert(t, !isContextAgnosticCommand(cmd.PsCommand()))
|
assert.Assert(t, !isContextAgnosticCommand(cmd.PsCommand()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAppendPaths(t *testing.T) {
|
||||||
|
assert.Equal(t, appendPaths("", "/bin/path"), "/bin/path")
|
||||||
|
assert.Equal(t, appendPaths("path1", "binaryPath"), "path1"+string(os.PathListSeparator)+"binaryPath")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user