本文整理汇总了Golang中github.com/convox/rack/Godeps/_workspace/src/github.com/codegangsta/cli.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cmdSSLDelete
func cmdSSLDelete(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) != 1 {
stdcli.Usage(c, "delete")
return
}
target := c.Args()[0]
parts := strings.Split(target, ":")
if len(parts) != 2 {
stdcli.Error(fmt.Errorf("target must be process:port"))
return
}
fmt.Printf("Deleting SSL listener %s... ", target)
_, err = rackClient(c).DeleteSSL(app, parts[0], parts[1])
if err != nil {
stdcli.Error(err)
return
}
fmt.Println("Done.")
}
示例2: cmdPsInfo
func cmdPsInfo(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
}
id := c.Args()[0]
p, err := rackClient(c).GetProcess(app, id)
if err != nil {
stdcli.Error(err)
return
}
fmt.Printf("Id %s\n", p.Id)
fmt.Printf("Name %s\n", p.Name)
fmt.Printf("Release %s\n", p.Release)
fmt.Printf("Size %d\n", p.Size)
fmt.Printf("CPU %0.2f%%\n", p.Cpu)
fmt.Printf("Memory %0.2f%%\n", p.Memory*100)
fmt.Printf("Started %s\n", humanizeTime(p.Started))
fmt.Printf("Command %s\n", p.Command)
}
示例3: 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
}
fmt.Printf("Promoting %s... ", release)
_, err = rackClient(c).PromoteRelease(app, release)
if err != nil {
stdcli.Error(err)
return
}
fmt.Println("UPDATING")
}
示例4: cmdInit
func cmdInit(c *cli.Context) {
wd := "."
if len(c.Args()) > 0 {
wd = c.Args()[0]
}
dir, _, err := stdcli.DirApp(c, wd)
if err != nil {
stdcli.Error(err)
return
}
changed, err := manifest.Init(dir)
if err != nil {
stdcli.Error(err)
return
}
if len(changed) > 0 {
fmt.Printf("Generated: %s\n", strings.Join(changed, ", "))
}
}
示例5: cmdPs
func cmdPs(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
ps, err := rackClient(c).GetProcesses(app, c.Bool("stats"))
if err != nil {
stdcli.Error(err)
return
}
if c.Bool("stats") {
t := stdcli.NewTable("ID", "NAME", "RELEASE", "SIZE", "CPU", "MEM", "STARTED", "COMMAND")
for _, p := range ps {
t.AddRow(prettyId(p), p.Name, p.Release, fmt.Sprintf("%d", p.Size), fmt.Sprintf("%0.2f%%", p.Cpu), fmt.Sprintf("%0.2f%%", p.Memory*100), humanizeTime(p.Started), p.Command)
}
t.Print()
} else {
t := stdcli.NewTable("ID", "NAME", "RELEASE", "SIZE", "STARTED", "COMMAND")
for _, p := range ps {
t.AddRow(prettyId(p), p.Name, p.Release, fmt.Sprintf("%d", p.Size), humanizeTime(p.Started), p.Command)
}
t.Print()
}
}
示例6: cmdAppCreate
func cmdAppCreate(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) > 0 {
app = c.Args()[0]
}
if app == "" {
stdcli.Error(fmt.Errorf("must specify an app name"))
return
}
fmt.Printf("Creating app %s... ", app)
_, err = rackClient(c).CreateApp(app)
if err != nil {
stdcli.Error(err)
return
}
fmt.Println("CREATING")
}
示例7: cmdPsStop
func cmdPsStop(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) != 1 {
stdcli.Usage(c, "stop")
return
}
id := c.Args()[0]
fmt.Printf("Stopping %s... ", id)
_, err = rackClient(c).StopProcess(app, id)
if err != nil {
stdcli.Error(err)
return
}
fmt.Println("OK")
}
示例8: cmdRackParamsSet
func cmdRackParamsSet(c *cli.Context) {
system, err := rackClient(c).GetSystem()
if err != nil {
stdcli.Error(err)
return
}
params := map[string]string{}
for _, arg := range c.Args() {
parts := strings.SplitN(arg, "=", 2)
if len(parts) != 2 {
stdcli.Error(fmt.Errorf("invalid argument: %s", arg))
return
}
params[parts[0]] = parts[1]
}
fmt.Print("Updating parameters... ")
err = rackClient(c).SetParameters(system.Name, params)
if err != nil {
stdcli.Error(err)
return
}
fmt.Println("OK")
}
示例9: executeBuildDir
func executeBuildDir(c *cli.Context, dir, app, manifest, description string) (string, error) {
dir, err := filepath.Abs(dir)
if err != nil {
return "", err
}
fmt.Print("Creating tarball... ")
tar, err := createTarball(dir)
if err != nil {
return "", err
}
fmt.Println("OK")
cache := !c.Bool("no-cache")
fmt.Print("Uploading... ")
build, err := rackClient(c).CreateBuildSource(app, tar, cache, manifest, description)
if err != nil {
return "", err
}
fmt.Println("OK")
return finishBuild(c, app, build)
}
示例10: cmdReleaseInfo
func cmdReleaseInfo(c *cli.Context) {
if len(c.Args()) < 1 {
stdcli.Usage(c, "release info")
return
}
release := c.Args()[0]
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
r, err := rackClient(c).GetRelease(app, release)
if err != nil {
stdcli.Error(err)
return
}
fmt.Printf("Id %s\n", r.Id)
fmt.Printf("Build %s\n", r.Build)
fmt.Printf("Created %s\n", r.Created)
fmt.Printf("Env ")
fmt.Println(strings.Replace(r.Env, "\n", "\n ", -1))
}
示例11: 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)
}
示例12: cmdEnvList
func cmdEnvList(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) > 0 {
stdcli.Error(fmt.Errorf("`convox env` does not take arguments. Perhaps you meant `convox env set`?"))
}
env, err := rackClient(c).GetEnvironment(app)
if err != nil {
stdcli.Error(err)
return
}
keys := []string{}
for key, _ := range env {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
fmt.Printf("%s=%s\n", key, env[key])
}
}
示例13: 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
}
示例14: cmdRackUpdate
func cmdRackUpdate(c *cli.Context) {
versions, err := version.All()
if err != nil {
stdcli.Error(err)
return
}
specified := "stable"
if len(c.Args()) > 0 {
specified = c.Args()[0]
}
version, err := versions.Resolve(specified)
if err != nil {
stdcli.Error(err)
return
}
system, err := rackClient(c).UpdateSystem(version.Version)
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)
}
示例15: cmdRackReleases
func cmdRackReleases(c *cli.Context) {
vs, err := version.All()
if err != nil {
return
}
selected := version.Versions{}
for _, v := range vs {
switch {
case !v.Published && c.Bool("unpublished"):
selected = append(selected, v)
case v.Published:
selected = append(selected, v)
}
}
sort.Sort(sort.Reverse(selected))
if len(selected) > 20 {
selected = selected[0:20]
}
for _, v := range selected {
fmt.Println(v.Version)
}
}