mirror of https://github.com/docker/docs.git
				
				
				
			Add emacs support to env command
Signed-off-by: Doug MacEachern <dougm@vmware.com>
This commit is contained in:
		
							parent
							
								
									a1275f6f11
								
							
						
					
					
						commit
						4e58bb9434
					
				| 
						 | 
					@ -130,6 +130,10 @@ func shellCfgSet(c CommandLine, api libmachine.API) (*ShellConfig, error) {
 | 
				
			||||||
		shellCfg.Prefix = "SET "
 | 
							shellCfg.Prefix = "SET "
 | 
				
			||||||
		shellCfg.Suffix = "\n"
 | 
							shellCfg.Suffix = "\n"
 | 
				
			||||||
		shellCfg.Delimiter = "="
 | 
							shellCfg.Delimiter = "="
 | 
				
			||||||
 | 
						case "emacs":
 | 
				
			||||||
 | 
							shellCfg.Prefix = "(setenv \""
 | 
				
			||||||
 | 
							shellCfg.Suffix = "\")\n"
 | 
				
			||||||
 | 
							shellCfg.Delimiter = "\" \""
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		shellCfg.Prefix = "export "
 | 
							shellCfg.Prefix = "export "
 | 
				
			||||||
		shellCfg.Suffix = "\"\n"
 | 
							shellCfg.Suffix = "\"\n"
 | 
				
			||||||
| 
						 | 
					@ -170,6 +174,10 @@ func shellCfgUnset(c CommandLine, api libmachine.API) (*ShellConfig, error) {
 | 
				
			||||||
		shellCfg.Prefix = "SET "
 | 
							shellCfg.Prefix = "SET "
 | 
				
			||||||
		shellCfg.Suffix = "\n"
 | 
							shellCfg.Suffix = "\n"
 | 
				
			||||||
		shellCfg.Delimiter = "="
 | 
							shellCfg.Delimiter = "="
 | 
				
			||||||
 | 
						case "emacs":
 | 
				
			||||||
 | 
							shellCfg.Prefix = "(setenv \""
 | 
				
			||||||
 | 
							shellCfg.Suffix = ")\n"
 | 
				
			||||||
 | 
							shellCfg.Delimiter = "\" nil"
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		shellCfg.Prefix = "unset "
 | 
							shellCfg.Prefix = "unset "
 | 
				
			||||||
		shellCfg.Suffix = "\n"
 | 
							shellCfg.Suffix = "\n"
 | 
				
			||||||
| 
						 | 
					@ -229,6 +237,9 @@ func (g *EnvUsageHintGenerator) GenerateUsageHint(userShell string, args []strin
 | 
				
			||||||
	case "cmd":
 | 
						case "cmd":
 | 
				
			||||||
		cmd = fmt.Sprintf("\tFOR /f \"tokens=*\" %%i IN ('%s') DO %%i", commandLine)
 | 
							cmd = fmt.Sprintf("\tFOR /f \"tokens=*\" %%i IN ('%s') DO %%i", commandLine)
 | 
				
			||||||
		comment = "REM"
 | 
							comment = "REM"
 | 
				
			||||||
 | 
						case "emacs":
 | 
				
			||||||
 | 
							cmd = fmt.Sprintf("(with-temp-buffer (shell-command \"%s\" (current-buffer)) (eval-buffer))", commandLine)
 | 
				
			||||||
 | 
							comment = ";;"
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		cmd = fmt.Sprintf("eval \"$(%s)\"", commandLine)
 | 
							cmd = fmt.Sprintf("eval \"$(%s)\"", commandLine)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,6 +65,12 @@ func TestHints(t *testing.T) {
 | 
				
			||||||
		{"cmd", "./machine env --shell=cmd --swarm default", "REM Run this command to configure your shell: \nREM \tFOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --swarm default') DO %i\n"},
 | 
							{"cmd", "./machine env --shell=cmd --swarm default", "REM Run this command to configure your shell: \nREM \tFOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --swarm default') DO %i\n"},
 | 
				
			||||||
		{"cmd", "./machine env --shell=cmd --no-proxy --swarm default", "REM Run this command to configure your shell: \nREM \tFOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --no-proxy --swarm default') DO %i\n"},
 | 
							{"cmd", "./machine env --shell=cmd --no-proxy --swarm default", "REM Run this command to configure your shell: \nREM \tFOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --no-proxy --swarm default') DO %i\n"},
 | 
				
			||||||
		{"cmd", "./machine env --shell=cmd --unset", "REM Run this command to configure your shell: \nREM \tFOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --unset') DO %i\n"},
 | 
							{"cmd", "./machine env --shell=cmd --unset", "REM Run this command to configure your shell: \nREM \tFOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --unset') DO %i\n"},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							{"emacs", "./machine env --shell=emacs default", ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs default\" (current-buffer)) (eval-buffer))\n"},
 | 
				
			||||||
 | 
							{"emacs", "./machine env --shell=emacs --no-proxy default", ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --no-proxy default\" (current-buffer)) (eval-buffer))\n"},
 | 
				
			||||||
 | 
							{"emacs", "./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", "./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", "./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"},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, test := range tests {
 | 
						for _, test := range tests {
 | 
				
			||||||
| 
						 | 
					@ -213,6 +219,42 @@ func TestShellCfgSet(t *testing.T) {
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			expectedErr: nil,
 | 
								expectedErr: nil,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								description: "emacs set happy path",
 | 
				
			||||||
 | 
								commandLine: &commandstest.FakeCommandLine{
 | 
				
			||||||
 | 
									CliArgs: []string{"quux"},
 | 
				
			||||||
 | 
									LocalFlags: &commandstest.FakeFlagger{
 | 
				
			||||||
 | 
										Data: map[string]interface{}{
 | 
				
			||||||
 | 
											"shell":    "emacs",
 | 
				
			||||||
 | 
											"swarm":    false,
 | 
				
			||||||
 | 
											"no-proxy": false,
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								api: &libmachinetest.FakeAPI{
 | 
				
			||||||
 | 
									Hosts: []*host.Host{
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											Name: "quux",
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								connChecker: &FakeConnChecker{
 | 
				
			||||||
 | 
									DockerHost:  "tcp://1.2.3.4:2376",
 | 
				
			||||||
 | 
									AuthOptions: nil,
 | 
				
			||||||
 | 
									Err:         nil,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								expectedShellCfg: &ShellConfig{
 | 
				
			||||||
 | 
									Prefix:          "(setenv \"",
 | 
				
			||||||
 | 
									Suffix:          "\")\n",
 | 
				
			||||||
 | 
									Delimiter:       "\" \"",
 | 
				
			||||||
 | 
									DockerCertPath:  filepath.Join(mcndirs.GetMachineDir(), "quux"),
 | 
				
			||||||
 | 
									DockerHost:      "tcp://1.2.3.4:2376",
 | 
				
			||||||
 | 
									DockerTLSVerify: "1",
 | 
				
			||||||
 | 
									UsageHint:       usageHint,
 | 
				
			||||||
 | 
									MachineName:     "quux",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								expectedErr: nil,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			description: "cmd.exe happy path",
 | 
								description: "cmd.exe happy path",
 | 
				
			||||||
			commandLine: &commandstest.FakeCommandLine{
 | 
								commandLine: &commandstest.FakeCommandLine{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +51,15 @@ load ${BASE_TEST_DIR}/helpers.bash
 | 
				
			||||||
  [[ ${lines[4]} == "set -gx NO_PROXY \"$(machine ip $NAME)\";" ]]
 | 
					  [[ ${lines[4]} == "set -gx NO_PROXY \"$(machine ip $NAME)\";" ]]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@test "$DRIVER: test emacs notation" {
 | 
				
			||||||
 | 
					  run machine env --shell emacs --no-proxy $NAME
 | 
				
			||||||
 | 
					  [[ ${lines[0]} == "(setenv \"DOCKER_TLS_VERIFY\" \"1\")" ]]
 | 
				
			||||||
 | 
					  [[ ${lines[1]} == "(setenv \"DOCKER_HOST\" \"$(machine url $NAME)\")" ]]
 | 
				
			||||||
 | 
					  [[ ${lines[2]} == "(setenv \"DOCKER_CERT_PATH\" \"$MACHINE_STORAGE_PATH/machines/$NAME\")" ]]
 | 
				
			||||||
 | 
					  [[ ${lines[3]} == "(setenv \"DOCKER_MACHINE_NAME\" \"$NAME\")" ]]
 | 
				
			||||||
 | 
					  [[ ${lines[4]} == "(setenv \"NO_PROXY\" \"$(machine ip $NAME)\")" ]]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@test "$DRIVER: test no proxy with NO_PROXY already set" {
 | 
					@test "$DRIVER: test no proxy with NO_PROXY already set" {
 | 
				
			||||||
  export NO_PROXY=localhost
 | 
					  export NO_PROXY=localhost
 | 
				
			||||||
  run machine env --no-proxy $NAME
 | 
					  run machine env --no-proxy $NAME
 | 
				
			||||||
| 
						 | 
					@ -103,4 +112,12 @@ load ${BASE_TEST_DIR}/helpers.bash
 | 
				
			||||||
  [[ ${lines[1]} == "SET DOCKER_HOST=" ]]
 | 
					  [[ ${lines[1]} == "SET DOCKER_HOST=" ]]
 | 
				
			||||||
  [[ ${lines[2]} == "SET DOCKER_CERT_PATH=" ]]
 | 
					  [[ ${lines[2]} == "SET DOCKER_CERT_PATH=" ]]
 | 
				
			||||||
  [[ ${lines[3]} == "SET DOCKER_MACHINE_NAME=" ]]
 | 
					  [[ ${lines[3]} == "SET DOCKER_MACHINE_NAME=" ]]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@test "$DRIVER: unset with emacs shell" {
 | 
				
			||||||
 | 
					  run machine env --shell emacs -u
 | 
				
			||||||
 | 
					  [[ ${lines[0]} == "(setenv \"DOCKER_TLS_VERIFY\" nil)" ]]
 | 
				
			||||||
 | 
					  [[ ${lines[1]} == "(setenv \"DOCKER_HOST\" nil)" ]]
 | 
				
			||||||
 | 
					  [[ ${lines[2]} == "(setenv \"DOCKER_CERT_PATH\" nil)" ]]
 | 
				
			||||||
 | 
					  [[ ${lines[3]} == "(setenv \"DOCKER_MACHINE_NAME\" nil)" ]]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue