This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathfeatures.go
143 lines (122 loc) · 2.83 KB
/
features.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"fmt"
"io"
"log"
"os"
"text/tabwriter"
"github.com/heroku/hk/Godeps/_workspace/src/github.com/bgentry/heroku-go"
)
var cmdFeatures = &Command{
Run: runFeatures,
Usage: "features",
NeedsApp: true,
Category: "app",
Short: "list app features" + extra,
Long: `
Features lists Heroku Labs features for an app.
Example:
$ hk features
+ preboot
user-env-compile
+ websockets
`,
}
func runFeatures(cmd *Command, args []string) {
if len(args) != 0 {
cmd.PrintUsage()
os.Exit(2)
}
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
features, err := client.AppFeatureList(mustApp(), &heroku.ListRange{Field: "name"})
must(err)
listFeatures(w, features)
}
func listFeatures(w io.Writer, features []heroku.AppFeature) {
for _, f := range features {
enabled := " "
if f.Enabled {
enabled = "+"
}
listRec(w,
enabled,
f.Name,
)
}
}
var cmdFeatureInfo = &Command{
Run: runFeatureInfo,
Usage: "feature-info <feature>",
NeedsApp: true,
Category: "app",
Short: "show info for an app feature" + extra,
Long: `
Shows detailed info for a Heroku Labs feature on an app.
Example:
$ hk feature-info preboot
...
`,
}
func runFeatureInfo(cmd *Command, args []string) {
if len(args) != 1 {
cmd.PrintUsage()
os.Exit(2)
}
appname := mustApp()
featureName := args[0]
feature, err := client.AppFeatureInfo(appname, featureName)
must(err)
fmt.Printf("Name: %s\n", feature.Name)
fmt.Printf("Docs: %s\n", feature.DocURL)
fmt.Printf("Enabled: %t\n", feature.Enabled)
fmt.Printf("Description: %s\n", feature.Description)
}
var cmdFeatureEnable = &Command{
Run: runFeatureEnable,
Usage: "feature-enable <feature>",
NeedsApp: true,
Category: "app",
Short: "enable an app feature" + extra,
Long: `
Enables a Heroku Labs feature on an app.
Example:
$ hk feature-enable preboot
Enabled preboot on myapp.
`,
}
func runFeatureEnable(cmd *Command, args []string) {
if len(args) != 1 {
cmd.PrintUsage()
os.Exit(2)
}
appname := mustApp()
featureName := args[0]
feature, err := client.AppFeatureUpdate(appname, featureName, true)
must(err)
log.Printf("Enabled %s on %s.", feature.Name, appname)
}
var cmdFeatureDisable = &Command{
Run: runFeatureDisable,
Usage: "feature-disable <feature>",
NeedsApp: true,
Category: "app",
Short: "disable an app feature" + extra,
Long: `
Disables a Heroku Labs feature on an app.
Example:
$ hk feature-disable websockets
Disabled websockets on myapp.
`,
}
func runFeatureDisable(cmd *Command, args []string) {
if len(args) != 1 {
cmd.PrintUsage()
os.Exit(2)
}
appname := mustApp()
featureName := args[0]
feature, err := client.AppFeatureUpdate(appname, featureName, false)
must(err)
log.Printf("Disabled %s on %s.", feature.Name, appname)
}