Skip to content

Commit 7e7c557

Browse files
authored
Merge pull request #342 from thaJeztah/less_indirection
client: remove some indirection and touch-up GoDoc
2 parents fa991bc + ad253f5 commit 7e7c557

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

client/command.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,30 @@ type Program interface {
1515
// ProgramFunc is a type of function that initializes programs based on arguments.
1616
type ProgramFunc func(args ...string) Program
1717

18-
// NewShellProgramFunc creates programs that are executed in a Shell.
19-
func NewShellProgramFunc(name string) ProgramFunc {
20-
return NewShellProgramFuncWithEnv(name, nil)
18+
// NewShellProgramFunc creates a [ProgramFunc] to run command in a [Shell].
19+
func NewShellProgramFunc(command string) ProgramFunc {
20+
return func(args ...string) Program {
21+
return createProgramCmdRedirectErr(command, args, nil)
22+
}
2123
}
2224

23-
// NewShellProgramFuncWithEnv creates programs that are executed in a Shell with environment variables
24-
func NewShellProgramFuncWithEnv(name string, env *map[string]string) ProgramFunc {
25+
// NewShellProgramFuncWithEnv creates a [ProgramFunc] tu run command
26+
// in a [Shell] with the given environment variables.
27+
func NewShellProgramFuncWithEnv(command string, env *map[string]string) ProgramFunc {
2528
return func(args ...string) Program {
26-
return &Shell{cmd: createProgramCmdRedirectErr(name, args, env)}
29+
return createProgramCmdRedirectErr(command, args, env)
2730
}
2831
}
2932

30-
func createProgramCmdRedirectErr(commandName string, args []string, env *map[string]string) *exec.Cmd {
31-
programCmd := exec.Command(commandName, args...)
33+
func createProgramCmdRedirectErr(command string, args []string, env *map[string]string) *Shell {
34+
ec := exec.Command(command, args...)
3235
if env != nil {
3336
for k, v := range *env {
34-
programCmd.Env = append(programCmd.Environ(), k+"="+v)
37+
ec.Env = append(ec.Environ(), k+"="+v)
3538
}
3639
}
37-
programCmd.Stderr = os.Stderr
38-
return programCmd
40+
ec.Stderr = os.Stderr
41+
return &Shell{cmd: ec}
3942
}
4043

4144
// Shell invokes shell commands to talk with a remote credentials-helper.

0 commit comments

Comments
 (0)