dawn-cli 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -3
  3. data/bin/dawni +15 -0
  4. data/lib/dawn/cli/commands.rb +9 -8
  5. data/lib/dawn/cli/commands/app.rb +35 -6
  6. data/lib/dawn/cli/commands/auth.rb +9 -7
  7. data/lib/dawn/cli/commands/base_commands.rb +31 -0
  8. data/lib/dawn/cli/commands/domain.rb +15 -5
  9. data/lib/dawn/cli/commands/drain.rb +15 -5
  10. data/lib/dawn/cli/commands/env.rb +25 -14
  11. data/lib/dawn/cli/commands/key.rb +20 -7
  12. data/lib/dawn/cli/commands/local.rb +13 -3
  13. data/lib/dawn/cli/commands/release.rb +6 -4
  14. data/lib/dawn/cli/helpers.rb +3 -5
  15. data/lib/dawn/cli/output_formatter.rb +15 -2
  16. data/lib/dawn/cli/parser.rb +58 -36
  17. data/lib/dawn/cli/version.rb +2 -2
  18. data/spec/api.log +45272 -0
  19. data/spec/cli/commands/app_spec.rb +71 -0
  20. data/spec/cli/commands/auth_spec.rb +13 -0
  21. data/spec/cli/commands/domain_spec.rb +25 -0
  22. data/spec/cli/commands/drain_spec.rb +25 -0
  23. data/spec/cli/commands/env_spec.rb +26 -0
  24. data/spec/cli/commands/key_spec.rb +30 -0
  25. data/spec/cli/commands/local_spec.rb +15 -0
  26. data/spec/cli/commands/release_spec.rb +19 -0
  27. data/spec/cli/parser_spec.rb +262 -0
  28. data/spec/cli_spec_helper.rb +13 -0
  29. data/spec/support/vcr.rb +11 -0
  30. data/spec/vcr/Dawn_CLI_App/_create/should_create_a_new_app_with_a_name.yml +51 -0
  31. data/spec/vcr/Dawn_CLI_App/_create/should_create_a_new_app_without_a_name.yml +51 -0
  32. data/spec/vcr/Dawn_CLI_App/_delete/should_delete_current_app.yml +98 -0
  33. data/spec/vcr/Dawn_CLI_App/_list/should_list_all_available_apps.yml +65 -0
  34. data/spec/vcr/Dawn_CLI_App/_list_gears/should_list_all_gears_for_current_app.yml +98 -0
  35. data/spec/vcr/Dawn_CLI_App/_logs/should_trail_the_current_app_s_logs.yml +98 -0
  36. data/spec/vcr/Dawn_CLI_App/_scale/should_modify_the_formation_for_the_current_app.yml +98 -0
  37. data/spec/vcr/Dawn_CLI_Auth/_login/should_login_using_proper_credentials.yml +48 -0
  38. data/spec/vcr/Dawn_CLI_Auth/_login/should_not_login_using_invalid_credentials.yml +46 -0
  39. data/spec/vcr/Dawn_CLI_Domain/_add/should_add_a_domain_to_the_current_app.yml +96 -0
  40. data/spec/vcr/Dawn_CLI_Domain/_delete/should_delete_a_domain_to_the_current_app.yml +97 -0
  41. data/spec/vcr/Dawn_CLI_Domain/_list/should_list_all_domains_for_current_app.yml +102 -0
  42. data/spec/vcr/Dawn_CLI_Drain/_add/should_add_a_drain_to_the_current_app.yml +359 -0
  43. data/spec/vcr/Dawn_CLI_Drain/_delete/should_remove_a_drain_from_current_app.yml +476 -0
  44. data/spec/vcr/Dawn_CLI_Drain/_list/should_list_all_drains_for_current_app.yml +98 -0
  45. data/spec/vcr/Dawn_CLI_Env/_get/should_retrieve_an_ENV_variable_given_a_key.yml +51 -0
  46. data/spec/vcr/Dawn_CLI_Env/_set/should_set_an_ENV_variable_given_a_Hash.yml +424 -0
  47. data/spec/vcr/Dawn_CLI_Env/_unset/should_remove_an_ENV_variable_given_a_key.yml +275 -0
  48. data/spec/vcr/Dawn_CLI_Key/_add/should_add_existing_id_rsa.yml +52 -0
  49. data/spec/vcr/Dawn_CLI_Key/_delete/should_delete_a_key_by_id.yml +101 -0
  50. data/spec/vcr/Dawn_CLI_Key/_get/should_retrieve_a_key_by_id.yml +102 -0
  51. data/spec/vcr/Dawn_CLI_Key/_list/should_list_all_keys_deployed.yml +53 -0
  52. data/spec/vcr/Dawn_CLI_Local/_health_check/should_verify_that_server_is_running.yml +50 -0
  53. data/spec/vcr/Dawn_CLI_Local/_whoami/should_print_current_user_to_console.yml +51 -0
  54. metadata +43 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5648f22bab9ddaf3fc4b15aa7d442e8cd14dde2d
