File: cmd_current.go

package info (click to toggle)
direnv 2.25.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,512 kB
  • sloc: asm: 1,643; sh: 1,595; csh: 76; makefile: 27; ansic: 24
file content (35 lines) | stat: -rw-r--r-- 624 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main

import (
	"errors"
)

// CmdCurrent is `direnv current`
var CmdCurrent = &Cmd{
	Name:    "current",
	Desc:    "Reports whether direnv's view of a file is current (or stale)",
	Args:    []string{"PATH"},
	Private: true,
	Action:  actionSimple(cmdCurrentAction),
}

func cmdCurrentAction(env Env, args []string) (err error) {
	if len(args) < 2 {
		err = errors.New("missing PATH argument")
		return
	}

	path := args[1]
	watches := NewFileTimes()
	watchString, ok := env[DIRENV_WATCHES]
	if ok {
		err = watches.Unmarshal(watchString)
		if err != nil {
			return
		}
	}

	err = watches.CheckOne(path)

	return
}