Merge pull request #3405 from eedeebee/3404-add-tcsh-support-to-env-command

Add tcsh support to --shell
This commit is contained in:
Nathan LeClaire 2016-06-01 15:56:28 -07:00
commit 52d0020542
4 changed files with 19 additions and 2 deletions

View File

@ -237,7 +237,7 @@ var Commands = []cli.Command{
},
cli.StringFlag{
Name: "shell",
Usage: "Force environment to be configured for a specified shell: [fish, cmd, powershell], default is auto-detect",
Usage: "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh], default is auto-detect",
},
cli.BoolFlag{
Name: "unset, u",

View File

@ -134,6 +134,10 @@ func shellCfgSet(c CommandLine, api libmachine.API) (*ShellConfig, error) {
shellCfg.Prefix = "SET "
shellCfg.Suffix = "\n"
shellCfg.Delimiter = "="
case "tcsh":
shellCfg.Prefix = "setenv "
shellCfg.Suffix = "\";\n"
shellCfg.Delimiter = " \""
case "emacs":
shellCfg.Prefix = "(setenv \""
shellCfg.Suffix = "\")\n"
@ -182,6 +186,10 @@ func shellCfgUnset(c CommandLine, api libmachine.API) (*ShellConfig, error) {
shellCfg.Prefix = "(setenv \""
shellCfg.Suffix = ")\n"
shellCfg.Delimiter = "\" nil"
case "tcsh":
shellCfg.Prefix = "unsetenv "
shellCfg.Suffix = ";\n"
shellCfg.Delimiter = ""
default:
shellCfg.Prefix = "unset "
shellCfg.Suffix = "\n"
@ -249,6 +257,9 @@ func (g *EnvUsageHintGenerator) GenerateUsageHint(userShell string, args []strin
case "emacs":
cmd = fmt.Sprintf("(with-temp-buffer (shell-command \"%s\" (current-buffer)) (eval-buffer))", commandLine)
comment = ";;"
case "tcsh":
cmd = fmt.Sprintf("eval `%s`", commandLine)
comment = ":"
default:
cmd = fmt.Sprintf("eval $(%s)", commandLine)
}

View File

@ -77,6 +77,12 @@ func TestHints(t *testing.T) {
{"emacs", []string{"./machine", "env", "--shell=emacs", "--swarm", "default"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --swarm default\" (current-buffer)) (eval-buffer))\n"},
{"emacs", []string{"./machine", "env", "--shell=emacs", "--no-proxy", "--swarm", "default"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --no-proxy --swarm default\" (current-buffer)) (eval-buffer))\n"},
{"emacs", []string{"./machine", "env", "--shell=emacs", "--unset"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --unset\" (current-buffer)) (eval-buffer))\n"},
{"tcsh", []string{"./machine", "env", "--shell=tcsh", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh default`\n"},
{"tcsh", []string{"./machine", "env", "--shell=tcsh", "--no-proxy", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --no-proxy default`\n"},
{"tcsh", []string{"./machine", "env", "--shell=tcsh", "--swarm", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --swarm default`\n"},
{"tcsh", []string{"./machine", "env", "--shell=tcsh", "--no-proxy", "--swarm", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --no-proxy --swarm default`\n"},
{"tcsh", []string{"./machine", "env", "--shell=tcsh", "--unset"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --unset`\n"},
}
for _, test := range tests {

View File

@ -25,7 +25,7 @@ a particular machine.
Options:
--swarm Display the Swarm config instead of the Docker daemon
--shell Force environment to be configured for a specified shell: [fish, cmd, powershell], default is sh/bash
--shell Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh], default is sh/bash
--unset, -u Unset variables instead of setting them
--no-proxy Add machine IP to NO_PROXY environment variable