当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.String方法代码示例

本文整理汇总了Golang中github.com/convox/rack/Godeps/_workspace/src/github.com/codegangsta/cli.Context.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.String方法的具体用法?Golang Context.String怎么用?Golang Context.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/convox/rack/Godeps/_workspace/src/github.com/codegangsta/cli.Context的用法示例。


在下文中一共展示了Context.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: cmdScale

func cmdScale(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	count := c.String("count")
	memory := c.String("memory")

	if len(c.Args()) == 0 && count == "" && memory == "" {
		displayFormation(c, app)
		return
	}

	if len(c.Args()) != 1 || (count == "" && memory == "") {
		stdcli.Usage(c, "scale")
		return
	}

	process := c.Args()[0]

	err = rackClient(c).SetFormation(app, process, count, memory)

	if err != nil {
		stdcli.Error(err)
		return
	}

	displayFormation(c, app)
}
开发者ID:soulware,项目名称:rack,代码行数:32,代码来源:scale.go

示例2: cmdRegistryAdd

func cmdRegistryAdd(c *cli.Context) {
	if len(c.Args()) < 1 {
		stdcli.Usage(c, "add")
		return
	}

	server := c.Args()[0]
	username := c.String("username")
	password := c.String("password")
	email := c.String("email")

	if username == "" {
		username = promptForUsername()
	}

	if password == "" {
		password = promptForPassword()
	}

	_, err := rackClient(c).AddRegistry(server, username, password, email)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Println("Done.")
}
开发者ID:anthonyrisinger,项目名称:rack,代码行数:28,代码来源:registries.go

示例3: cmdRackScale

func cmdRackScale(c *cli.Context) {
	count := 0
	typ := ""

	if c.IsSet("count") {
		count = c.Int("count")
	}

	if c.IsSet("type") {
		typ = c.String("type")
	}

	system, err := rackClient(c).ScaleSystem(count, typ)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Name     %s\n", system.Name)
	fmt.Printf("Status   %s\n", system.Status)
	fmt.Printf("Version  %s\n", system.Version)
	fmt.Printf("Count    %d\n", system.Count)
	fmt.Printf("Type     %s\n", system.Type)
}
开发者ID:soulware,项目名称:rack,代码行数:25,代码来源:rack.go

示例4: DirApp

// If user specifies the app's name from command line, then use it;
// if not, try to read the app name from .convox/app
// otherwise use the current working directory's name
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, err = ReadSetting("app")

		if err != nil {
			app = ""
		}
	}

	if app == "" {
		app = path.Base(abs)
	}

	app = strings.ToLower(app)

	return abs, app, nil
}
开发者ID:anthonyrisinger,项目名称:rack,代码行数:28,代码来源:stdcli.go

示例5: cmdDeploy

func cmdDeploy(c *cli.Context) {
	wd := "."

	if len(c.Args()) > 0 {
		wd = c.Args()[0]
	}

	dir, app, err := stdcli.DirApp(c, wd)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Deploying %s\n", app)

	a, err := rackClient(c).GetApp(app)

	if err != nil {
		stdcli.Error(err)
		return
	}

	switch a.Status {
	case "creating":
		stdcli.Error(fmt.Errorf("app is still creating: %s", app))
		return
	case "running", "updating":
	default:
		stdcli.Error(fmt.Errorf("unable to build app: %s", app))
		return
	}

	// build
	release, err := executeBuild(c, dir, app, c.String("file"), c.String("description"))

	if err != nil {
		stdcli.Error(err)
		return
	}

	if release == "" {
		return
	}

	fmt.Printf("Promoting %s... ", release)

	_, err = rackClient(c).PromoteRelease(app, release)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Println("UPDATING")
}
开发者ID:soulware,项目名称:rack,代码行数:56,代码来源:deploy.go

示例6: cmdBuildsCreate

func cmdBuildsCreate(c *cli.Context) {
	wd := "."

	if len(c.Args()) > 0 {
		wd = c.Args()[0]
	}

	dir, app, err := stdcli.DirApp(c, wd)

	if err != nil {
		stdcli.Error(err)
		return
	}

	a, err := rackClient(c).GetApp(app)

	if err != nil {
		stdcli.Error(err)
		return
	}

	switch a.Status {
	case "creating":
		stdcli.Error(fmt.Errorf("app is still creating: %s", app))
		return
	case "running", "updating":
	default:
		stdcli.Error(fmt.Errorf("unable to build app: %s", app))
		return
	}

	if len(c.Args()) > 0 {
		dir = c.Args()[0]
	}

	release, err := executeBuild(c, dir, app, c.String("file"), c.String("description"))

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Release: %s\n", release)
}
开发者ID:soulware,项目名称:rack,代码行数:44,代码来源:builds.go

