-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_params.go
36 lines (32 loc) · 882 Bytes
/
action_params.go
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
36
package actions
import (
"github.com/sandreas/log"
"github.com/urfave/cli"
"os"
)
type ActionParams struct {
Quiet bool `arg:"help:do not show any output"`
Force bool `arg:"help:force the requested action - even if it might be not a good idea"`
Debug bool `arg:"-d,help:debug mode with logging to Stdout and into $HOME/.graft/application.log"`
}
func parseActionParams(c *cli.Context) *ActionParams {
return &ActionParams{
Quiet: c.Bool("quiet"),
Force: c.Bool("force"),
Debug: c.Bool("debug"),
}
}
func initLogging(settings *ActionParams) {
if settings.Quiet {
log.RemoveAllTargets()
} else {
startLogLevel := log.LevelInfo
if settings.Debug {
startLogLevel = log.LevelDebug
}
log.WithTargets(
log.NewColorTerminalTarget(os.Stdout, startLogLevel, log.LevelInfo),
log.NewColorTerminalTarget(os.Stderr, log.LevelWarn, log.LevelFatal),
)
}
}