當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cli.Context類代碼示例

本文整理匯總了Golang中github.com/convox/cli/Godeps/_workspace/src/github.com/codegangsta/cli.Context的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Context類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: cmdServiceInfo

func cmdServiceInfo(c *cli.Context) {
	if len(c.Args()) != 1 {
		stdcli.Usage(c, "info")
		return
	}

	name := c.Args()[0]

	data, err := ConvoxGet("/services/" + name)

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

	var s *Service
	err = json.Unmarshal(data, &s)

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

	fmt.Printf("Name    %s\n", s.Name)
	fmt.Printf("Status  %s\n", s.Status)
	fmt.Printf("URL     %s\n", s.URL)
}
開發者ID:linearregression,項目名稱:cli,代碼行數:27,代碼來源:services.go

示例2: cmdServiceInfo

func cmdServiceInfo(c *cli.Context) {
	if len(c.Args()) != 1 {
		stdcli.Usage(c, "info")
		return
	}

	name := c.Args()[0]

	data, err := ConvoxGet("/services/" + name)

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

	var s *Service
	err = json.Unmarshal(data, &s)

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

	fmt.Printf("Name    %s\n", s.Name)
	fmt.Printf("Status  %s\n", s.Status)
	fmt.Printf("URL     %s\n", fmt.Sprintf("%s://%s:%[email protected]%s:%s/%s", s.Tags["Service"], s.Outputs["EnvPostgresUsername"], s.Outputs["EnvPostgresPassword"], s.Outputs["Port5432TcpAddr"], s.Outputs["Port5432TcpPort"], s.Outputs["EnvPostgresDatabase"]))
}
開發者ID:ngotnghet,項目名稱:cli,代碼行數:27,代碼來源:services.go

示例3: cmdEnvSet

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

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

	resp, err := fetchEnv(app)

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

	var old map[string]string
	err = json.Unmarshal(resp, &old)

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

	data := ""

	for key, value := range old {
		data += fmt.Sprintf("%s=%s\n", key, value)
	}

	stat, err := os.Stdin.Stat()

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

	if (stat.Mode() & os.ModeCharDevice) == 0 {
		in, err := ioutil.ReadAll(os.Stdin)

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

		data += string(in)
	}

	for _, value := range c.Args() {
		data += fmt.Sprintf("%s\n", value)
	}

	path := fmt.Sprintf("/apps/%s/environment", app)

	resp, err = ConvoxPost(path, data)

	if err != nil {
		stdcli.Error(err)
		return
	}
}
開發者ID:nguyendangminh,項目名稱:cli,代碼行數:60,代碼來源:env.go

示例4: cmdBuildsInfo

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

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

	if len(c.Args()) != 1 {
		stdcli.Usage(c, "info")
		return
	}

	build := c.Args()[0]

	path := fmt.Sprintf("/apps/%s/builds/%s", app, build)

	resp, err := ConvoxGet(path)

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

	var b Build

	err = json.Unmarshal(resp, &b)

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

	fmt.Println(b.Logs)
}
開發者ID:noqcks,項目名稱:cli,代碼行數:35,代碼來源:builds.go

示例5: 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")
}
開發者ID:nguyendangminh,項目名稱:cli,代碼行數:25,代碼來源:app_test.go

示例6: cmdEnvGet

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

	if err != nil {
		stdcli.Error(err)
		return
	}
	if len(c.Args()) == 1 {
		variable := c.Args()[0]

		resp, err := fetchEnv(app)

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

		var env map[string]string
		json.Unmarshal(resp, &env)

		fmt.Println(env[variable])
	} else {
        	fmt.Printf("You supplied %d arguments to convox env get, 1 is required\n", len(c.Args()))
        }
}
開發者ID:srri,項目名稱:cli,代碼行數:25,代碼來源:env.go

示例7: cmdPs

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

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

	if len(c.Args()) == 0 {
		processList(app)
	} else {
		processTop(app, c.Args()[0])
	}
}
開發者ID:ngotnghet,項目名稱:cli,代碼行數:14,代碼來源:ps.go

示例8: cmdRun

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

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

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

	ps := c.Args()[0]

	command := ""

	if len(c.Args()) > 1 {
		args := c.Args()[1:]
		command = strings.Join(args, " ")
	}

	v := url.Values{}
	v.Set("command", command)

	_, err = ConvoxPostForm(fmt.Sprintf("/apps/%s/processes/%s/run", app, ps), v)

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

	fmt.Printf("Running %s `%s`\n", ps, command)
}
開發者ID:ngotnghet,項目名稱:cli,代碼行數:34,代碼來源:run.go

示例9: cmdExec

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

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

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

	ps := c.Args()[0]

	command := ""

	if len(c.Args()) > 1 {
		args := c.Args()[1:]
		command = strings.Join(args, " ")
	}

	err = stdcli.Run("docker", "exec", "-it", fmt.Sprintf("%s-%s", app, ps), "sh", "-c", command)

	if err != nil {
		stdcli.Error(err)
		return
	}
}
開發者ID:nguyendangminh,項目名稱:cli,代碼行數:29,代碼來源:exec.go

示例10: 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
}
開發者ID:rjocoleman,項目名稱:cli,代碼行數:15,代碼來源:stdcli.go

示例11: cmdSwitch

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

	host := c.Args()[0]

	err := switchHost(host)

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

	fmt.Printf("Switched to %s\n", host)
}
開發者ID:nguyendangminh,項目名稱:cli,代碼行數:17,代碼來源:switch.go

示例12: cmdServiceDelete

func cmdServiceDelete(c *cli.Context) {
	if len(c.Args()) != 1 {
		stdcli.Usage(c, "delete")
		return
	}

	name := c.Args()[0]

	fmt.Printf("Deleting %s... ", name)

	_, err := ConvoxDelete(fmt.Sprintf("/services/%s", name))

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

	fmt.Println("OK")
}
開發者ID:linearregression,項目名稱:cli,代碼行數:19,代碼來源:services.go

示例13: cmdEnvUnset

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

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

	variable := c.Args()[0]

	path := fmt.Sprintf("/apps/%s/environment/%s", app, variable)

	_, err = ConvoxDelete(path)

	if err != nil {
		stdcli.Error(err)
		return
	}
}
開發者ID:rjocoleman,項目名稱:cli,代碼行數:19,代碼來源:env.go

示例14: cmdAppDelete

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

	app := c.Args()[0]

	fmt.Printf("Deleting %s: ", app)

	_, err := ConvoxDelete(fmt.Sprintf("/apps/%s", app))

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

	fmt.Println("OK")
}
開發者ID:rjocoleman,項目名稱:cli,代碼行數:19,代碼來源:apps.go

示例15: cmdBuild

func cmdBuild(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
	}

	_, err = executeBuild(dir, app)

	if err != nil {
		stdcli.Error(err)
		return
	}
}
開發者ID:ngotnghet,項目名稱:cli,代碼行數:21,代碼來源:build.go


注:本文中的github.com/convox/cli/Godeps/_workspace/src/github.com/codegangsta/cli.Context類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。