示例7: cmdServiceCreate

func cmdServiceCreate(c *cli.Context) {
	if len(c.Args()) != 2 {
		stdcli.Usage(c, "create")
		return
	}

	t := c.Args()[0]
	name := c.Args()[1]
	url := c.String("url")

	fmt.Printf("Creating %s (%s)... ", name, t)

	_, err := rackClient(c).CreateService(t, name, url)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Println("CREATING")
}
开发者ID:gisnalbert,项目名称:rack,代码行数:21,代码来源:services.go

示例8: cmdStart

func cmdStart(c *cli.Context) {
	wd := "."

	if len(c.Args()) > 0 {
		wd = c.Args()[0]
	}

	dir, app, err := stdcli.DirApp(c, wd)

	if err != nil {
		stdcli.Error(err)
		return
	}

	file := c.String("file")

	m, err := manifest.Read(dir, file)

	if err != nil {
		changes, err := manifest.Init(dir)

		if err != nil {
			stdcli.Error(err)
			return
		}

		fmt.Printf("Generated: %s\n", strings.Join(changes, ", "))

		m, err = manifest.Read(dir, file)

		if err != nil {
			stdcli.Error(err)
			return
		}
	}

	missing := m.MissingEnvironment()

	if len(missing) > 0 {
		stdcli.Error(fmt.Errorf("env expected: %s", strings.Join(missing, ", ")))
		return
	}

	wanted, err := m.PortsWanted()

	if err != nil {
		stdcli.Error(err)
		return
	}

	conflicts := make([]string, 0)

	host := "127.0.0.1"

	if h := os.Getenv("DOCKER_HOST"); h != "" {
		u, err := url.Parse(h)

		if err != nil {
			stdcli.Error(err)
			return
		}

		parts := strings.Split(u.Host, ":")
		host = parts[0]
	}

	for _, p := range wanted {
		conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", host, p), 200*time.Millisecond)

		if err == nil {
			conflicts = append(conflicts, p)
			defer conn.Close()
		}
	}

	if len(conflicts) > 0 {
		stdcli.Error(fmt.Errorf("ports in use: %s", strings.Join(conflicts, ", ")))
		return
	}

	errors := m.Build(app, dir, true)

	if len(errors) != 0 {
		fmt.Printf("errors: %+v\n", errors)
		return
	}

	errors = m.Run(app)

	if len(errors) != 0 {
		// TODO figure out what to do here
		// fmt.Printf("errors: %+v\n", errors)
		return
	}
}
开发者ID:anthonyrisinger,项目名称:rack,代码行数:95,代码来源:start.go

示例9: cmdSSLCreate

