-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.go
68 lines (53 loc) · 1.46 KB
/
common.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package command
import (
"flag"
"fmt"
cli "github.com/seashell/cli/pkg/cli"
)
// manyStrings
type manyStrings []string
func (s *manyStrings) Set(val string) error {
*s = append(*s, val)
return nil
}
func (s *manyStrings) String() string {
var out []string
out = *s
return fmt.Sprintf("%v", out)
}
// RootFlagSet :
type RootFlagSet struct {
*flag.FlagSet
envPaths manyStrings
configPaths manyStrings
}
// FlagSet declares flags that are common to all commands,
// returning a RootFlagSet struct that will hold their values after
// flag.Parse() is called by the command
func FlagSet(name string) *RootFlagSet {
flags := &RootFlagSet{
FlagSet: flag.NewFlagSet(name, flag.ContinueOnError),
}
flags.Usage = func() {}
flags.Var(&flags.envPaths, "env", "")
flags.Var(&flags.configPaths, "config", "")
// TODO: direct output to UI
flags.SetOutput(nil)
return flags
}
// GlobalOptions returns the global usage options string.
func GlobalOptions() string {
text := `
--config=<path>
Path to a HCL file containing valid Seashell CLI configurations.
Overrides the SEASHELL_CONFIG_PATH environment variable if set.
--env=<path>
Path to an env file
Overrides the SEASHEL_ENV_FILE_PATH environment variable if set.
`
return text
}
// DefaultErrorMessage returns the default error message for this command
func DefaultErrorMessage(cmd cli.NamedCommand) string {
return fmt.Sprintf("For additional help try 'seashell %s --help'", cmd.Name())
}