generated from jojomi/go-project-template-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv_health.go
53 lines (44 loc) · 1012 Bytes
/
env_health.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
)
// EnvHealth encapsulates the environment for the CLI health handler.
type EnvHealth struct {
JobDir string
JobFile string
Command string
Args []string
RequiredOnly bool
PossibleOnly bool
Verbose bool
}
// ParseFrom reads the state from a given cobra command and its args.
func (e *EnvHealth) ParseFrom(command *cobra.Command, args []string) error {
var err error
jobDir, err := command.Flags().GetString("job-dir")
if err != nil {
return err
}
e.JobDir, err = homedir.Expand(jobDir)
if err != nil {
return err
}
e.JobFile, err = command.Flags().GetString("job-file")
if err != nil {
return err
}
e.RequiredOnly, err = command.Flags().GetBool("required-only")
if err != nil {
return err
}
e.PossibleOnly, err = command.Flags().GetBool("possible-only")
if err != nil {
return err
}
e.Verbose, err = command.Flags().GetBool("verbose")
if err != nil {
return err
}
return nil
}