本文整理汇总了Golang中github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context.BoolT方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.BoolT方法的具体用法?Golang Context.BoolT怎么用?Golang Context.BoolT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.BoolT方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sizeList
func sizeList(ctx *cli.Context) {
if ctx.BoolT("help") == true {
cli.ShowAppHelp(ctx)
os.Exit(1)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
opt := &godo.ListOptions{
Page: 1,
PerPage: 50, // Not likely to have more than 50 sizes soon
}
sizeList, _, err := client.Sizes.List(opt)
if err != nil {
fmt.Printf("Unable to list Sizes: %s\n", err)
os.Exit(1)
}
cliOut := NewCLIOutput()
defer cliOut.Flush()
cliOut.Header("Slug", "Memory", "VCPUs", "Disk", "Transfer", "Price Monthly", "Price Hourly")
for _, size := range sizeList {
cliOut.Writeln("%s\t%dMB\t%d\t%dGB\t%d\t$%.0f\t$%.5f\n",
size.Slug, size.Memory, size.Vcpus, size.Disk, size.Transfer, size.PriceMonthly, size.PriceHourly)
}
}
示例2: regionList
func regionList(ctx *cli.Context) {
if ctx.BoolT("help") == true {
cli.ShowAppHelp(ctx)
os.Exit(1)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
opt := &godo.ListOptions{
Page: 1,
PerPage: 50, // Not likely to have more than 50 regions soon
}
regionList, _, err := client.Regions.List(opt)
if err != nil {
fmt.Printf("Unable to list Regions: %s\n", err)
os.Exit(1)
}
cliOut := NewCLIOutput()
defer cliOut.Flush()
cliOut.Header("Name", "Slug", "Available")
for _, region := range regionList {
cliOut.Writeln("%s\t%s\t%t\n", region.Name, region.Slug, region.Available)
}
}
示例3: actionList
func actionList(ctx *cli.Context) {
if ctx.BoolT("help") == true {
cli.ShowAppHelp(ctx)
os.Exit(1)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
opt := &godo.ListOptions{
Page: ctx.Int("page"),
PerPage: ctx.Int("page-size"),
}
actionList, _, err := client.Actions.List(opt)
if err != nil {
fmt.Printf("Unable to list Actions: %s\n", err)
os.Exit(1)
}
cliOut := NewCLIOutput()
defer cliOut.Flush()
cliOut.Header("ID", "Region", "ResourceType", "ResourceID", "Type", "StartedAt", "CompletedAt", "Status")
for _, action := range actionList {
cliOut.Writeln("%d\t%s\t%s\t%d\t%s\t%s\t%s\t%s\n",
action.ID, action.RegionSlug, action.ResourceType, action.ResourceID, action.Type, action.StartedAt, action.CompletedAt, action.Status)
}
}
示例4: domainList
func domainList(ctx *cli.Context) {
if ctx.BoolT("help") == true {
cli.ShowAppHelp(ctx)
os.Exit(1)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
opt := &godo.ListOptions{
Page: ctx.Int("page"),
PerPage: ctx.Int("page-size"),
}
domainList, _, err := client.Domains.List(opt)
if err != nil {
log.Fatalf("Unable to list Domains: %s.", err)
}
cliOut := NewCLIOutput()
defer cliOut.Flush()
cliOut.Header("Name", "TTL")
for _, domain := range domainList {
cliOut.Writeln("%s\t%d\n", domain.Name, domain.TTL)
}
}
示例5: dropletList
func dropletList(ctx *cli.Context) {
if ctx.BoolT("help") == true {
cli.ShowAppHelp(ctx)
os.Exit(1)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
opt := &godo.ListOptions{}
dropletList := []godo.Droplet{}
for { // TODO make all optional
dropletPage, resp, err := client.Droplets.List(opt)
if err != nil {
fmt.Printf("Unable to list Droplets: %s\n", err)
os.Exit(1)
}
// append the current page's droplets to our list
for _, d := range dropletPage {
dropletList = append(dropletList, d)
}
// if we are at the last page, break out the for loop
if resp.Links == nil || resp.Links.IsLastPage() {
break
}
page, err := resp.Links.CurrentPage()
if err != nil {
fmt.Printf("Unable to get pagination: %s\n", err)
os.Exit(1)
}
// set the page we want for the next request
opt.Page = page + 1
}
cliOut := NewCLIOutput()
defer cliOut.Flush()
cliOut.Header("ID", "Name", "IP Address", "Status", "Memory", "Disk", "Region")
for _, droplet := range dropletList {
publicIP := PublicIPForDroplet(&droplet)
cliOut.Writeln("%d\t%s\t%s\t%s\t%dMB\t%dGB\t%s\n",
droplet.ID, droplet.Name, publicIP, droplet.Status, droplet.Memory, droplet.Disk, droplet.Region.Slug)
}
}
示例6: sshList
func sshList(ctx *cli.Context) {
if ctx.BoolT("help") == true {
cli.ShowAppHelp(ctx)
os.Exit(1)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
opt := &godo.ListOptions{}
keyList := []godo.Key{}
for {
keyPage, resp, err := client.Keys.List(opt)
if err != nil {
fmt.Printf("Unable to list SSH Keys: %s\n", err)
os.Exit(1)
}
// append the current page's droplets to our list
for _, d := range keyPage {
keyList = append(keyList, d)
}
// if we are at the last page, break out the for loop
if resp.Links == nil || resp.Links.IsLastPage() {
break
}
page, err := resp.Links.CurrentPage()
if err != nil {
fmt.Printf("Unable to get pagination: %s\n", err)
os.Exit(1)
}
// set the page we want for the next request
opt.Page = page + 1
}
cliOut := NewCLIOutput()
defer cliOut.Flush()
cliOut.Header("ID", "Name", "Fingerprint")
for _, key := range keyList {
cliOut.Writeln("%d\t%s\t%s\n", key.ID, key.Name, key.Fingerprint)
}
}