4
- data.tar.gz: 755487a68afc3f624344ad1fcb171147cbe9b3eb
3
+ metadata.gz: fb88fe1d21465c414f7484e29a1ea5c0b5707fce
4
+ data.tar.gz: ab4c46253f6b16ee661d6e80502ffc075087fea3
5
5
  SHA512:
6
- metadata.gz: 32142f2d3d226bf03a43fc4b6fe6c3f73173d5a56a8a4c4df47eb20225c9d16ffd81e0d5d9909bb55a359e6313464c3a44cc22d7ac9e0047ea103e1571f0554f
7
- data.tar.gz: ee71bb731ff703315c787c644680359c53a6958aed662a3325990947346daf39746902c5100cced416d8ad332bb3508efca9c5ec79aa5c39de9a54e7d5218eed
6
+ metadata.gz: 3a0a7ddb400aa20f6e1159f6ddce03f2a337a7a435fa344b1b0a6f3d829a166047293d62d828cdb11dedbf5b71dd4a7a59323c6ac558082e9feb538016775552
7
+ data.tar.gz: 9bed41ab03f8752d942d738c8b52eda1e6fd8a5b2e6bfd0e8865f30223baef4a48c8dccf46f2c3e1c5e197fe067c80d4af1ebfd2fd79c36998f3feb5c61b345e
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  Dawn-CLI
2
2
  ========
