forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings-get.go
50 lines (41 loc) · 942 Bytes
/
settings-get.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
package cmd
import (
"fmt"
"os"
"regexp"
"text/tabwriter"
"github.com/evcc-io/evcc/server/db/settings"
"github.com/spf13/cobra"
)
// settingsGetCmd represents the configure command
var settingsGetCmd = &cobra.Command{
Use: "get",
Short: "Get configuration settings",
Run: runSettingsGet,
Args: cobra.MaximumNArgs(1),
}
func init() {
settingsCmd.AddCommand(settingsGetCmd)
}
func runSettingsGet(cmd *cobra.Command, args []string) {
// load config
if err := loadConfigFile(&conf); err != nil {
log.FATAL.Fatal(err)
}
// setup environment
if err := configureEnvironment(cmd, conf); err != nil {
log.FATAL.Fatal(err)
}
var re *regexp.Regexp
if len(args) > 0 {
re = regexp.MustCompile(args[0])
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
for _, s := range settings.All() {
if re != nil && !re.MatchString(s.Key) {
continue
}
fmt.Fprintf(w, "%s:\t%s\n", s.Key, s.Value)
}
w.Flush()
}