-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathvalidate.go
45 lines (40 loc) · 1.15 KB
/
validate.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
package config
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/iostreams"
)
func newValidate() (cmd *cobra.Command) {
const (
short = "Validate an app's config file"
long = `Validates an application's config file against the Fly platform to
ensure it is correct and meaningful to the platform.`
)
cmd = command.New("validate", short, long, runValidate,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.NoArgs
flag.Add(cmd, flag.App(), flag.AppConfig(),
flag.Bool{Name: "machines", Description: "Forces apps v2 config validation"},
flag.Bool{Name: "nomad", Description: "Forces apps v1 config validation"},
)
return
}
func runValidate(ctx context.Context) error {
io := iostreams.FromContext(ctx)
cfg := appconfig.ConfigFromContext(ctx)
switch {
case flag.GetBool(ctx, "machines"):
cfg.SetMachinesPlatform()
case flag.GetBool(ctx, "nomad"):
cfg.SetNomadPlatform()
}
err, extra_info := cfg.Validate(ctx)
fmt.Fprintln(io.Out, extra_info)
return err
}