|
| 1 | +package parser |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/workato/deis-workflow-cli/cmd" |
| 5 | + docopt "github.com/docopt/docopt-go" |
| 6 | +) |
| 7 | + |
| 8 | +// Services routes service commands to their specific function. |
| 9 | +func Services(argv []string, cmdr cmd.Commander) error { |
| 10 | + usage := ` |
| 11 | +Valid commands for services: |
| 12 | +
|
| 13 | +services:add create service for an application |
| 14 | +services:list list application services |
| 15 | +services:remove remove service from an application |
| 16 | +
|
| 17 | +Use 'deis help [command]' to learn more. |
| 18 | +` |
| 19 | + |
| 20 | + switch argv[0] { |
| 21 | + case "services:add": |
| 22 | + return servicesAdd(argv, cmdr) |
| 23 | + case "services:list": |
| 24 | + return servicesList(argv, cmdr) |
| 25 | + case "services:remove": |
| 26 | + return servicesRemove(argv, cmdr) |
| 27 | + default: |
| 28 | + if printHelp(argv, usage) { |
| 29 | + return nil |
| 30 | + } |
| 31 | + |
| 32 | + if argv[0] == "services" { |
| 33 | + argv[0] = "services:list" |
| 34 | + return servicesList(argv, cmdr) |
| 35 | + } |
| 36 | + |
| 37 | + PrintUsage(cmdr) |
| 38 | + return nil |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +func servicesAdd(argv []string, cmdr cmd.Commander) error { |
| 43 | + usage := ` |
| 44 | +Creates extra service for an application and binds it to specific route of the main app domain |
| 45 | +
|
| 46 | +Usage: deis services:add --type <procfile_type> --route <path_pattern> [options] |
| 47 | +
|
| 48 | +Arguments: |
| 49 | + <procfile_type> |
| 50 | + Procfile type which should handle the request, e.g. webhooks (should be bind to the port PORT). |
| 51 | + Only single extra service per Porcfile type could be created |
| 52 | +
|
| 53 | + <path_pattern> |
| 54 | + Nginx locations where route requests, one or many via comma, |
| 55 | + e.g. /webhooks/notify |
| 56 | + OR "/webhooks/notify,~ ^/users/[0-9]+/.*/webhooks/notify,/webhooks/rest" |
| 57 | +
|
| 58 | +Options: |
| 59 | + -a --app=<app> |
| 60 | + the uniquely identifiable name for the application. |
| 61 | +` |
| 62 | + |
| 63 | + args, err := docopt.Parse(usage, argv, true, "", false, true) |
| 64 | + |
| 65 | + if err != nil { |
| 66 | + return err |
| 67 | + } |
| 68 | + |
| 69 | + app := safeGetValue(args, "--app") |
| 70 | + procfileType := safeGetValue(args, "<procfile_type>") |
| 71 | + pathPattern := safeGetValue(args, "<path_pattern>") |
| 72 | + |
| 73 | + return cmdr.ServicesAdd(app, procfileType, pathPattern) |
| 74 | +} |
| 75 | + |
| 76 | +func servicesList(argv []string, cmdr cmd.Commander) error { |
| 77 | + usage := ` |
| 78 | +Lists extra services for an application |
| 79 | +
|
| 80 | +Usage: deis services:list [options] |
| 81 | +
|
| 82 | +Options: |
| 83 | + -a --app=<app> |
| 84 | + the uniquely identifiable name for the application. |
| 85 | +` |
| 86 | + |
| 87 | + args, err := docopt.Parse(usage, argv, true, "", false, true) |
| 88 | + |
| 89 | + if err != nil { |
| 90 | + return err |
| 91 | + } |
| 92 | + |
| 93 | + app := safeGetValue(args, "--app") |
| 94 | + |
| 95 | + return cmdr.ServicesList(app) |
| 96 | +} |
| 97 | + |
| 98 | +func servicesRemove(argv []string, cmdr cmd.Commander) error { |
| 99 | + usage := ` |
| 100 | +Deletes specific extra service for application |
| 101 | +
|
| 102 | +Usage: deis services:remove <procfile_type> [options] |
| 103 | +
|
| 104 | +Arguments: |
| 105 | + <procfile_type> |
| 106 | + extra service for procfile type that should be removed |
| 107 | +
|
| 108 | +Options: |
| 109 | + -a --app=<app> |
| 110 | + the uniquely identifiable name for the application. |
| 111 | +` |
| 112 | + |
| 113 | + args, err := docopt.Parse(usage, argv, true, "", false, true) |
| 114 | + |
| 115 | + if err != nil { |
| 116 | + return err |
| 117 | + } |
| 118 | + |
| 119 | + app := safeGetValue(args, "--app") |
| 120 | + procfileType := safeGetValue(args, "<procfile_type>") |
| 121 | + |
| 122 | + return cmdr.ServicesRemove(app, procfileType) |
| 123 | +} |
0 commit comments