3
- [link](https://github.com/dawn/dawn-cli)
4
-
5
3
  [![Dependency Status](https://gemnasium.com/dawn/dawn-cli.svg)](https://gemnasium.com/dawn/dawn-cli)
6
4
  [![Gem Version](https://badge.fury.io/rb/dawn-cli.svg)](http://badge.fury.io/rb/dawn-cli)
7
5
  [![Code Climate](https://codeclimate.com/github/dawn/dawn-cli.png)](https://codeclimate.com/github/dawn/dawn-cli)
8
6
 
9
- CLI for [Dawn](https://github.com/dawn/dawn)
7
+ [CLI](https://github.com/dawn/dawn-cli) for [Dawn](https://github.com/dawn/dawn)
10
8
 
11
9
  If you are looking for the ruby API
12
10
  [Dawn-API](https://github.com/dawn/dawn-api)
data/bin/dawni ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dawn/cli'
3
+
4
+ line_number = 1
5
+ loop do
6
+ print("~dawn %03d> " % line_number)
7
+ line = gets.chomp
8
+ argv = line.split(" ")
9
+ break if %w[quit exit].include?(argv.first)
10
+ begin
11
+ Dawn::CLI.run argv
12
+ rescue SystemExit # any form of abort
13
+ end
14
+ line_number += 1
15
+ end
@@ -1,8 +1,9 @@
1
- require 'dawn/cli/commands/auth' # Netrc setup and login command
2
- require 'dawn/cli/commands/app' # App management
3
- require 'dawn/cli/commands/drain' # App Drains management
4
- require 'dawn/cli/commands/env' # App ENV management
5
- require 'dawn/cli/commands/domain' # App Domains management
6
- require 'dawn/cli/commands/key' # Key management
7
- require 'dawn/cli/commands/local' # Various functions
8
- require 'dawn/cli/commands/release' # App Releases functions
1
+ require 'dawn/cli/commands/base_commands' #
2
+ require 'dawn/cli/commands/auth' # Netrc setup and login command
3
+ require 'dawn/cli/commands/app' # App management
4
+ require 'dawn/cli/commands/drain' # App Drains management
5
+ require 'dawn/cli/commands/env' # App ENV management
6
+ require 'dawn/cli/commands/domain' # App Domains management
7
+ require 'dawn/cli/commands/key' # Key management
8
+ require 'dawn/cli/commands/local' # Various functions
9
+ require 'dawn/cli/commands/release' # App Releases functions
@@ -1,12 +1,15 @@
1
- require "dawn/cli/helpers"
1
+ require "dawn/cli/commands/base_commands"
2
+ require "json"
2
3
 
3
4
  module Dawn
4
5
  module CLI
5
6
  module App
7
+ extend Dawn::CLI::BaseCommands
6
8
 
7
- extend Dawn::CLI::Helpers
8
-
9
+ ###
9
10
  # "Create a new dawn App (with git; setup)"
11
+ # @param [String] appname
12
+ ###
10
13
  def self.create(appname=nil)
11
14
  app = try_create_app appname
12
15
  # since its possible for dawn to create a new app, with a random name
@@ -16,12 +19,18 @@ module Dawn
16
19
  say "\tAPP\t#{app.name}"
17
20
  end
18
21
 
22
+ ###
19
23
  # "Displays a list of all the apps you have deployed to dawn"
24
+ ###
20
25
  def self.list
21
26
  say format_apps(Dawn::App.all)
22
27
  end
23
28
 
29
+ ###
24
30
  # "Modify the gears of the current app"
31
+ # @param [Hash<String, Array[String, Integer]>] modifiers
32
+ # EG. { "web" => ["+", 1] }
33
+ ###
25
34
  def self.scale(modifiers)
26
35
  app = current_app
27
36
 
@@ -43,7 +52,9 @@ module Dawn
43
52
  app.scale(app: { formation: formation })
44
53
  end
45
54
 
55
+ ###
46
56
  # "Deletes the app on dawn"
57
+ ###
47
58
  def self.delete
48
59
  app = current_app
49
60
 
@@ -51,19 +62,23 @@ module Dawn
51
62
  git_remove_dawn_remote app
52
63
  end
53
64
 
65
+ ###
54
66
  # "Prints the App's log to STDOUT"
55
- def self.logs(follow=false)
67
+ # @param [Array<String>] filters
68
+ # @param [Boolean] follow
69
+ ###
70
+ def self.logs(filters, follow=false)
56
71
  # this is the only method which requires the uri & net/http
57
72
  require 'uri'
58
73
  require 'net/http'
59
74
 
75
+ app = current_app
76
+
60
77
  filter_regex = %r{\A(?<timestamp>\S+)\s(?<token>\S+)\[(?<proc_id>\S+)\]\:(?<message>.*)}
61
78
  timestamp_regex = %r{(?<year>\d+)-(?<month>\d+)-(?<day>\d+)T(?<hour>\d+)\:(?<minute>\d+)\:(?<second>\d+)\.(?<other>.*)}
62
79
 
63
80
  opts = {}
64
81
  opts[:tail] = follow
65
- filters = args
66
- app = current_app
67
82
  url = app.logs(opts)
68
83
  uri = URI.parse(url)
69
84
 
@@ -97,7 +112,9 @@ module Dawn
97
112
  end
98
113
  end
99
114
 
115
+ ###
100
116
  # "Lists all currently running Gears"
117
+ ###
101
118
  def self.list_gears
102
119
  app = current_app
103
120
  gears = app.gears.all.sort_by(&:number)
@@ -113,10 +130,22 @@ module Dawn
113
130
  end
114
131
  end
115
132
 
133
+ ###
134
+ # "Restart the current app"
135
+ ###
116
136
  def self.restart
117
137
  current_app.restart
118
138
  end
119
139
 
140
+ ###
141
+ # "run a command in the current_app"
142
+ # @param [Array<String>] argv
143
+ ###
144
+ def self.run(argv)
145
+ current_app.run(command: argv.join(" "))
146
+ rescue Excon::Errors::BadRequest => ex
147
+ handle_abort_exception("dawn run", ex)
148
+ end
120
149
  end
121
150
  end
122
151
  end
@@ -1,19 +1,21 @@
1
- require "dawn/cli/helpers"
1
+ require "dawn/cli/commands/base_commands"
2
2
 
3
3
  module Dawn
4
4
  module CLI
5
5
  module Auth
6
+ extend Dawn::CLI::BaseCommands
6
7
 
7
- extend Dawn::CLI::Helpers
8
-
8
+ ###
9
9
  # "save login details to .netrc"
10
- # usn = ask "Username: "
11
- # psw = password "Password: "
10
+ # @param [String] username
11
+ # @param [String] password
12
+ ###
12
13
  def self.login(username, password)
13
14
  Dawn.authenticate(username: username, password: password)
14
- say " ! login details have been saved to your .netrc"
15
+ say "\tLOGIN details have been saved to your ~/.netrc"
16
+ rescue Excon::Errors::BadRequest
17
+ abort "dawn login: Login has failed, check your username and password"
15
18
  end
16
-
17
19
  end
18
20
  end
19
21
  end
@@ -0,0 +1,31 @@
1
+ require "dawn/cli/helpers"
2
+
3
+ module Dawn
4
+ module CLI
5
+ module BaseCommands
6
+ include Dawn::CLI::Helpers
7
+
8
+ ###
9
+ # @param [Symbol] sym
10
+ # @param [Array<Objects>] *args
11
+ ###
12
+ def command(sym, *args, &block)
13
+ if Dawn::CLI.no_operation
14
+ say "#{self}.#{sym}(#{args.map(&:inspect).join(", ")})"
15
+ else
16
+ send(sym, *args, &block)
17
+ end
18
+ sym
19
+ end
20
+
21
+ def handle_abort_exception(basename, ex)
22
+ error_obj = JSON.load(ex.response.body) rescue nil
23
+ if error_obj
24
+ abort "#{basename}: (#{error_obj["id"]}) #{error_obj["message"]} #{error_obj["error"]}"
25
+ else
26
+ abort "#{basename}: has failed for some unknown reason"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,26 +1,36 @@
1
- require "dawn/cli/helpers"
1
+ require "dawn/cli/commands/base_commands"
2
2
 
3
3
  module Dawn
4
4
  module CLI
5
5
  module Domain
6
+ extend Dawn::CLI::BaseCommands
6
7
 
7
- extend Dawn::CLI::Helpers
8
-
8
+ ###
9
9
  # "List all domains for the current app"
10
+ ###
10
11
  def self.list
11
12
  say format_domains(current_app.domains.all)
12
13
  end
13
14
 
15
+ ###
14
16
  # "Add a new domain to the current app"
17
+ # @param [String] url
18
+ ###
15
19
  def self.add(url)
16
20
  current_app.domains.create(domain: { url: url })
21
+ rescue Excon::Errors::Conflict => ex
22
+ handle_abort_exception("dawn domain add", ex)
17
23
  end
18
24
 
25
+ ###
19
26
  # "Remove an existing domain from the current app"
27
+ # @param [String] url
28
+ ###
20
29
  def self.delete(url)
21
- current_app.domains.delete(url: url)
30
+ current_app.domains.destroy(url: url)
31
+ rescue Excon::Errors::NotFound => ex
32
+ handle_abort_exception("dawn domain delete", ex)
22
33
  end
23
-
24
34
  end
25
35
  end
26
36
  end
@@ -1,26 +1,36 @@
1
- require "dawn/cli/helpers"
1
+ require "dawn/cli/commands/base_commands"
2
2
 
3
3
  module Dawn
4
4
  module CLI
5
5
  module Drain
6
+ extend Dawn::CLI::BaseCommands
6
7
 
7
- extend Dawn::CLI::Helpers
8
-
8
+ ###
9
9
  # "List all drains for the current app"
10
+ ###
10
11
  def self.list
11
12
  say format_drains(current_app.drains.all)
12
13
  end
13
14
 
15
+ ###
14
16
  # "Add a new drain to the current app"
17
+ # @param [String] url
18
+ ###
15
19
  def self.add(url)
16
20
  current_app.drains.create(drain: { url: url })
21
+ rescue Excon::Errors::Conflict => ex
22
+ handle_abort_exception("dawn drain add", ex)
17
23
  end
18
24
 
25
+ ###
19
26
  # "Remove an existing drain from the current app"
27
+ # @param [String] url
28
+ ###
20
29
  def self.delete(url)
21
- current_app.drains.delete(url: url)
30
+ current_app.drains.destroy(url: url)
31
+ rescue Excon::Errors::NotFound => ex
32
+ handle_abort_exception("dawn drain delete", ex)
22
33
  end
23
-
24
34
  end
25
35
  end
26
36
  end
@@ -1,43 +1,54 @@
1
- require "dawn/cli/helpers"
1
+ require "dawn/cli/commands/base_commands"
2
2
 
3
3
  module Dawn
4
4
  module CLI
5
5
  module Env
6
+ extend Dawn::CLI::BaseCommands
6
7
 
7
- extend Dawn::CLI::Helpers
8
-
9
- # displays all the current app's ENV variables
8
+ ###
9
+ # "Displays all the current app's ENV variables"
10
+ ###
10
11
  def self.list
11
12
  current_app.env.each do |k, v|
12
13
  say "#{k}=#{v}"
13
14
  end
14
15
  end
15
16
 
17
+ ###
16
18
  # "Get an ENV var"
19
+ ###
17
20
  def self.get(*keys)
18
- app = current_app
19
- env = app.env
21
+ env = current_app.env
20
22
  keys.each do |k|
21
23
  say "#{k}=#{env[k]}"
22
24
  end
23
25
  end
24
26
 
27
+ ###
25
28
  # "Set multiple ENV variables"
26
- def self.set(hash)
27
- app = current_app
28
- app.env.update(app.env.merge(hash)) # this is a Hash method
29
- app.env.save # this is a API method
29
+ # @param [Hash<String, String>] env
30
+ ###
31
+ def self.set(env)
32
+ appenv = current_app.env
33
+ appenv.update(appenv.merge(env)) # this is a Hash method
34
+ appenv.save # this is an API method
35
+ rescue Excon::Errors::BadRequest => ex
36
+ handle_abort_exception("dawn env set", ex)
30
37
  end
31
38
 
39
+ ###
32
40
  # "Deletes an ENV var"
41
+ # @param [Array<String>] *keys
42
+ ###
33
43
  def self.unset(*keys)
34
- app = current_app
44
+ env = current_app.env
35
45
  keys.each do |k|
36
- app.env.delete(k)
46
+ env.delete(k)
37
47
  end
38
- app.env.save
48
+ env.save
49
+ rescue Excon::Errors::BadRequest => ex
50
+ handle_abort_exception("dawn env unset", ex)
39
51
  end
40
-
41
52
  end
42
53
  end
43
54
  end
@@ -1,34 +1,47 @@
1
- require "dawn/cli/helpers"
1
+ require "dawn/cli/commands/base_commands"
2
2
 
3
3
  module Dawn
4
4
  module CLI
5
5
  module Key
6
+ extend Dawn::CLI::BaseCommands
6
7
 
7
- extend Dawn::CLI::Helpers
8
-
8
+ ###
9
9
  # "Lists all your Keys currently on dawn"
10
+ ###
10
11
  def self.list
11
12
  say format_keys(Dawn::Key.all)
12
13
  end
13
14
 
15
+ ###
14
16
  # "Adds this machine's sshkey to Dawn"
17
+ ###
15
18
  def self.add
16
19
  filename = File.join(Dir.home, ".ssh/id_rsa.pub")
17
20
  pubkey = File.read filename
18
21
  key = Dawn::Key.create(key: pubkey)
22
+ rescue Excon::Errors::UnprocessableEntity => ex
23
+ handle_abort_exception("dawn key add", ex)
19
24
  end
20
25
 
26
+ ###
21
27
  # "Retrieve a Key by ID"
28
+ # @param [String] id
29
+ ###
22
30
  def self.get(id)
23
- key = Dawn::Key.find(id: id)
24
- say format_keys([key])
31
+ say Dawn::Key.find(id: id).key
32
+ rescue Excon::Errors::NotFound => ex
33
+ handle_abort_exception("dawn key get", ex)
25
34
  end
26
35
 
36
+ ###
27
37
  # "Delete a Key by ID"
28
- def self.delete
38
+ # @param [String] id
39
+ ###
40
+ def self.delete(id)
29
41
  Dawn::Key.destroy(id: id)
42
+ rescue Excon::Errors::NotFound => ex
43
+ handle_abort_exception("dawn key delete", ex)
30
44
  end
31
-
32
45
  end
33
46
  end
34
47
  end
@@ -1,15 +1,25 @@
1
- require "dawn/cli/helpers"
1
+ require "dawn/cli/commands/base_commands"
2
2
 
3
3
  module Dawn
4
4
  module CLI
5
5
  module Local
6
+ extend Dawn::CLI::BaseCommands
6
7
 
7
- extend Dawn::CLI::Helpers
8
-
8
+ ###
9
+ # "verify if server is running"
10
+ ###
9
11
  def self.health_check
10
12
  Dawn::API.health_check
13
+ say "All is well"
11
14
  end
12
15
 
16
+ ###
17
+ # "print current username to console"
18
+ ###
19
+ def self.whoami
20
+ account = Dawn::Account.current
21
+ say account.username
22
+ end
13
23
  end
14
24
  end
15
25
  end