本文整理汇总了Golang中github.com/convox/cli/Godeps/_workspace/src/github.com/codegangsta/cli.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: cmdEnvGet
func cmdEnvGet(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) == 0 {
stdcli.Error(errors.New("No variable specified"))
return
}
if len(c.Args()) > 1 {
stdcli.Error(errors.New("Only 1 variable can be retrieved at a time"))
return
}
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])
}
开发者ID:redbadger,项目名称:cli,代码行数:32,代码来源:env.go
示例17: cmdEnvUnset
func cmdEnvUnset(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) == 0 {
stdcli.Error(errors.New("No variable specified"))
return
}
if len(c.Args()) > 1 {
stdcli.Error(errors.New("Only 1 variable can be unset at a time"))
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:nguyendangminh,项目名称:cli,代码行数:29,代码来源:env.go
示例18: cmdEnvGet
func cmdEnvGet(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
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])
}
开发者ID:rjocoleman,项目名称:cli,代码行数:22,代码来源:env.go
示例19: cmdReleasePromote
func cmdReleasePromote(c *cli.Context) {
if len(c.Args()) < 1 {
stdcli.Usage(c, "release promote")
return
}
release := c.Args()[0]
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
_, err = postRelease(app, release)
if err != nil {
stdcli.Error(err)
return
}
}
开发者ID:noqcks,项目名称:cli,代码行数:22,代码来源:releases.go
示例20: cmdSystemUpate
func cmdSystemUpate(c *cli.Context) {
version := ""
if len(c.Args()) == 0 {
resp, err := http.Get("http://convox.s3.amazonaws.com/release/latest/version")
if err != nil {
fmt.Printf("ERROR")
stdcli.Error(err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
stdcli.Error(err)
return
}
version = string(body)
} else {
version = c.Args()[0]
}
v := url.Values{}
v.Set("version", version)
_, err := ConvoxPostForm("/system", v)
if err != nil {
stdcli.Error(err)
return
}
cmdSystem(c)
}
开发者ID:rjocoleman,项目名称:cli,代码行数:38,代码来源:system.go
注:本文中的github.com/convox/cli/Godeps/_workspace/src/github.com/codegangsta/cli.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论