github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/timeouts.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 // Timeouts routes timeouts commands to their specific function 9 func Timeouts(argv []string, cmdr cmd.Commander) error { 10 usage := ` 11 Valid commands for timeouts: 12 13 timeouts:list list resource timeouts for an app 14 timeouts:set set resource timeouts for an app 15 timeouts:unset unset resource timeouts for an app 16 17 Use 'deis help [command]' to learn more. 18 ` 19 20 switch argv[0] { 21 case "timeouts:list": 22 return timeoutList(argv, cmdr) 23 case "timeouts:set": 24 return timeoutSet(argv, cmdr) 25 case "timeouts:unset": 26 return timeoutUnset(argv, cmdr) 27 default: 28 if printHelp(argv, usage) { 29 return nil 30 } 31 32 if argv[0] == "timeouts" { 33 argv[0] = "timeouts:list" 34 return timeoutList(argv, cmdr) 35 } 36 37 PrintUsage(cmdr) 38 return nil 39 } 40 } 41 42 func timeoutList(argv []string, cmdr cmd.Commander) error { 43 usage := ` 44 Lists resource timeouts for an application. 45 46 Usage: deis timeouts:list [options] 47 48 Options: 49 -a --app=<app> 50 the uniquely identifiable name of the application. 51 ` 52 53 args, err := docopt.Parse(usage, argv, true, "", false, true) 54 55 if err != nil { 56 return err 57 } 58 59 return cmdr.TimeoutsList(safeGetValue(args, "--app")) 60 } 61 62 func timeoutSet(argv []string, cmdr cmd.Commander) error { 63 usage := ` 64 Sets termination grace period for an application. 65 66 Usage: deis timeouts:set [options] <type>=<value>... 67 68 Arguments: 69 <type> 70 the process type as defined in your Procfile, such as 'web' or 'worker'. 71 Note that Dockerfile apps have a default 'cmd' process type. 72 <value> 73 The value to apply to the process type in seconds. 74 75 Options: 76 -a --app=<app> 77 the uniquely identifiable name for the application. 78 ` 79 80 args, err := docopt.Parse(usage, argv, true, "", false, true) 81 82 if err != nil { 83 return err 84 } 85 86 app := safeGetValue(args, "--app") 87 timeouts := args["<type>=<value>"].([]string) 88 89 return cmdr.TimeoutsSet(app, timeouts) 90 } 91 92 func timeoutUnset(argv []string, cmdr cmd.Commander) error { 93 usage := ` 94 Unsets timeouts for an application. Default value (30s) 95 or KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS is used 96 97 Usage: deis timeouts:unset [options] <type>... 98 99 Arguments: 100 <type> 101 the process type as defined in your Procfile, such as 'web' or 'worker'. 102 Note that Dockerfile apps have a default 'cmd' process type. 103 104 Options: 105 -a --app=<app> 106 the uniquely identifiable name for the application. 107 ` 108 109 args, err := docopt.Parse(usage, argv, true, "", false, true) 110 111 if err != nil { 112 return err 113 } 114 115 app := safeGetValue(args, "--app") 116 timeouts := args["<type>"].([]string) 117 118 return cmdr.TimeoutsUnset(app, timeouts) 119 }