github.com/koron/hk@v0.0.0-20150303213137-b8aeaa3ab34c/account_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 cmdAccountFeatures = &Command{ 14 Run: runAccountFeatures, 15 Usage: "account-features", 16 Category: "account", 17 Short: "list account features" + extra, 18 Long: ` 19 Account-features lists Heroku Labs features for your account. 20 21 Example: 22 23 $ hk account-features 24 + pipelines 25 `, 26 } 27 28 func runAccountFeatures(cmd *Command, args []string) { 29 if len(args) != 0 { 30 cmd.PrintUsage() 31 os.Exit(2) 32 } 33 w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0) 34 defer w.Flush() 35 36 features, err := client.AccountFeatureList(&heroku.ListRange{Field: "name"}) 37 must(err) 38 39 listAccountFeatures(w, features) 40 } 41 42 func listAccountFeatures(w io.Writer, features []heroku.AccountFeature) { 43 for _, f := range features { 44 enabled := " " 45 if f.Enabled { 46 enabled = "+" 47 } 48 listRec(w, 49 enabled, 50 f.Name, 51 ) 52 } 53 } 54 55 var cmdAccountFeatureInfo = &Command{ 56 Run: runAccountFeatureInfo, 57 Usage: "account-feature-info <feature>", 58 Category: "account", 59 Short: "show info for an account feature" + extra, 60 Long: ` 61 Shows detailed info for a Heroku Labs feature on an account. 62 63 Example: 64 65 $ hk feature-info preboot 66 ... 67 `, 68 } 69 70 func runAccountFeatureInfo(cmd *Command, args []string) { 71 if len(args) != 1 { 72 cmd.PrintUsage() 73 os.Exit(2) 74 } 75 feature, err := client.AccountFeatureInfo(args[0]) 76 must(err) 77 fmt.Printf("Name: %s\n", feature.Name) 78 fmt.Printf("Docs: %s\n", feature.DocURL) 79 fmt.Printf("Enabled: %t\n", feature.Enabled) 80 fmt.Printf("Description: %s\n", feature.Description) 81 } 82 83 var cmdAccountFeatureEnable = &Command{ 84 Run: runAccountFeatureEnable, 85 Usage: "account-feature-enable <feature>", 86 Category: "account", 87 Short: "enable an account feature" + extra, 88 Long: ` 89 Enables a Heroku Labs feature on your account. 90 91 Example: 92 93 $ hk account-feature-enable pipelines 94 Enabled pipelines. 95 `, 96 } 97 98 func runAccountFeatureEnable(cmd *Command, args []string) { 99 if len(args) != 1 { 100 cmd.PrintUsage() 101 os.Exit(2) 102 } 103 featureName := args[0] 104 feature, err := client.AccountFeatureUpdate(featureName, true) 105 must(err) 106 log.Printf("Enabled %s.", feature.Name) 107 } 108 109 var cmdAccountFeatureDisable = &Command{ 110 Run: runAccountFeatureDisable, 111 Usage: "account-feature-disable <feature>", 112 Category: "account", 113 Short: "disable an account feature" + extra, 114 Long: ` 115 Disables a Heroku Labs feature on your account. 116 117 Example: 118 119 $ hk account-feature-disable pipelines 120 Disabled pipelines. 121 `, 122 } 123 124 func runAccountFeatureDisable(cmd *Command, args []string) { 125 if len(args) != 1 { 126 cmd.PrintUsage() 127 os.Exit(2) 128 } 129 featureName := args[0] 130 feature, err := client.AccountFeatureUpdate(featureName, false) 131 must(err) 132 log.Printf("Disabled %s.", feature.Name) 133 }