MCPcopy Index your code
hub / github.com/docker/docker-agent / newCommandFactory

Function newCommandFactory

pkg/hooks/handler.go:137–151  ·  view source on GitHub ↗

newCommandFactory resolves the OS shell once at factory-build time so per-hook invocations don't pay the shell-detection cost.

()

Source from the content-addressed store, hash-verified

135// newCommandFactory resolves the OS shell once at factory-build time so
136// per-hook invocations don't pay the shell-detection cost.
137func newCommandFactory() HandlerFactory {
138 shell, shellArgs := shellpath.DetectShell()
139 return func(env HandlerEnv, hook Hook) (Handler, error) {
140 if hook.Command == "" {
141 return nil, errors.New("command hook requires a non-empty command")
142 }
143 return &commandHandler{
144 workingDir: hookWorkingDir(env.WorkingDir, hook.WorkingDir),
145 env: hookEnv(env.Env, hook.Env),
146 shell: shell,
147 shellArgs: shellArgs,
148 command: hook.Command,
149 }, nil
150 }
151}
152
153// hookWorkingDir resolves the directory a command hook runs in. An
154// absolute override wins; a relative override is joined onto the

Callers 1

NewRegistryFunction · 0.85

Calls 4

DetectShellFunction · 0.92
hookWorkingDirFunction · 0.85
hookEnvFunction · 0.85
NewMethod · 0.45

Tested by

no test coverage detected