Module: Dawn::CLI
- Defined in:
- lib/dawn/cli/parser.rb,
lib/dawn/cli/helpers.rb,
lib/dawn/cli/version.rb,
lib/dawn/cli/commands/app.rb,
lib/dawn/cli/commands/env.rb,
lib/dawn/cli/commands/key.rb,
lib/dawn/cli/commands/auth.rb,
lib/dawn/cli/commands/drain.rb,
lib/dawn/cli/commands/local.rb,
lib/dawn/cli/commands/domain.rb,
lib/dawn/cli/commands/release.rb,
lib/dawn/cli/output_formatter.rb
Defined Under Namespace
Modules: App, Auth, Domain, Drain, Env, Helpers, Key, Local, OutputFormatter, Release, Version
Constant Summary
collapse
- DOC_TOP =
%Q(usage: dawn [-a APPNAME] [-h] [<command>] [<argv>...]
Options:
-a APPNAME, --app=APPNAME specify app.
-h, --help display help.
--version print version.
Commands:
create [<name>] initialize a new app in this the wd.
ls print all deployed apps.
ps print all running gears for current app.
login setup your netrc login details for dawn.
logs [-f]
-f, --follow follow logs.
app App control command.
domain Domain control command.
drain Drain control command.
env ENV control command.
key Key control command.
release Release control command.
run run command on current app.
)
- DOC_SUBCOMMAND =
{}
- VERSION =
Version::STRING
- @@selected_app =
nil
Class Method Summary
collapse
Class Method Details
.not_a_command(basename, command) ⇒ Object
150
151
152
153
|
# File 'lib/dawn/cli/parser.rb', line 150
def self.not_a_command(basename, command)
abort "#{basename}: '#{command}' is not a #{basename} command. See '#{basename} --help'."
end
|
.run(argv) ⇒ Object
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'lib/dawn/cli/parser.rb', line 260
def self.run(argv)
result = Docopt.docopt(DOC_TOP, argv: argv,
version: Dawn::CLI::VERSION, help: false)
command = result["<command>"]
unless command
result = Docopt.docopt(DOC_TOP, argv: argv,
version: Dawn::CLI::VERSION, help: true)
end
self.selected_app = result["--app"]
case command
when "create"
Dawn::CLI::App.create command_argv.first
when "ls"
Dawn::CLI::App.list
when "ps"
Dawn::CLI::App.list_gears
when "login"
username = ask("Username: ")
password = ask("Password: ") { |q| q.echo = false }
Dawn::CLI::Auth.login username, password
when "logs"
Dawn::CLI::App.logs
when *DOC_SUBCOMMAND.keys
run_subcommand(command, argv)
else
not_a_command("dawn", command)
end
rescue Docopt::Exit => ex
abort ex.message
end
|
.run_app_command(options) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/dawn/cli/parser.rb', line 159
def self.run_app_command(options)
if options["delete"]
Dawn::CLI::App.delete
elsif options["restart"]
Dawn::CLI::App.restart
elsif options["scale"]
data = options["<gear_modifier>"].inject({}) do |str, hash|
if str =~ /(\S+)([+-=])(\d+)/
hash[$1] = [$2, $3.to_i]
end
end
Dawn::CLI::App.scale(data)
else
Dawn::CLI::App.list
end
end
|
.run_domain_command(options) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/dawn/cli/parser.rb', line 176
def self.run_domain_command(options)
if options["add"]
url = options["<url>"]
Dawn::CLI::Domain.add(url)
elsif options["delete"]
url = options["<url>"]
Dawn::CLI::Domain.delete(url)
else
Dawn::CLI::Domain.list
end
end
|
.run_drain_command(options) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/dawn/cli/parser.rb', line 188
def self.run_drain_command(options)
if options["add"]
url = options["<url>"]
Dawn::CLI::Drain.add(url)
elsif options["delete"]
url = options["<url>"]
Dawn::CLI::Drain.delete(url)
else
Dawn::CLI::Drain.list
end
end
|
.run_env_command(options) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/dawn/cli/parser.rb', line 200
def self.run_env_command(options)
if options["get"]
keys = options["<key_name>"]
Dawn::CLI::Env.get(*keys)
elsif options["set"]
data = options["<argv>"].each_with_object({}) do |str, hash|
if str =~ /(\S+)=(.*)/
key, value = $1, $2
hash[key] = value
end
end
Dawn::CLI::Env.set(data)
elsif options["unset"]
keys = options["<key_name>"]
Dawn::CLI::Env.unset(*keys)
else
Dawn::CLI::Env.list
end
end
|
.run_key_command(options) ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/dawn/cli/parser.rb', line 220
def self.run_key_command(options)
if options["add"]
Dawn::CLI::Key.add
elsif options["get"]
id = options["<id>"].first
Dawn::CLI::Key.get(id)
elsif options["delete"]
id = options["<id>"].first
Dawn::CLI::Key.delete(id)
else
Dawn::CLI::Key.list
end
end
|
.run_release_command(options) ⇒ Object
234
235
236
237
238
239
240
241
|
# File 'lib/dawn/cli/parser.rb', line 234
def self.run_release_command(options)
if options["add"]
Dawn::CLI::Release.add
else
Dawn::CLI::Release.list
not_a_command("dawn release", command)
end
end
|
.run_subcommand(command, argv) ⇒ Object
247
248
249
250
251
252
253
254
255
|
# File 'lib/dawn/cli/parser.rb', line 247
def self.run_subcommand(command, argv)
if argv.empty?
subcommand = ""
else
result = Docopt.docopt(DOC_SUBCOMMAND[command], argv: argv,
version: Dawn::CLI::VERSION, help: true)
end
send("run_#{command}_command", result)
end
|
.selected_app ⇒ String
136
137
138
|
# File 'lib/dawn/cli/parser.rb', line 136
def self.selected_app
@@selected_app
end
|
.selected_app=(appname) ⇒ Object
143
144
145
|
# File 'lib/dawn/cli/parser.rb', line 143
def self.selected_app=(appname)
@@selected_app = appname
end
|