本文整理汇总了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)
}
示例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"]))
}
示例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
}
}
示例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)
}
示例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")
}
示例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()))
}
}
示例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])
}
}
示例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)
}
示例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
}
}
示例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
}
示例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)
}
示例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")
}
示例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
}
}
示例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")
}
示例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
}
}