func cmdSSLCreate(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(c.Args()) < 1 {
		stdcli.Usage(c, "create")
		return
	}

	target := c.Args()[0]

	parts := strings.Split(target, ":")

	if len(parts) != 2 {
		stdcli.Error(fmt.Errorf("target must be process:port"))
		return
	}

	var pub []byte
	var key []byte

	switch len(c.Args()) {
	case 1:
		if c.Bool("self-signed") {
			formation, err := rackClient(c).ListFormation(app)

			if err != nil {
				stdcli.Error(err)
				return
			}

			host := ""

			for _, entry := range formation {
				if entry.Name == parts[0] {
					host = entry.Balancer
				}
			}

			if host == "" {
				stdcli.Error(fmt.Errorf("no balancer for process: %s", parts[0]))
				return
			}

			pub, key, err = generateSelfSignedCertificate(app, host)

			if err != nil {
				stdcli.Error(err)
				return
			}
		} else {
			stdcli.Usage(c, "create")
			return
		}
	case 3:
		pub, err = ioutil.ReadFile(c.Args()[1])

		if err != nil {
			stdcli.Error(err)
			return
		}

		key, err = ioutil.ReadFile(c.Args()[2])

		if err != nil {
			stdcli.Error(err)
			return
		}
	default:
		stdcli.Usage(c, "create")
		return
	}

	chain := ""

	if chainFile := c.String("chain"); chainFile != "" {
		data, err := ioutil.ReadFile(chainFile)

		if err != nil {
			stdcli.Error(err)
			return
		}

		chain = string(data)
	}

	fmt.Printf("Creating SSL listener %s... ", target)

	_, err = rackClient(c).CreateSSL(app, parts[0], parts[1], string(pub), string(key), chain, c.Bool("secure"))

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Println("Done.")
//.........这里部分代码省略.........
开发者ID:kuenzaa,项目名称:rack,代码行数:101,代码来源:ssl.go

示例10: cmdSSLUpdate

func cmdSSLUpdate(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(c.Args()) < 1 {
		stdcli.Usage(c, "create")
		return
	}

	target := c.Args()[0]

	parts := strings.Split(target, ":")

	if len(parts) != 2 {
		stdcli.Error(fmt.Errorf("target must be process:port"))
		return
	}

	var pub []byte
	var key []byte

	pub, err = ioutil.ReadFile(c.Args()[1])

	if err != nil {
		stdcli.Error(err)
		return
	}

	key, err = ioutil.ReadFile(c.Args()[2])

	if err != nil {
		stdcli.Error(err)
		return
	}

	chain := ""

	if chainFile := c.String("chain"); chainFile != "" {
		data, err := ioutil.ReadFile(chainFile)

		if err != nil {
			stdcli.Error(err)
			return
		}

		chain = string(data)
	}

	fmt.Printf("Updating SSL listener %s... ", target)

	_, err = rackClient(c).UpdateSSL(app, parts[0], parts[1], string(pub), string(key), chain)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Println("Done.")
}
开发者ID:kuenzaa,项目名称:rack,代码行数:63,代码来源:ssl.go

示例11: cmdUninstall

func cmdUninstall(c *cli.Context) {
	if !c.Bool("force") {
		apps, err := rackClient(c).GetApps()

		if err != nil {
			stdcli.Error(err)
			return
		}

		if len(apps) != 0 {
			stdcli.Error(fmt.Errorf("Please delete all apps before uninstalling."))
		}

		services, err := rackClient(c).GetServices()

		if err != nil {
			stdcli.Error(err)
			return
		}

		if len(services) != 0 {
			stdcli.Error(fmt.Errorf("Please delete all services before uninstalling."))
		}
	}

	fmt.Println(Banner)

	creds, err := readCredentials(c)
	if err != nil {
		stdcli.Error(err)
		return
	}

	if creds == nil {
		stdcli.Error(fmt.Errorf("error reading credentials"))
		return
	}

	region := c.String("region")
	stackName := c.String("stack-name")

	fmt.Println("")

	fmt.Println("Uninstalling Convox...")

	// CF Stack Delete and Retry could take 30+ minutes. Periodically generate more progress output.
	go func() {
		t := time.Tick(2 * time.Minute)
		for range t {
			fmt.Println("Uninstalling Convox...")
		}
	}()

	distinctId := randomString(10)

	CloudFormation := cloudformation.New(session.New(), awsConfig(region, creds))

	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 {
		sendMixpanelEvent("convox-uninstall-retry", "")

		_, err = CloudFormation.DeleteStack(&cloudformation.DeleteStackInput{
			StackName: aws.String(stackId),
		})

		if err != nil {
			handleError("uninstall", distinctId, err)
			return
		}

//.........这里部分代码省略.........
开发者ID:cozmo,项目名称:rack,代码行数:101,代码来源:install.go

示例12: 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(Banner)

	distinctId, err := currentId()
	creds, err := readCredentials(c)

	if err != nil {
		handleError("install", distinctId, err)
		return
	}

	if creds == nil {
		err = fmt.Errorf("error reading credentials")
		handleError("install", distinctId, err)
		return
	}

	reader := bufio.NewReader(os.Stdin)

	if email := c.String("email"); email != "" {
		distinctId = email
		updateId(distinctId)
	} else if terminal.IsTerminal(int(os.Stdin.Fd())) {
		fmt.Print("Email Address (optional, to receive project updates): ")

		email, err := reader.ReadString('\n')

		if err != nil {
			handleError("install", distinctId, err)
			return
		}

		if strings.TrimSpace(email) != "" {
			distinctId = email
			updateId(email)
		}
	}

	development := "No"
	if c.Bool("development") {
		isDevelopment = true
		development = "Yes"
	}

	encryption := "Yes"
	if c.Bool("disable-encryption") {
		encryption = "No"
	}

	ami := c.String("ami")

	key := c.String("key")

	stackName := c.String("stack-name")

	vpcCIDR := c.String("vpc-cidr")

	subnet0CIDR := c.String("subnet0-cidr")

	subnet1CIDR := c.String("subnet1-cidr")

	subnet2CIDR := c.String("subnet2-cidr")

	versions, err := version.All()

	if err != nil {
		handleError("install", distinctId, err)
		return
	}

	version, err := versions.Resolve(c.String("version"))

	if err != nil {
		handleError("install", distinctId, err)
		return
	}

	versionName := version.Version
	formationUrl := fmt.Sprintf(FormationUrl, versionName)

	instanceCount := fmt.Sprintf("%d", c.Int("instance-count"))

	fmt.Printf("Installing Convox (%s)...\n", versionName)

//.........这里部分代码省略.........
开发者ID:cozmo,项目名称:rack,代码行数:101,代码来源:install.go

示例13: 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 := os.Getenv("CONVOX_PASSWORD")

	if password == "" {
		password = c.String("password")
	}

	if password != "" {
		// password flag
		err = testLogin(host, password, c.App.Version)
	} else {
		// first try current login
		password, err = getLogin(host)
		err = testLogin(host, password, c.App.Version)

		// then prompt for password
		if err != nil {
			password = promptForPassword()
			err = testLogin(host, password, c.App.Version)
		}
	}

	if err != nil {
		if strings.Contains(err.Error(), "401") {
			stdcli.Error(fmt.Errorf("invalid login"))
		} else {
			stdcli.Error(err)
		}
		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.")
}
开发者ID:inconshreveable,项目名称:rack,代码行数:63,代码来源:login.go

示例14: cmdUninstall

func cmdUninstall(c *cli.Context) {
	if !c.Bool("force") {
		apps, err := rackClient(c).GetApps()

		if err != nil {
			stdcli.Error(err)
			return
		}

		if len(apps) != 0 {
			stdcli.Error(fmt.Errorf("Please delete all apps before uninstalling."))
		}
	}

	fmt.Println(Banner)

	creds, err := readCredentials(c)
	if err != nil {
		stdcli.Error(err)
		return
	}

	if creds == nil {
		stdcli.Error(fmt.Errorf("error reading credentials"))
		return
	}

	region := c.String("region")
	stackName := c.String("stack-name")

	fmt.Println("")

	fmt.Println("Uninstalling Convox...")

	distinctId := randomString(10)

	CloudFormation := cloudformation.New(&aws.Config{
		Region:      aws.String(region),
		Credentials: credentials.NewStaticCredentials(creds.Access, creds.Secret, creds.Session),
	})

	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
	}

	host := ""
	for _, o := range res.Stacks[0].Outputs {
		if *o.OutputKey == "Dashboard" {
			host = *o.OutputValue
			break
		}
	}

	if configuredHost, _ := currentHost(); configuredHost == host {
		removeHost()
	}
	removeLogin(host)

	fmt.Println("Successfully uninstalled.")

	sendMixpanelEvent("convox-uninstall-success", "")
}
开发者ID:anthonyrisinger,项目名称:rack,代码行数:94,代码来源:install.go

示例15: cmdStart

func cmdStart(c *cli.Context) {
	wd := "."

	if len(c.Args()) > 0 {
		wd = c.Args()[0]
	}

	dir, app, err := stdcli.DirApp(c, wd)

	if err != nil {
		stdcli.Error(err)
		return
	}

	file := c.String("file")

	m, err := manifest.Read(dir, file)

	if err != nil {
		changes, err := manifest.Init(dir)

		if err != nil {
			stdcli.Error(err)
			return
		}

		fmt.Printf("Generated: %s\n", strings.Join(changes, ", "))

		m, err = manifest.Read(dir, file)

		if err != nil {
			stdcli.Error(err)
			return
		}
	}

	conflicts, err := m.PortConflicts()

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(conflicts) > 0 {
		stdcli.Error(fmt.Errorf("ports in use: %s", strings.Join(conflicts, ", ")))
		return
	}

	missing, err := m.MissingEnvironment()

	if err != nil {
		stdcli.Error(err)
		return
	}

	if len(missing) > 0 {
		stdcli.Error(fmt.Errorf("env expected: %s", strings.Join(missing, ", ")))
		return
	}

	errors := m.Build(app, dir, !c.Bool("no-cache"))

	if len(errors) != 0 {
		fmt.Printf("errors: %+v\n", errors)
		return
	}

	errors = m.Run(app)

	if len(errors) != 0 {
		// TODO figure out what to do here
		// fmt.Printf("errors: %+v\n", errors)
		return
	}
}
开发者ID:cozmo,项目名称:rack,代码行数:75,代码来源:start.go


注:本文中的github.com/convox/rack/Godeps/_workspace/src/github.com/codegangsta/cli.Context.String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。