MCPcopy
hub / github.com/direnv/direnv / cmdWatchAction

Function cmdWatchAction

internal/cmd/cmd_watch.go:17–61  ·  view source on GitHub ↗
(env Env, args []string)

Source from the content-addressed store, hash-verified

15}
16
17func cmdWatchAction(env Env, args []string) (err error) {
18 var shellName string
19
20 if len(args) < 2 {
21 return fmt.Errorf("a path is required to add to the list of watches")
22 }
23 if len(args) >= 2 {
24 shellName = args[1]
25 } else {
26 shellName = "bash"
27 }
28
29 shell := DetectShell(shellName)
30
31 if shell == nil {
32 return fmt.Errorf("unknown target shell '%s'", shellName)
33 }
34
35 watches := NewFileTimes()
36 watchString, ok := env[DIRENV_WATCHES]
37 if ok {
38 err = watches.Unmarshal(watchString)
39 if err != nil {
40 return
41 }
42 }
43
44 for _, arg := range args[2:] {
45 err = watches.Update(arg)
46 if err != nil {
47 return
48 }
49 }
50
51 e := make(ShellExport)
52 e.Add(DIRENV_WATCHES, watches.Marshal())
53
54 exportStr, err := shell.Export(e)
55 if err != nil {
56 return err
57 }
58 _, _ = os.Stdout.WriteString(exportStr)
59
60 return
61}

Callers

nothing calls this directly

Calls 7

UnmarshalMethod · 0.95
UpdateMethod · 0.95
MarshalMethod · 0.95
DetectShellFunction · 0.85
NewFileTimesFunction · 0.85
AddMethod · 0.80
ExportMethod · 0.65

Tested by

no test coverage detected