cmd/gitbayd/configshow.go
39 lines · 1174 bytes
1package main
2
3import (
4 "fmt"
5 "os"
6
7 "github.com/BurntSushi/toml"
8 "github.com/spf13/cobra"
9
10 "gitbay.org/gitbay/internal/config"
11)
12
13// configShowCmd prints the configuration the daemon runs with: the file
14// with every default filled in, as TOML, so a support question starts
15// from what is in effect rather than what was written. The SMTP password
16// is the one secret the file can hold and is never printed.
17func configShowCmd() *cobra.Command {
18 return &cobra.Command{
19 Use: "show",
20 Short: "print the effective configuration, defaults filled in, secrets redacted",
21 RunE: func(cmd *cobra.Command, args []string) error {
22 cfg, err := config.Load(configPath)
23 if err != nil && cfg.Server.Root == "" {
24 // Nothing decoded: the file is missing or malformed.
25 return err
26 }
27 if cfg.Mail.SMTPPass != "" {
28 cfg.Mail.SMTPPass = "<redacted>"
29 }
30 fmt.Printf("# effective configuration from %s\n", configPath)
31 if encErr := toml.NewEncoder(os.Stdout).Encode(cfg); encErr != nil {
32 return encErr
33 }
34 // A validation failure still prints the config above; the
35 // contradiction it names is what the reader came to see.
36 return err
37 },
38 }
39}