本文整理汇总了Golang中github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context.Bool方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Bool方法的具体用法?Golang Context.Bool怎么用?Golang Context.Bool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.Bool方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: dropletActionResize
func dropletActionResize(ctx *cli.Context) {
if ctx.Int("id") == 0 && len(ctx.Args()) != 1 {
fmt.Printf("Error: Must provide ID or name for Droplet to destroy.\n")
os.Exit(1)
}
size := ctx.String("size")
disk := ctx.Bool("disk")
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
id := ctx.Int("id")
if id == 0 {
droplet, err := FindDropletByName(client, ctx.Args()[0])
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(64)
} else {
id = droplet.ID
}
}
droplet, _, err := client.Droplets.Get(id)
if err != nil {
fmt.Printf("Unable to find Droplet: %s\n", err)
os.Exit(1)
}
action, _, err := client.DropletActions.Resize(droplet.ID, size, disk)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
WriteOutput(action)
}
示例2: dropletCreate
func dropletCreate(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
log.Fatal("Error: Must provide name for Droplet.")
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
// Add domain to end if available.
dropletName := ctx.Args().First()
if ctx.Bool("add-region") {
dropletName = fmt.Sprintf("%s.%s", dropletName, ctx.String("region"))
}
if ctx.String("domain") != "" {
dropletName = fmt.Sprintf("%s.%s", dropletName, ctx.String("domain"))
}
// Loop through the SSH Keys and add by name. DO API should have handled
// this case as well.
var sshKeys []godo.DropletCreateSSHKey
keyNames := ctx.String("ssh-keys")
if keyNames != "" {
for _, keyName := range strings.Split(keyNames, ",") {
sshKey, err := FindKeyByName(client, keyName)
if sshKey != nil && err == nil {
sshKeys = append(sshKeys, godo.DropletCreateSSHKey{ID: sshKey.ID})
} else {
log.Fatalf("Warning: Could not find key: %q.", keyName)
}
}
}
userData := ""
userDataPath := ctx.String("user-data-file")
if userDataPath != "" {
file, err := os.Open(userDataPath)
if err != nil {
log.Fatalf("Error opening user data file: %s.", err)
}
userDataFile, err := ioutil.ReadAll(file)
if err != nil {
log.Fatalf("Error reading user data file: %s.", err)
}
userData = string(userDataFile)
} else {
userData = ctx.String("user-data")
}
createRequest := &godo.DropletCreateRequest{
Name: dropletName,
Region: ctx.String("region"),
Size: ctx.String("size"),
Image: godo.DropletCreateImage{
Slug: ctx.String("image"),
},
SSHKeys: sshKeys,
Backups: ctx.Bool("backups"),
IPv6: ctx.Bool("ipv6"),
PrivateNetworking: ctx.Bool("private-networking"),
UserData: userData,
}
droplet, resp, err := client.Droplets.Create(createRequest)
if err != nil {
log.Fatalf("Unable to create Droplet: %s.", err)
}
if ctx.Bool("wait-for-active") {
util.WaitForActive(client, resp.Links.Actions[0].HREF)
}
WriteOutput(droplet)
}