|
| 1 | +package parser |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/deis/workflow-cli/cmd" |
| 5 | + docopt "github.com/docopt/docopt-go" |
| 6 | +) |
| 7 | + |
| 8 | +// Maintenance displays all relevant commands for `deis maintenance`. |
| 9 | +func Maintenance(argv []string) error { |
| 10 | + usage := ` |
| 11 | +Valid commands for maintenance: |
| 12 | +
|
| 13 | +maintenance:info view maintenance mode of an application |
| 14 | +maintenance:on turn on maintenance for an app |
| 15 | +maintenance:off turn off maintenance for an app |
| 16 | +
|
| 17 | +Use 'deis help [command]' to learn more. |
| 18 | +` |
| 19 | + |
| 20 | + switch argv[0] { |
| 21 | + case "maintenance:info": |
| 22 | + return maintenanceInfo(argv) |
| 23 | + case "maintenance:on": |
| 24 | + return maintenanceEnable(argv) |
| 25 | + case "maintenance:off": |
| 26 | + return maintenanceDisable(argv) |
| 27 | + default: |
| 28 | + if printHelp(argv, usage) { |
| 29 | + return nil |
| 30 | + } |
| 31 | + |
| 32 | + if argv[0] == "maintenance" { |
| 33 | + argv[0] = "maintenance:info" |
| 34 | + return maintenanceInfo(argv) |
| 35 | + } |
| 36 | + |
| 37 | + PrintUsage() |
| 38 | + return nil |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +func maintenanceInfo(argv []string) error { |
| 43 | + usage := ` |
| 44 | +Prints info about the current application's maintenance state. |
| 45 | +
|
| 46 | +Usage: deis maintenance:info [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 | + |
| 55 | + if err != nil { |
| 56 | + return err |
| 57 | + } |
| 58 | + |
| 59 | + return cmd.MaintenanceInfo(safeGetValue(args, "--app")) |
| 60 | +} |
| 61 | + |
| 62 | +func maintenanceEnable(argv []string) error { |
| 63 | + usage := ` |
| 64 | +Enables maintenance mode for an app. |
| 65 | +
|
| 66 | +Usage: deis maintenance:on [options] |
| 67 | +
|
| 68 | +Options: |
| 69 | + -a --app=<app> |
| 70 | + the uniquely identifiable name of the application. |
| 71 | +` |
| 72 | + |
| 73 | + args, err := docopt.Parse(usage, argv, true, "", false, true) |
| 74 | + |
| 75 | + if err != nil { |
| 76 | + return err |
| 77 | + } |
| 78 | + |
| 79 | + return cmd.MaintenanceEnable(safeGetValue(args, "--app")) |
| 80 | +} |
| 81 | + |
| 82 | +func maintenanceDisable(argv []string) error { |
| 83 | + usage := ` |
| 84 | +Disables maintenance mode for an app. |
| 85 | +
|
| 86 | +Usage: deis maintenance:off [options] |
| 87 | +
|
| 88 | +Options: |
| 89 | + -a --app=<app> |
| 90 | + the uniquely identifiable name of the application. |
| 91 | +` |
| 92 | + |
| 93 | + args, err := docopt.Parse(usage, argv, true, "", false, true) |
| 94 | + |
| 95 | + if err != nil { |
| 96 | + return err |
| 97 | + } |
| 98 | + |
| 99 | + return cmd.MaintenanceDisable(safeGetValue(args, "--app")) |
| 100 | +} |
0 commit comments