-
Notifications
You must be signed in to change notification settings - Fork 28
/
show.go
53 lines (45 loc) · 1.28 KB
/
show.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 config
import (
"fmt"
"github.com/nhost/be/services/mimir/model"
"github.com/nhost/cli/clienv"
"github.com/nhost/cli/project/env"
"github.com/pelletier/go-toml/v2"
"github.com/urfave/cli/v2"
)
func CommandShow() *cli.Command {
return &cli.Command{ //nolint:exhaustruct
Name: "show",
Aliases: []string{},
Usage: "Shows configuration after resolving secrets",
Description: "Note that this command will always use the local secrets, even if you specify subdomain",
Action: commandShow,
Flags: []cli.Flag{
&cli.StringFlag{ //nolint:exhaustruct
Name: flagSubdomain,
Usage: "Show this subdomain's rendered configuration. Defaults to base configuration",
EnvVars: []string{"NHOST_SUBDOMAIN"},
},
},
}
}
func commandShow(c *cli.Context) error {
ce := clienv.FromCLI(c)
var secrets model.Secrets
if err := clienv.UnmarshalFile(ce.Path.Secrets(), &secrets, env.Unmarshal); err != nil {
return fmt.Errorf(
"failed to parse secrets, make sure secret values are between quotes: %w",
err,
)
}
cfg, err := Validate(ce, c.String(flagSubdomain), secrets)
if err != nil {
return err
}
b, err := toml.Marshal(cfg)
if err != nil {
return fmt.Errorf("error marshalling config: %w", err)
}
ce.Println(string(b))
return nil
}