File: cmd_log.go

package info (click to toggle)
direnv 2.37.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 872 kB
  • sloc: sh: 1,499; csh: 83; makefile: 7
file content (31 lines) | stat: -rw-r--r-- 627 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
package cmd

import (
	"errors"
	"fmt"
)

// CmdLog is `direnv log [--status | --error] <message>`
var CmdLog = &Cmd{
	Name:   "log",
	Desc:   "Logs a given message",
	Args:   []string{"[--status | --error]", "<message>"},
	Action: actionWithConfig(cmdLog),
}

func cmdLog(_ Env, args []string, c *Config) (err error) {
	if len(args) != 3 {
		return errors.New("invalid arguments")
	}
	logType := args[1]
	message := args[2]
	switch logType {
	case "--status", "-status":
		logStatus(c, message)
	case "--error", "-error":
		logError(c, message)
	default:
		return fmt.Errorf("invalid log-type '%s'", logType)
	}
	return nil
}