github.com/koron/hk@v0.0.0-20150303213137-b8aeaa3ab34c/orgs.go (about)

     1  package main
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  	"text/tabwriter"
     7  
     8  	"github.com/heroku/hk/Godeps/_workspace/src/github.com/bgentry/heroku-go"
     9  )
    10  
    11  var cmdOrgs = &Command{
    12  	Run:      runOrgs,
    13  	Usage:    "orgs",
    14  	Category: "orgs",
    15  	Short:    "list Heroku orgs",
    16  	Long:     "Lists Heroku organizations that the user belongs to.",
    17  }
    18  
    19  func runOrgs(cmd *Command, args []string) {
    20  	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
    21  	defer w.Flush()
    22  
    23  	orgs, err := client.OrganizationList(&heroku.ListRange{Field: "name"})
    24  	must(err)
    25  	printOrgsList(w, orgs)
    26  }
    27  
    28  func printOrgsList(w io.Writer, orgs []heroku.Organization) {
    29  	for _, org := range orgs {
    30  		listRec(w,
    31  			org.Name,
    32  			org.Role,
    33  		)
    34  	}
    35  }
    36  
    37  // Returns true if the app is in an org, and false otherwise.
    38  func isAppInOrg(app *heroku.OrganizationApp) bool {
    39  	return app.Organization != nil
    40  }
    41  
    42  // This function uses must(err), so the program will exit if an error is
    43  // encountered.
    44  func mustGetOrgApp(appname string) *heroku.OrganizationApp {
    45  	app, err := client.OrganizationAppInfo(appname)
    46  	must(err)
    47  	return app
    48  }