mirror of https://github.com/docker/docs.git
Merge pull request #2027 from dgageot/2019-fix-env-hints
FIX #2019 invalid env hints
This commit is contained in:
commit
cb473ad0a7
|
@ -59,7 +59,7 @@ func cmdEnv(c *cli.Context) {
|
|||
|
||||
t := template.New("envConfig")
|
||||
|
||||
usageHint := generateUsageHint(c.App.Name, c.Args().First(), userShell)
|
||||
usageHint := generateUsageHint(c.App.Name, c.Args().First(), userShell, c.Bool("no-proxy"), c.Bool("swarm"))
|
||||
|
||||
shellCfg := &ShellConfig{
|
||||
DockerCertPath: authOptions.CertDir,
|
||||
|
@ -164,29 +164,25 @@ func cmdEnv(c *cli.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func generateUsageHint(appName, machineName, userShell string) string {
|
||||
func generateUsageHint(appName, machineName, userShell string, noProxy bool, swarm bool) string {
|
||||
flags := ""
|
||||
if noProxy {
|
||||
flags += "--no-proxy "
|
||||
}
|
||||
if swarm {
|
||||
flags += "--swarm "
|
||||
}
|
||||
|
||||
cmd := ""
|
||||
switch userShell {
|
||||
case "fish":
|
||||
if machineName != "" {
|
||||
cmd = fmt.Sprintf("eval (%s env %s)", appName, machineName)
|
||||
} else {
|
||||
cmd = fmt.Sprintf("eval (%s env)", appName)
|
||||
}
|
||||
cmd = fmt.Sprintf("eval (%s env --shell=fish %s%s)", appName, flags, machineName)
|
||||
case "powershell":
|
||||
if machineName != "" {
|
||||
cmd = fmt.Sprintf("%s env --shell=powershell %s | Invoke-Expression", appName, machineName)
|
||||
} else {
|
||||
cmd = fmt.Sprintf("%s env --shell=powershell | Invoke-Expression", appName)
|
||||
}
|
||||
cmd = fmt.Sprintf("%s env --shell=powershell %s%s | Invoke-Expression", appName, flags, machineName)
|
||||
case "cmd":
|
||||
cmd = "copy and paste the above values into your command prompt"
|
||||
default:
|
||||
if machineName != "" {
|
||||
cmd = fmt.Sprintf("eval \"$(%s env %s)\"", appName, machineName)
|
||||
} else {
|
||||
cmd = fmt.Sprintf("eval \"$(%s env)\"", appName)
|
||||
}
|
||||
cmd = fmt.Sprintf("eval \"$(%s env %s%s)\"", appName, flags, machineName)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("# Run this command to configure your shell: \n# %s\n", cmd)
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestHints(t *testing.T) {
|
||||
var tests = []struct {
|
||||
userShell string
|
||||
noProxy bool
|
||||
swarm bool
|
||||
hints string
|
||||
}{
|
||||
{"", false, false, "# Run this command to configure your shell: \n# eval \"$(machine env default)\"\n"},
|
||||
{"", true, false, "# Run this command to configure your shell: \n# eval \"$(machine env --no-proxy default)\"\n"},
|
||||
{"", false, true, "# Run this command to configure your shell: \n# eval \"$(machine env --swarm default)\"\n"},
|
||||
{"", true, true, "# Run this command to configure your shell: \n# eval \"$(machine env --no-proxy --swarm default)\"\n"},
|
||||
|
||||
{"fish", false, false, "# Run this command to configure your shell: \n# eval (machine env --shell=fish default)\n"},
|
||||
{"fish", true, false, "# Run this command to configure your shell: \n# eval (machine env --shell=fish --no-proxy default)\n"},
|
||||
{"fish", false, true, "# Run this command to configure your shell: \n# eval (machine env --shell=fish --swarm default)\n"},
|
||||
{"fish", true, true, "# Run this command to configure your shell: \n# eval (machine env --shell=fish --no-proxy --swarm default)\n"},
|
||||
|
||||
{"powershell", false, false, "# Run this command to configure your shell: \n# machine env --shell=powershell default | Invoke-Expression\n"},
|
||||
{"powershell", true, false, "# Run this command to configure your shell: \n# machine env --shell=powershell --no-proxy default | Invoke-Expression\n"},
|
||||
{"powershell", false, true, "# Run this command to configure your shell: \n# machine env --shell=powershell --swarm default | Invoke-Expression\n"},
|
||||
{"powershell", true, true, "# Run this command to configure your shell: \n# machine env --shell=powershell --no-proxy --swarm default | Invoke-Expression\n"},
|
||||
|
||||
{"cmd", false, false, "# Run this command to configure your shell: \n# copy and paste the above values into your command prompt\n"},
|
||||
{"cmd", true, false, "# Run this command to configure your shell: \n# copy and paste the above values into your command prompt\n"},
|
||||
{"cmd", false, true, "# Run this command to configure your shell: \n# copy and paste the above values into your command prompt\n"},
|
||||
{"cmd", true, true, "# Run this command to configure your shell: \n# copy and paste the above values into your command prompt\n"},
|
||||
}
|
||||
|
||||
for _, expected := range tests {
|
||||
hints := generateUsageHint("machine", "default", expected.userShell, expected.noProxy, expected.swarm)
|
||||
|
||||
assert.Equal(t, expected.hints, hints)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue