1
|
|
|
module Rapis |
2
|
|
|
class Cli < Thor |
3
|
|
|
class_option :file, aliases: '-f', desc: 'Configuration file', type: :string, default: 'Apifile' |
4
|
|
|
|
5
|
|
|
def self.start(*args) |
6
|
|
|
begin |
7
|
|
|
super(*args) |
8
|
|
|
rescue OperationError => e |
9
|
|
|
Rapis.logger.fatal(e.message) |
10
|
|
|
rescue => e |
11
|
|
|
Rapis.logger.error(e.message, e.backtrace) |
12
|
|
|
end |
13
|
|
|
end |
14
|
|
|
|
15
|
|
|
desc 'create', 'Create REST API' |
16
|
|
|
option :name, aliases: '-n', desc: 'Name', type: :string, required: true |
17
|
|
|
option :description, aliases: '-d', desc: 'Description', type: :string, default: nil |
18
|
|
|
def create |
19
|
|
|
actions.create(options) |
20
|
|
|
end |
21
|
|
|
|
22
|
|
|
desc 'convert', 'Convert the REST API configuration to the specified format' |
23
|
|
|
option :format, aliases: '-F', desc: 'Output format # accepts json, yaml', type: :string, required: true |
24
|
|
|
option :output, aliases: '-o', desc: 'Output path', type: :string, default: '' |
25
|
|
|
def convert |
26
|
|
|
actions.convert(options) |
27
|
|
|
end |
28
|
|
|
|
29
|
|
|
desc 'list', 'List the REST APIs and the stages' |
30
|
|
|
option :verbose, aliases: '-V', desc: 'Verbose mode', type: :boolean, default: false |
31
|
|
|
def list |
32
|
|
|
actions.list(options) |
33
|
|
|
end |
34
|
|
|
|
35
|
|
|
desc 'export', 'Export the configuration as Ruby DSL' |
36
|
|
|
option :rest_api, aliases: '-r', desc: 'The id of the REST API', type: :string, required: true |
37
|
|
|
option :stage, aliases: '-s', desc: 'The name of the stage', type: :string, required: true |
38
|
|
|
option :write, aliases: '-w', desc: 'Write the configuration to the file', type: :boolean, default: false |
39
|
|
|
def export |
40
|
|
|
actions.export(options) |
41
|
|
|
end |
42
|
|
|
|
43
|
|
|
desc 'diff', 'Diff the local configuration and the remote configuration' |
44
|
|
|
option :rest_api, aliases: '-r', desc: 'The id of the REST API', type: :string, required: true |
45
|
|
|
option :stage, aliases: '-s', desc: 'The name of the stage', type: :string, required: true |
46
|
|
|
def diff |
47
|
|
|
actions.diff(options) |
48
|
|
|
end |
49
|
|
|
|
50
|
|
|
desc 'apply', 'Apply the REST API configuration' |
51
|
|
|
option :rest_api, aliases: '-r', desc: 'The id of the REST API', type: :string, required: true |
52
|
|
|
def apply |
53
|
|
|
actions.apply(options) |
54
|
|
|
end |
55
|
|
|
|
56
|
|
|
desc 'deploy', 'Deploy the current REST API configuration to the stage' |
57
|
|
|
option :rest_api, aliases: '-r', desc: 'The id of the REST API', type: :string, required: true |
58
|
|
|
option :stage, aliases: '-s', desc: 'The name of the stage', type: :string, required: true |
59
|
|
|
option :description, aliases: '-d', desc: 'The description for the deployment', type: :string, default: '' |
60
|
|
|
option :stage_description, aliases: '-D', desc: 'The description of the stage', type: :string, default: '' |
61
|
|
|
option :cache, aliases: '-c', desc: 'Size of the cache cluster', type: :string, default: '0.0' |
62
|
|
|
option :variables, aliases: '-v', desc: 'A map that defines the stage variables', type: :hash, default: {} |
63
|
|
|
def deploy |
64
|
|
|
actions.deploy(options) |
65
|
|
|
end |
66
|
|
|
|
67
|
|
|
private |
68
|
|
|
|
69
|
|
|
def actions |
70
|
|
|
Rapis::Actions.new( |
71
|
|
|
Rapis::Client.new |
72
|
|
|
) |
73
|
|
|
end |
74
|
|
|
end |
75
|
|
|
end |
76
|
|
|
|