github.com/koron/hk@v0.0.0-20150303213137-b8aeaa3ab34c/features.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io" 6 "log" 7 "os" 8 "text/tabwriter" 9 10 "github.com/heroku/hk/Godeps/_workspace/src/github.com/bgentry/heroku-go" 11 ) 12 13 var cmdFeatures = &Command{ 14 Run: runFeatures, 15 Usage: "features", 16 NeedsApp: true, 17 Category: "app", 18 Short: "list app features" + extra, 19 Long: ` 20 Features lists Heroku Labs features for an app. 21 22 Example: 23 24 $ hk features 25 + preboot 26 user-env-compile 27 + websockets 28 `, 29 } 30 31 func runFeatures(cmd *Command, args []string) { 32 if len(args) != 0 { 33 cmd.PrintUsage() 34 os.Exit(2) 35 } 36 w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0) 37 defer w.Flush() 38 39 features, err := client.AppFeatureList(mustApp(), &heroku.ListRange{Field: "name"}) 40 must(err) 41 42 listFeatures(w, features) 43 } 44 45 func listFeatures(w io.Writer, features []heroku.AppFeature) { 46 for _, f := range features { 47 enabled := " " 48 if f.Enabled { 49 enabled = "+" 50 } 51 listRec(w, 52 enabled, 53 f.Name, 54 ) 55 } 56 } 57 58 var cmdFeatureInfo = &Command{ 59 Run: runFeatureInfo, 60 Usage: "feature-info <feature>", 61 NeedsApp: true, 62 Category: "app", 63 Short: "show info for an app feature" + extra, 64 Long: ` 65 Shows detailed info for a Heroku Labs feature on an app. 66 67 Example: 68 69 $ hk feature-info preboot 70 ... 71 `, 72 } 73 74 func runFeatureInfo(cmd *Command, args []string) { 75 if len(args) != 1 { 76 cmd.PrintUsage() 77 os.Exit(2) 78 } 79 appname := mustApp() 80 featureName := args[0] 81 feature, err := client.AppFeatureInfo(appname, featureName) 82 must(err) 83 fmt.Printf("Name: %s\n", feature.Name) 84 fmt.Printf("Docs: %s\n", feature.DocURL) 85 fmt.Printf("Enabled: %t\n", feature.Enabled) 86 fmt.Printf("Description: %s\n", feature.Description) 87 } 88 89 var cmdFeatureEnable = &Command{ 90 Run: runFeatureEnable, 91 Usage: "feature-enable <feature>", 92 NeedsApp: true, 93 Category: "app", 94 Short: "enable an app feature" + extra, 95 Long: ` 96 Enables a Heroku Labs feature on an app. 97 98 Example: 99 100 $ hk feature-enable preboot 101 Enabled preboot on myapp. 102 `, 103 } 104 105 func runFeatureEnable(cmd *Command, args []string) { 106 if len(args) != 1 { 107 cmd.PrintUsage() 108 os.Exit(2) 109 } 110 appname := mustApp() 111 featureName := args[0] 112 feature, err := client.AppFeatureUpdate(appname, featureName, true) 113 must(err) 114 log.Printf("Enabled %s on %s.", feature.Name, appname) 115 } 116 117 var cmdFeatureDisable = &Command{ 118 Run: runFeatureDisable, 119 Usage: "feature-disable <feature>", 120 NeedsApp: true, 121 Category: "app", 122 Short: "disable an app feature" + extra, 123 Long: ` 124 Disables a Heroku Labs feature on an app. 125 126 Example: 127 128 $ hk feature-disable websockets 129 Disabled websockets on myapp. 130 `, 131 } 132 133 func runFeatureDisable(cmd *Command, args []string) { 134 if len(args) != 1 { 135 cmd.PrintUsage() 136 os.Exit(2) 137 } 138 appname := mustApp() 139 featureName := args[0] 140 feature, err := client.AppFeatureUpdate(appname, featureName, false) 141 must(err) 142 log.Printf("Disabled %s on %s.", feature.Name, appname) 143 }