/
status.go
86 lines (73 loc) · 2.32 KB
/
status.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package cmd
import (
"fmt"
"os"
"strings"
"text/tabwriter"
"github.com/manifoldco/torus-cli/errs"
"github.com/manifoldco/torus-cli/prefs"
"github.com/manifoldco/torus-cli/ui"
"github.com/urfave/cli"
)
func init() {
status := cli.Command{
Name: "status",
Usage: "Show the current Torus status associated with your account and project",
Category: "PROJECT STRUCTURE",
Flags: []cli.Flag{
stdEnvFlag,
serviceFlag("Use this service.", "default", true),
// These flags are hidden so we can still parse out the values
// from the prefs files and env vars, but we don't display
// them to the users in help.
// A user could still set the flag on the command line though :(
placeHolderStringFlag{
StringFlag: cli.StringFlag{Name: "org", EnvVar: "TORUS_ORG", Hidden: true},
Required: true,
},
placeHolderStringFlag{
StringFlag: cli.StringFlag{Name: "project", EnvVar: "TORUS_PROJECT", Hidden: true},
Required: true,
},
placeHolderStringFlag{
StringFlag: cli.StringFlag{Name: "instance", EnvVar: "TORUS_INSTANCE", Value: "1", Hidden: true},
Required: true,
},
},
Action: chain(
ensureDaemon, ensureSession, loadDirPrefs, loadPrefDefaults,
setUserEnv, statusCmd,
),
}
Cmds = append(Cmds, status)
}
func statusCmd(ctx *cli.Context) error {
preferences, err := prefs.NewPreferences()
if err != nil {
return err
}
if !preferences.Core.Context {
msg := fmt.Sprintf("Context is disabled. Use '%s prefs' to enable it.", ctx.App.Name)
return errs.NewExitError(msg)
}
err = checkRequiredFlags(ctx)
if err != nil {
fmt.Printf("You are not inside a linked working directory. "+
"Use '%s link' to link your project.\n", ctx.App.Name)
return nil
}
org := ctx.String("org")
project := ctx.String("project")
env := ctx.String("environment")
service := ctx.String("service")
w := tabwriter.NewWriter(os.Stdout, 2, 0, 1, ' ', 0)
fmt.Fprintf(w, "%s:\t%s\n", ui.BoldString("Org"), org)
fmt.Fprintf(w, "%s:\t%s\n", ui.BoldString("Project"), project)
fmt.Fprintf(w, "%s:\t%s\n", ui.BoldString("Environment"), env)
fmt.Fprintf(w, "%s:\t%s\n", ui.BoldString("Service"), service)
w.Flush()
parts := []string{"", org, project, env, service}
credPath := strings.Join(parts, "/")
fmt.Printf("\n%s: %s\n", ui.BoldString("Credential Path"), credPath)
return nil
}