github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/ps.go (about) 1 package parser 2 3 import ( 4 "github.com/teamhephy/workflow-cli/cmd" 5 docopt "github.com/docopt/docopt-go" 6 ) 7 8 // Ps routes ps commands to their specific function. 9 func Ps(argv []string, cmdr cmd.Commander) error { 10 usage := ` 11 Valid commands for processes: 12 13 ps:list list application processes 14 ps:restart restart an application or its process types 15 ps:scale scale processes (e.g. web=4 worker=2) 16 17 Use 'deis help [command]' to learn more. 18 ` 19 20 switch argv[0] { 21 case "ps:list": 22 return psList(argv, cmdr) 23 case "ps:restart": 24 return psRestart(argv, cmdr) 25 case "ps:scale": 26 return psScale(argv, cmdr) 27 default: 28 if printHelp(argv, usage) { 29 return nil 30 } 31 32 if argv[0] == "ps" { 33 argv[0] = "ps:list" 34 return psList(argv, cmdr) 35 } 36 37 PrintUsage(cmdr) 38 return nil 39 } 40 } 41 42 func psList(argv []string, cmdr cmd.Commander) error { 43 usage := ` 44 Lists processes servicing an application. 45 46 Usage: deis ps:list [options] 47 48 Options: 49 -a --app=<app> 50 the uniquely identifiable name for the application. 51 ` 52 53 args, err := docopt.Parse(usage, argv, true, "", false, true) 54 if err != nil { 55 return err 56 } 57 58 // The 1000 is fake for now until API understands limits 59 return cmdr.PsList(safeGetValue(args, "--app"), 1000) 60 } 61 62 func psRestart(argv []string, cmdr cmd.Commander) error { 63 usage := ` 64 Restart an application, a process type or a specific process. 65 66 Usage: deis ps:restart [<type>] [options] 67 68 Arguments: 69 <type> 70 the process name as defined in your Procfile, such as 'web' or 'worker'. 71 To restart a particular process, use 'web-asdfg' or 'app-v2-web-asdfg'. 72 73 Options: 74 -a --app=<app> 75 the uniquely identifiable name for the application. 76 ` 77 78 args, err := docopt.Parse(usage, argv, true, "", false, true) 79 80 if err != nil { 81 return err 82 } 83 84 apps := safeGetValue(args, "--app") 85 tp := safeGetValue(args, "<type>") 86 return cmdr.PsRestart(apps, tp) 87 } 88 89 func psScale(argv []string, cmdr cmd.Commander) error { 90 usage := ` 91 Scales an application's processes by type. 92 93 Usage: deis ps:scale <type>=<num>... [options] 94 95 Arguments: 96 <type> 97 the process name as defined in your Procfile, such as 'web' or 'worker'. 98 Note that Dockerfile apps have a default 'cmd' process type. 99 <num> 100 the number of processes. 101 102 Options: 103 -a --app=<app> 104 the uniquely identifiable name for the application. 105 ` 106 107 args, err := docopt.Parse(usage, argv, true, "", false, true) 108 109 if err != nil { 110 return err 111 } 112 113 apps := safeGetValue(args, "--app") 114 return cmdr.PsScale(apps, args["<type>=<num>"].([]string)) 115 }