本文整理汇总了Golang中github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context.Args方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Args方法的具体用法?Golang Context.Args怎么用?Golang Context.Args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.Args方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sshCreate
func sshCreate(ctx *cli.Context) {
if len(ctx.Args()) != 2 {
log.Fatal("Must provide name and public key file.")
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
file, err := os.Open(ctx.Args()[1])
if err != nil {
log.Fatalf("Error opening key file: %s.", err)
}
keyData, err := ioutil.ReadAll(file)
if err != nil {
log.Fatalf("Error reading key file: %s.", err)
}
createRequest := &godo.KeyCreateRequest{
Name: ctx.Args().First(),
PublicKey: string(keyData),
}
key, _, err := client.Keys.Create(createRequest)
if err != nil {
log.Fatal(err)
}
WriteOutput(key)
}
示例2: TestApp_RunAsSubcommandParseFlags
func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
var context *cli.Context
a := cli.NewApp()
a.Commands = []cli.Command{
{
Name: "foo",
Action: func(c *cli.Context) {
context = c
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "lang",
Value: "english",
Usage: "language for the greeting",
},
},
Before: func(_ *cli.Context) error { return nil },
},
}
a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})
expect(t, context.Args().Get(0), "abcd")
expect(t, context.String("lang"), "spanish")
}
示例3: dropletActionUpgrade
func dropletActionUpgrade(ctx *cli.Context) {
if ctx.Int("id") == 0 && len(ctx.Args()) != 1 {
log.Fatal("Error: Must provide ID or name for Droplet to resize.")
}
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 {
log.Fatal(err)
} else {
id = droplet.ID
}
}
droplet, _, err := client.Droplets.Get(id)
if err != nil {
log.Fatal("Unable to find Droplet: %s.", err)
}
action, _, err := client.DropletActions.Upgrade(droplet.ID)
if err != nil {
log.Fatal(err)
}
WriteOutput(action)
}
示例4: dropletDestroy
func dropletDestroy(ctx *cli.Context) {
if ctx.Int("id") == 0 && len(ctx.Args()) != 1 {
log.Fatal("Error: Must provide ID or name for Droplet to destroy.")
}
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 {
log.Fatal(err)
} else {
id = droplet.ID
}
}
droplet, _, err := client.Droplets.Get(id)
if err != nil {
log.Fatalf("Unable to find Droplet: %s.", err)
}
_, err = client.Droplets.Delete(id)
if err != nil {
log.Fatalf("Unable to destroy Droplet: %s.", err)
}
log.Fatalf("Droplet %s destroyed.", droplet.Name)
}
示例5: domainRecordList
func domainRecordList(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
fmt.Printf("Error: Must provide a domain name for which to list records.\n")
os.Exit(64)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
domainName := ctx.Args().First()
opt := &godo.ListOptions{
Page: ctx.Int("page"),
PerPage: ctx.Int("page-size"),
}
domainDecords, _, err := client.Domains.Records(domainName, opt)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}
WriteOutput(domainDecords)
}
示例6: sshDestroy
func sshDestroy(ctx *cli.Context) {
if ctx.Int("id") == 0 && ctx.String("fingerprint") == "" && len(ctx.Args()) < 1 {
fmt.Printf("Error: Must provide ID, fingerprint or name for SSH Key to destroy.\n")
os.Exit(1)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
id := ctx.Int("id")
fingerprint := ctx.String("fingerprint")
var key godo.Key
if id == 0 && fingerprint == "" {
key, err := FindKeyByName(client, ctx.Args().First())
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(64)
} else {
id = key.ID
}
} else if id != 0 {
key, _, err := client.Keys.GetByID(id)
if err != nil {
fmt.Printf("Unable to find SSH Key: %s\n", err)
os.Exit(1)
} else {
id = key.ID
}
} else {
key, _, err := client.Keys.GetByFingerprint(fingerprint)
if err != nil {
fmt.Printf("Unable to find SSH Key: %s\n", err)
os.Exit(1)
} else {
id = key.ID
}
}
_, err := client.Keys.DeleteByID(id)
if err != nil {
fmt.Printf("Unable to destroy SSH Key: %s\n", err)
os.Exit(1)
}
fmt.Printf("Key %s destroyed.\n", key.Name)
}
示例7: domainShow
func domainShow(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
log.Fatal("Error: Must provide name for Domain.")
}
name := ctx.Args().First()
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
domain, _, err := client.Domains.Get(name)
if err != nil {
log.Fatal(err)
}
WriteOutput(domain)
}
示例8: domainDestroy
func domainDestroy(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
log.Fatal("Error: Must provide a name for the domain to destroy.")
}
name := ctx.Args().First()
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
_, err := client.Domains.Delete(name)
if err != nil {
log.Fatalf("Unable to destroy domain: %s.", err)
}
log.Printf("Domain %s destroyed", name)
}
示例9: sshFind
func sshFind(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
log.Fatal("Error: Must provide name for Key.")
}
name := ctx.Args().First()
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
key, err := FindKeyByName(client, name)
if err != nil {
log.Fatal(err)
}
WriteOutput(key)
}
示例10: domainCreate
func domainCreate(ctx *cli.Context) {
if len(ctx.Args()) != 2 {
log.Fatal("Must provide domain name and Droplet name.")
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
droplet, err := FindDropletByName(client, ctx.Args()[1])
if err != nil {
log.Fatal(err)
}
createRequest := &godo.DomainCreateRequest{
Name: ctx.Args().First(),
IPAddress: PublicIPForDroplet(droplet),
}
domain, _, err := client.Domains.Create(createRequest)
if err != nil {
log.Fatal(err)
}
WriteOutput(domain)
}
示例11: 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)
}
示例12: domainRecordDestroy
func domainRecordDestroy(ctx *cli.Context) {
if len(ctx.Args()) != 2 {
fmt.Printf("Error: Must provide domain name and domain record id.\n")
os.Exit(1)
}
domainName := ctx.Args().First()
recordID, err := strconv.Atoi(ctx.Args()[1])
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
_, err = client.Domains.DeleteRecord(domainName, recordID)
if err != nil {
fmt.Printf("Unable to destroy domain record: %s\n", err)
os.Exit(1)
}
fmt.Printf("Domain record %d destroyed.\n", recordID)
}
示例13: domainRecordShow
func domainRecordShow(ctx *cli.Context) {
if len(ctx.Args()) == 2 {
fmt.Printf("Error: Must provide domain name and domain record id.\n")
os.Exit(64)
}
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
domainName := ctx.Args().First()
recordID, err := strconv.Atoi(ctx.Args()[1])
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}
domainDecord, _, err := client.Domains.Record(domainName, recordID)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}
WriteOutput(domainDecord)
}
示例14: sshFind
func sshFind(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
fmt.Printf("Error: Must provide name for Key.\n")
os.Exit(1)
}
name := ctx.Args().First()
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
key, err := FindKeyByName(client, name)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(64)
}
WriteOutput(key)
}
示例15: domainShow
func domainShow(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
fmt.Printf("Error: Must provide name for Domain.\n")
os.Exit(64)
}
name := ctx.Args().First()
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
domain, _, err := client.Domains.Get(name)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}
WriteOutput(domain)
}