MCPcopy
hub / github.com/direnv/direnv / cmdHookAction

Function cmdHookAction

internal/cmd/cmd_hook.go:24–61  ·  view source on GitHub ↗
(_ Env, args []string)

Source from the content-addressed store, hash-verified

22}
23
24func cmdHookAction(_ Env, args []string) (err error) {
25 var target string
26
27 if len(args) > 1 {
28 target = args[1]
29 }
30
31 selfPath, err := os.Executable()
32 if err != nil {
33 return err
34 }
35
36 // Convert Windows path if needed
37 selfPath = strings.ReplaceAll(selfPath, "\\", "/")
38 ctx := HookContext{selfPath}
39
40 shell := DetectShell(target)
41 if shell == nil {
42 return fmt.Errorf("unknown target shell '%s'", target)
43 }
44
45 hookStr, err := shell.Hook()
46 if err != nil {
47 return err
48 }
49
50 hookTemplate, err := template.New("hook").Parse(hookStr)
51 if err != nil {
52 return err
53 }
54
55 err = hookTemplate.Execute(os.Stdout, ctx)
56 if err != nil {
57 return err
58 }
59
60 return
61}

Callers

nothing calls this directly

Calls 2

DetectShellFunction · 0.85
HookMethod · 0.65

Tested by

no test coverage detected