(env Env, args []string)
| 15 | } |
| 16 | |
| 17 | func 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 | } |
nothing calls this directly
no test coverage detected