-
Notifications
You must be signed in to change notification settings - Fork 224
/
show.go
53 lines (46 loc) · 1.2 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 (
"context"
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/flaps"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/iostreams"
)
func newShow() (cmd *cobra.Command) {
const (
short = "Show an app's configuration"
long = `Show an application's configuration. The configuration is presented
in JSON format. The configuration data is retrieved from the Fly service.`
)
cmd = command.New("show", short, long, runShow,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.NoArgs
cmd.Aliases = []string{"display"}
flag.Add(cmd, flag.App(), flag.AppConfig())
return
}
func runShow(ctx context.Context) error {
io := iostreams.FromContext(ctx)
appName := appconfig.NameFromContext(ctx)
flapsClient, err := flaps.NewFromAppName(ctx, appName)
if err != nil {
return err
}
ctx = flaps.NewContext(ctx, flapsClient)
cfg, err := appconfig.FromRemoteApp(ctx, appName)
if err != nil {
return err
}
b, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err
}
fmt.Fprintln(io.Out, string(b))
return nil
}