本文整理汇总了Golang中github.com/convox/cli/Godeps/_workspace/src/github.com/codegangsta/cli.Context.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.String方法的具体用法?Golang Context.String怎么用?Golang Context.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/convox/cli/Godeps/_workspace/src/github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.String方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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")
}
示例2: DirApp
func DirApp(c *cli.Context, wd string) (string, string, error) {
abs, err := filepath.Abs(wd)
if err != nil {
return "", "", err
}
app := c.String("app")
if app == "" {
app = path.Base(abs)
}
return abs, app, nil
}
示例3: cmdScale
func cmdScale(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
v := url.Values{}
if c.IsSet("count") {
v.Set("count", c.String("count"))
}
if c.IsSet("memory") {
v.Set("mem", c.String("memory"))
}
if len(v) > 0 {
_, err = ConvoxPostForm("/apps/"+app, v)
if err != nil {
stdcli.Error(err)
return
}
}
data, err := ConvoxGet("/apps/" + app)
if err != nil {
stdcli.Error(err)
return
}
var a *App
err = json.Unmarshal(data, &a)
if err != nil {
stdcli.Error(err)
return
}
fmt.Printf("Count %v\n", a.Parameters["DesiredCount"])
fmt.Printf("Memory %v\n", a.Parameters["Memory"])
}
示例4: cmdSystemScale
func cmdSystemScale(c *cli.Context) {
v := url.Values{}
if c.IsSet("count") {
v.Set("count", c.String("count"))
}
if c.IsSet("type") {
v.Set("type", c.String("type"))
}
if len(v) > 0 {
_, err := ConvoxPostForm("/system", v)
if err != nil {
stdcli.Error(err)
return
}
}
cmdSystem(c)
}
示例5: cmdScale
func cmdScale(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) < 1 {
stdcli.Usage(c, "scale")
return
}
v := url.Values{}
if c.IsSet("count") {
v.Set("count", c.String("count"))
}
if c.IsSet("memory") {
v.Set("mem", c.String("memory"))
}
if len(v) > 0 {
v.Set("process", c.Args()[0])
_, err = ConvoxPostForm("/apps/"+app, v)
if err != nil {
stdcli.Error(err)
return
}
}
data, err := ConvoxGet("/apps/" + app)
if err != nil {
stdcli.Error(err)
return
}
var a *App
err = json.Unmarshal(data, &a)
if err != nil {
stdcli.Error(err)
return
}
processes := make(map[string]Process, 0)
longest := 7
for k, v := range a.Parameters {
if !strings.HasSuffix(k, "DesiredCount") {
continue
}
ps := strings.Replace(k, "DesiredCount", "", 1)
p := strings.ToLower(ps)
i, err := strconv.ParseInt(v, 10, 64)
if err != nil {
stdcli.Error(err)
return
}
m, err := strconv.ParseInt(a.Parameters[ps+"Memory"], 10, 64)
if err != nil {
stdcli.Error(err)
return
}
processes[p] = Process{Name: p, Count: i, Memory: m}
}
fmt.Printf(fmt.Sprintf("%%-%ds %%-5s %%-5s\n", longest), "PROCESS", "COUNT", "MEM")
for _, ps := range processes {
fmt.Printf(fmt.Sprintf("%%-%ds %%-5d %%-5d\n", longest), ps.Name, ps.Count, ps.Memory)
}
}
示例6: cmdLogin
func cmdLogin(c *cli.Context) {
if len(c.Args()) != 1 {
stdcli.Usage(c, "login")
}
host := c.Args()[0]
u, err := url.Parse(host)
if err != nil {
stdcli.Error(err)
return
}
if u.Host != "" {
host = u.Host
}
password := c.String("password")
if password == "" {
fmt.Print("Password: ")
in, err := terminal.ReadPassword(int(os.Stdin.Fd()))
fmt.Println()
if err != nil {
stdcli.Error(err)
return
}
password = string(in)
}
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
req, err := http.NewRequest("GET", fmt.Sprintf("https://%s/apps", host), nil)
if err != nil {
stdcli.Error(err)
return
}
req.SetBasicAuth("convox", string(password))
res, err := client.Do(req)
if err != nil {
stdcli.Error(err)
return
}
defer res.Body.Close()
if res.StatusCode != 200 {
stdcli.Error(fmt.Errorf("invalid login"))
return
}
err = addLogin(host, password)
if err != nil {
stdcli.Error(err)
return
}
err = switchHost(host)
if err != nil {
stdcli.Error(err)
return
}
fmt.Println("Logged in successfully.")
}
示例7: cmdScale
func cmdScale(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
v := url.Values{}
if c.IsSet("count") {
v.Set("count", c.String("count"))
}
if c.IsSet("memory") {
v.Set("mem", c.String("memory"))
}
if len(v) > 0 {
v.Set("process", c.Args()[0])
_, err = ConvoxPostForm("/apps/"+app, v)
if err != nil {
stdcli.Error(err)
return
}
}
data, err := ConvoxGet("/apps/" + app)
if err != nil {
stdcli.Error(err)
return
}
var a *App
err = json.Unmarshal(data, &a)
if err != nil {
stdcli.Error(err)
return
}
processes := map[string]Process{}
names := []string{}
for k, v := range a.Parameters {
if !strings.HasSuffix(k, "DesiredCount") {
continue
}
ps := strings.Replace(k, "DesiredCount", "", 1)
p := strings.ToLower(ps)
i, err := strconv.ParseInt(v, 10, 64)
if err != nil {
stdcli.Error(err)
return
}
m, err := strconv.ParseInt(a.Parameters[ps+"Memory"], 10, 64)
if err != nil {
stdcli.Error(err)
return
}
processes[p] = Process{Name: p, Count: i, Memory: m}
names = append(names, p)
}
sort.Strings(names)
t := stdcli.NewTable("PROCESS", "COUNT", "MEM")
for _, name := range names {
ps := processes[name]
t.AddRow(ps.Name, fmt.Sprintf("%d", ps.Count), fmt.Sprintf("%d", ps.Memory))
}
t.Print()
}
示例8: cmdUninstall
func cmdUninstall(c *cli.Context) {
fmt.Println(`
___ ___ ___ __ __ ___ __ _
/'___\ / __'\ /' _ '\/\ \/\ \ / __'\/\ \/'\
/\ \__//\ \_\ \/\ \/\ \ \ \_/ |/\ \_\ \/> </
\ \____\ \____/\ \_\ \_\ \___/ \ \____//\_/\_\
\/____/\/___/ \/_/\/_/\/__/ \/___/ \//\/_/
`)
fmt.Println("This uninstaller needs AWS credentials to uninstall the Convox platform from")
fmt.Println("your AWS account. These credentials will only be used to communicate")
fmt.Println("between this uninstaller running on your computer and the AWS API.")
fmt.Println("")
fmt.Println("We recommend that you create a new set of credentials exclusively for this")
fmt.Println("uninstall process and then delete them once the uninstaller has completed.")
fmt.Println("")
fmt.Println("To generate a new set of AWS credentials go to:")
fmt.Println("https://docs.convox.com/docs/creating-an-iam-user-and-credentials")
fmt.Println("")
reader := bufio.NewReader(os.Stdin)
access := os.Getenv("AWS_ACCESS_KEY_ID")
secret := os.Getenv("AWS_SECRET_ACCESS_KEY")
region := c.String("region")
if access == "" || secret == "" {
var err error
fmt.Print("AWS Access Key: ")
access, err = reader.ReadString('\n')
if err != nil {
stdcli.Error(err)
}
fmt.Print("AWS Secret Access Key: ")
secret, err = reader.ReadString('\n')
if err != nil {
stdcli.Error(err)
}
}
stackName := c.String("stack-name")
fmt.Println("")
fmt.Println("Uninstalling Convox...")
distinctId := randomString(10)
access = strings.TrimSpace(access)
secret = strings.TrimSpace(secret)
CloudFormation := cloudformation.New(&aws.Config{
Region: region,
Credentials: credentials.NewStaticCredentials(access, secret, ""),
})
res, err := CloudFormation.DescribeStacks(&cloudformation.DescribeStacksInput{
StackName: aws.String(stackName),
})
if err != nil {
sendMixpanelEvent(fmt.Sprintf("convox-uninstall-error"), err.Error())
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "ValidationError" {
stdcli.Error(fmt.Errorf("Stack %q does not exist.", stackName))
}
}
stdcli.Error(err)
}
stackId := *res.Stacks[0].StackID
_, err = CloudFormation.DeleteStack(&cloudformation.DeleteStackInput{
StackName: aws.String(stackId),
})
if err != nil {
handleError("uninstall", distinctId, err)
return
}
sendMixpanelEvent("convox-uninstall-start", "")
_, err = waitForCompletion(stackId, CloudFormation, true)
if err != nil {
handleError("uninstall", distinctId, err)
return
}
//.........这里部分代码省略.........
示例9: cmdInstall
func cmdInstall(c *cli.Context) {
region := c.String("region")
if !lambdaRegions[region] {
stdcli.Error(fmt.Errorf("Convox is not currently supported in %s", region))
}
tenancy := "default"
instanceType := c.String("instance-type")
if c.Bool("dedicated") {
tenancy = "dedicated"
if strings.HasPrefix(instanceType, "t2") {
stdcli.Error(fmt.Errorf("t2 instance types aren't supported in dedicated tenancy, please set --instance-type."))
}
}
fmt.Println(`
___ ___ ___ __ __ ___ __ _
/ ___\ / __ \ / _ \/\ \/\ \ / __ \/\ \/ \
/\ \__//\ \_\ \/\ \/\ \ \ \_/ |/\ \_\ \/> </
\ \____\ \____/\ \_\ \_\ \___/ \ \____//\_/\_\
\/____/\/___/ \/_/\/_/\/__/ \/___/ \//\/_/
`)
fmt.Println("This installer needs AWS credentials to install the Convox platform into")
fmt.Println("your AWS account. These credentials will only be used to communicate")
fmt.Println("between this installer running on your computer and the AWS API.")
fmt.Println("")
fmt.Println("We recommend that you create a new set of credentials exclusively for this")
fmt.Println("install process and then delete them once the installer has completed.")
fmt.Println("")
fmt.Println("To generate a new set of AWS credentials go to:")
fmt.Println("https://docs.convox.com/docs/creating-an-iam-user-and-credentials")
fmt.Println("")
distinctId, err := currentId()
if err != nil {
handleError("install", distinctId, err)
return
}
reader := bufio.NewReader(os.Stdin)
access := os.Getenv("AWS_ACCESS_KEY_ID")
secret := os.Getenv("AWS_SECRET_ACCESS_KEY")
if access == "" || secret == "" {
var err error
fmt.Print("AWS Access Key ID: ")
access, err = reader.ReadString('\n')
if err != nil {
stdcli.Error(err)
}
fmt.Print("AWS Secret Access Key: ")
secret, err = reader.ReadString('\n')
if err != nil {
stdcli.Error(err)
}
fmt.Println("")
}
development := "No"
if c.Bool("development") {
development = "Yes"
}
key := c.String("key")
stackName := c.String("stack-name")
version := c.String("version")
instanceCount := fmt.Sprintf("%d", c.Int("instance-count"))
fmt.Println("Installing Convox...")
access = strings.TrimSpace(access)
secret = strings.TrimSpace(secret)
password := randomString(30)
CloudFormation := cloudformation.New(&aws.Config{
Region: region,
Credentials: credentials.NewStaticCredentials(access, secret, ""),
})
res, err := CloudFormation.CreateStack(&cloudformation.CreateStackInput{
Capabilities: []*string{aws.String("CAPABILITY_IAM")},
Parameters: []*cloudformation.Parameter{
//.........这里部分代码省略.........
示例10: cmdUninstall
func cmdUninstall(c *cli.Context) {
if !c.Bool("force") {
apps := getApps()
if len(*apps) != 0 {
stdcli.Error(fmt.Errorf("Please delete all apps before uninstalling."))
}
}
fmt.Println(`
___ ___ ___ __ __ ___ __ _
/'___\ / __'\ /' _ '\/\ \/\ \ / __'\/\ \/'\
/\ \__//\ \_\ \/\ \/\ \ \ \_/ |/\ \_\ \/> </
\ \____\ \____/\ \_\ \_\ \___/ \ \____//\_/\_\
\/____/\/___/ \/_/\/_/\/__/ \/___/ \//\/_/
`)
fmt.Println("This uninstaller needs AWS credentials to uninstall the Convox platform from")
fmt.Println("your AWS account. These credentials will only be used to communicate")
fmt.Println("between this uninstaller running on your computer and the AWS API.")
fmt.Println("")
fmt.Println("We recommend that you create a new set of credentials exclusively for this")
fmt.Println("uninstall process and then delete them once the uninstaller has completed.")
fmt.Println("")
fmt.Println("To generate a new set of AWS credentials go to:")
fmt.Println("https://console.aws.amazon.com/iam/home#security_credential")
fmt.Println("")
reader := bufio.NewReader(os.Stdin)
access := os.Getenv("AWS_ACCESS_KEY_ID")
secret := os.Getenv("AWS_SECRET_ACCESS_KEY")
if access == "" || secret == "" {
var err error
fmt.Print("AWS Access Key: ")
access, err = reader.ReadString('\n')
if err != nil {
stdcli.Error(err)
}
fmt.Print("AWS Secret Access Key: ")
secret, err = reader.ReadString('\n')
if err != nil {
stdcli.Error(err)
}
}
stackName := os.Getenv("STACK_NAME")
if stackName == "" {
stackName = "convox"
}
fmt.Println("")
fmt.Println("Uninstalling Convox...")
distinctId := randomString(10)
access = strings.TrimSpace(access)
secret = strings.TrimSpace(secret)
CloudFormation := cloudformation.New(&aws.Config{
Region: c.String("region"),
Credentials: credentials.NewStaticCredentials(access, secret, ""),
})
res, err := CloudFormation.DescribeStackResources(&cloudformation.DescribeStackResourcesInput{
StackName: aws.String(stackName),
})
if err != nil {
handleError("uninstall", distinctId, err)
return
}
stackId := ""
bucket := ""
for _, r := range res.StackResources {
stackId = *r.StackID
if *r.LogicalResourceID == "RegistryBucket" {
bucket = *r.PhysicalResourceID
}
}
_, err = CloudFormation.DeleteStack(&cloudformation.DeleteStackInput{
StackName: aws.String(stackName),
})
if err != nil {
handleError("uninstall", distinctId, err)
//.........这里部分代码省略.........
示例11: cmdInstall
func cmdInstall(c *cli.Context) {
tenancy := "default"
instanceType := c.String("instance-type")
if c.Bool("dedicated") {
tenancy = "dedicated"
if strings.HasPrefix(instanceType, "t2") {
stdcli.Error(fmt.Errorf("t2 instance types aren't supported in dedicated tenancy, please set --instance-type."))
}
}
fmt.Println(`
___ ___ ___ __ __ ___ __ _
/ ___\ / __ \ / _ \/\ \/\ \ / __ \/\ \/ \
/\ \__//\ \_\ \/\ \/\ \ \ \_/ |/\ \_\ \/> </
\ \____\ \____/\ \_\ \_\ \___/ \ \____//\_/\_\
\/____/\/___/ \/_/\/_/\/__/ \/___/ \//\/_/
`)
fmt.Println("This installer needs AWS credentials to install the Convox platform into")
fmt.Println("your AWS account. These credentials will only be used to communicate")
fmt.Println("between this installer running on your computer and the AWS API.")
fmt.Println("")
fmt.Println("We recommend that you create a new set of credentials exclusively for this")
fmt.Println("install process and then delete them once the installer has completed.")
fmt.Println("")
fmt.Println("To generate a new set of AWS credentials go to:")
fmt.Println("https://console.aws.amazon.com/iam/home?region=us-east-1#security_credential")
fmt.Println("")
distinctId, err := currentId()
if err != nil {
handleError("install", distinctId, err)
return
}
reader := bufio.NewReader(os.Stdin)
access := os.Getenv("AWS_ACCESS_KEY_ID")
secret := os.Getenv("AWS_SECRET_ACCESS_KEY")
if access == "" || secret == "" {
var err error
fmt.Print("AWS Access Key ID: ")
access, err = reader.ReadString('\n')
if err != nil {
stdcli.Error(err)
}
fmt.Print("AWS Secret Access Key: ")
secret, err = reader.ReadString('\n')
if err != nil {
stdcli.Error(err)
}
fmt.Println("")
}
development := os.Getenv("DEVELOPMENT")
if development != "Yes" {
development = "No"
}
key := os.Getenv("KEY")
stackName := os.Getenv("STACK_NAME")
if stackName == "" {
stackName = "convox"
}
version := os.Getenv("VERSION")
if version == "" {
version = "latest"
}
instanceCount := fmt.Sprintf("%d", c.Int("instance-count"))
fmt.Println("Installing Convox...")
access = strings.TrimSpace(access)
secret = strings.TrimSpace(secret)
password := randomString(30)
CloudFormation := cloudformation.New(&aws.Config{
Region: "us-east-1",
Credentials: credentials.NewStaticCredentials(access, secret, ""),
})
//.........这里部分代码省略.........