dawn-cli 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d84982fb0b5183bfa3934340f5bab8083a68cb0
4
- data.tar.gz: 3047933667d1f0fb125c23d4ed2f81df17983c44
3
+ metadata.gz: 8c69df2b06d2b520437bb91ae452de45c88693ce
4
+ data.tar.gz: cbc1a3bd916fc0aab3651867f8b2ddf797142c11
5
5
  SHA512:
6
- metadata.gz: 80bb11d6044735d1499cdf033b4f3d0cd4ded45b103b5bf6dd7488f1554cb25452685fd430c6a6c17cc66af1b0e24cfbf1ae57e094ab875fa075248930867c7e
7
- data.tar.gz: ac198cc5ce1c5211e46b318c4fdbe188ad11834fc3bbbcaf78b85272486d575d4e641e8f5194d6c57a816aeddbe053adffcaa032474bbcf64ab0ab573f736e6f
6
+ metadata.gz: 11d3f2f1ddd10804df98ab8f571a3f36de4369bc101bccc3c8619b6931eb65f21abe7e5563c79d5c48f8af195f2b0ebd0ea984c6388729ff46578c34d3b058f8
7
+ data.tar.gz: b1c12805372cca918d79124a7de6f66f44dc1a66c516143ce8d5a12fa125105e6cc4e61d9b0bd182879292854c48e2c345da8bbe23474e7f08bf71e06f3ec79c
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ Overview
2
+ ========
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ Dawn-CLI
2
+ ========
3
+ [link](https://github.com/dawn/dawn-cli)
4
+
5
+ [![Dependency Status](https://gemnasium.com/dawn/dawn-cli.svg)](https://gemnasium.com/dawn/dawn-cli)
6
+ [![Gem Version](https://badge.fury.io/rb/dawn-cli.svg)](http://badge.fury.io/rb/dawn-cli)
7
+ [![Code Climate](https://codeclimate.com/github/dawn/dawn-cli.png)](https://codeclimate.com/github/dawn/dawn-cli)
8
+
9
+ CLI for [Dawn](https://github.com/dawn/dawn)
10
+
11
+ If you are looking for the ruby API
12
+ [Dawn-API](https://github.com/dawn/dawn-api)
13
+
14
+ ## Installation
15
+ ```shell
16
+ gem install dawn-cli
17
+ ```
18
+
19
+ ## Building
20
+ ```shell
21
+ gem pack dawn-cli.gem
22
+ ```
23
+
24
+ ## Usage
25
+ ```shell
26
+ dawn
27
+ ```
28
+ Help is printed if no commands are given.
29
+
30
+ ## ENV Variables
31
+ [ENV(s)](https://github.com/dawn/dawn-api#influential-env-variable)
data/bin/dawn CHANGED
@@ -1,8 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require 'commander'
3
- require 'commander/import'
4
- require 'dawn/cli/version'
5
-
6
2
  require 'dawn/cli'
7
-
8
- Dawn::CLI::Application.new.run
3
+ Dawn::CLI.run ARGV.dup
@@ -1,174 +1,112 @@
1
- module Dawn
2
- module CLI
3
- class Application
4
- def app_commands
5
-
6
- command "app:ls" do |c|
7
- c.syntax = "dawn app:ls"
8
- c.description = "Displays a list of all the apps you have deployed to dawn"
9
-
10
- c.action do |args, options|
11
- apps = Dawn::App.all
12
- say format_apps(apps)
13
- end
14
- end
15
- alias_command "ls", "app:ls"
1
+ require "dawn/cli/helpers"
16
2
 
17
- command "app:scale" do |c|
18
- c.syntax = "dawn app:scale <gear_modifier>"
19
- c.description = "Modify the gears of the current app"
3
+ module Dawn
4
+ module CLI
5
+ module App
20
6
 
21
- c.action do |args, options|
22
- app = current_app
23
- formation = {}
7
+ extend Dawn::CLI::Helpers
24
8
 
25
- args.each do |s|
26
- mtch_data = s.match(/(?<type>\S+)(?<op>[+-=])(?<value>\d+)/)
27
- next unless mtch_data
9
+ # "Displays a list of all the apps you have deployed to dawn"
10
+ def self.list
11
+ say format_apps(Dawn::App.all)
12
+ end
28
13
 
29
- type = mtch_data[:type]
30
- value = mtch_data[:value].to_i
31
- old_formation = (app.formation[type] || 0).to_i
14
+ # "Modify the gears of the current app"
15
+ def self.scale(modifiers)
16
+ app = current_app
32
17
 
33
- formation[type] = case mtch_data[:op]
34
- when "+" then old_formation + value
35
- when "-" then old_formation - value
36
- when "=" then value
37
- end
38
- end
39
- app.scale formation: formation
40
- end
41
- end
18
+ #formation = app.formation.dup
19
+ formation = {}
42
20
 
43
- command "app:delete" do |c|
44
- c.syntax = "dawn app:delete [<app_id>]"
45
- c.description = "Delete App app_id, if no app_id is provided, the current app is deleted instead"
21
+ modifiers.each do |type, a|
22
+ operator, value = *a
46
23
 
47
- c.option "--name APPNAME", String, "specify an app by name to remove"
24
+ old_formation = (app.formation[type] || 0).to_i
48
25
 
49
- c.action do |args, options|
50
- if app_id = args.first
51
- app = Dawn::App.find(id: app_id)
52
- elsif app_name = options.name
53
- app = Dawn::App.find(name: app_name)
54
- else
55
- app = current_app
56
- end
26
+ formation[type] = case operator
27
+ when "+" then old_formation + value.to_i
28
+ when "-" then old_formation - value.to_i
29
+ when "=" then value.to_i
30
+ end
31
+ end
57
32
 
58
- app_name = app.name
59
- app.destroy
33
+ app.scale(app: { formation: formation })
34
+ end
60
35
 
61
- git_remove_dawn_remote app
62
- end
63
- end
36
+ # "Deletes the app on dawn"
37
+ def self.delete
38
+ app = current_app
64
39
 
65
- command "app:rename" do |c|
66
- c.syntax = "dawn rename <new_name>"
67
- c.description = "Rename the current App to <new_name>"
40
+ app.destroy
41
+ git_remove_dawn_remote app
42
+ end
68
43
 
69
- c.action do |args, options|
70
- app_name = args.first
71
- app = current_app
72
- app.update name: app_name
73
- end
74
- end
75
- alias_command "rename", "app:rename"
76
-
77
- command "app:logs" do |c|
78
- c.syntax = "dawn logs [-f]"
79
- c.description = "Prints the App's log to STDOUT"
80
-
81
- c.option "-f", "should the logs be followed?"
82
-
83
- c.action do |args, options|
84
- filter_regex = %r{\A(?<timestamp>\S+)\s(?<token>\S+)\[(?<proc_id>\S+)\]\:(?<message>.*)}
85
- timestamp_regex = %r{(?<year>\d+)-(?<month>\d+)-(?<day>\d+)T(?<hour>\d+)\:(?<minute>\d+)\:(?<second>\d+)\.(?<other>.*)}
86
-
87
- opts = {}
88
- opts[:tail] = options.f
89
- filters = args
90
- app = current_app
91
- url = app.logs(opts)
92
- uri = URI.parse(url)
93
-
94
- begin
95
- http = Net::HTTP.new(uri.host, uri.port)
96
- http.read_timeout = 60 * 60 * 24
97
- begin
98
- http.start do
99
- link_url = uri.path + ("?srv=1")
100
- #say uri.host + ":" + uri.port.to_s + link_url
101
- http.request_get(link_url) do |request|
102
- request.read_body do |chunk|
103
- if filters.size > 0
104
- chunk.each_line do |line|
105
- if mtch_data = line.chomp.match(filter_regex)
106
- say mtch_data[0] if filters.include?(mtch_data[:proc_id])
44
+ # "Prints the App's log to STDOUT"
45
+ def self.logs(follow=false)
46
+ # this is the only method which requires the uri & net/http
47
+ require 'uri'
48
+ require 'net/http'
49
+
50
+ filter_regex = %r{\A(?<timestamp>\S+)\s(?<token>\S+)\[(?<proc_id>\S+)\]\:(?<message>.*)}
51
+ timestamp_regex = %r{(?<year>\d+)-(?<month>\d+)-(?<day>\d+)T(?<hour>\d+)\:(?<minute>\d+)\:(?<second>\d+)\.(?<other>.*)}
52
+
53
+ opts = {}
54
+ opts[:tail] = follow
55
+ filters = args
56
+ app = current_app
57
+ url = app.logs(opts)
58
+ uri = URI.parse(url)
59
+
60
+ begin
61
+ http = Net::HTTP.new(uri.host, uri.port)
62
+ http.read_timeout = 60 * 60 * 24
63
+ begin
64
+ http.start do
65
+ link_url = uri.path + ("?srv=1")
66
+ #say uri.host + ":" + uri.port.to_s + link_url
67
+ http.request_get(link_url) do |request|
68
+ request.read_body do |chunk|
69
+ if filters.size > 0
70
+ chunk.each_line do |line|
71
+ if mtch_data = line.chomp.match(filter_regex)
72
+ say mtch_data[0] if filters.include?(mtch_data[:proc_id])
73
+ end
74
+ end
75
+ else
76
+ say chunk.to_s
107
77
  end
108
78
  end
109
- else
110
- say chunk.to_s
111
79
  end
112
80
  end
81
+ rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError
82
+ raise "Could not connect to logging service"
83
+ rescue Timeout::Error, EOFError
84
+ raise "\nRequest timed out"
113
85
  end
86
+ rescue Interrupt
114
87
  end
115
- rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError
116
- raise "Could not connect to logging service"
117
- rescue Timeout::Error, EOFError
118
- raise "\nRequest timed out"
119
88
  end
120
- rescue Interrupt
121
- end
122
- end
123
- end
124
- alias_command "logs", "app:logs"
125
89
 
126
- command "app:gears" do |c|
127
- c.syntax = "dawn ps [<gear_name>]"
128
- c.description = "Lists all currently running Gears"
90
+ # "Lists all currently running Gears"
91
+ def self.list_gears
92
+ app = current_app
93
+ gears = app.gears.all.sort_by(&:number)
129
94
 
130
- c.action do |args, options|
131
- app = current_app
132
- gears = app.gears.all.sort_by(&:number)
133
-
134
- if args.empty?
135
- ## Print all Gears
136
- gears_by_type = gears.each_with_object({}) do |gear, hsh|
137
- (hsh[gear.type] ||= []) << gear
138
- end
139
- gears_by_type.keys.sort.each do |key|
140
- grs = gears_by_type[key]
141
- say "=== #{key}:"
142
- say format_gears grs
143
- end
144
- else
145
- ## Print a specific gear
146
- query = args.first
147
- gear = gears.find { |gear| gear.name == query }
148
-
149
- if gear
150
- say format_gears([gear])
151
- else
152
- say "Gear #{query} was not found."
95
+ ## Print all Gears
96
+ gears_by_type = gears.each_with_object({}) do |gear, hsh|
97
+ (hsh[gear.type] ||= []) << gear
98
+ end
99
+ gears_by_type.keys.sort.each do |key|
100
+ grs = gears_by_type[key]
101
+ say "=== #{key}:"
102
+ say format_gears grs
103
+ end
153
104
  end
154
- end
155
- end
156
- end
157
- alias_command "ps", "app:gears"
158
105
 
159
- command "app:restart" do |c|
160
- c.syntax = "dawn restart"
161
- c.description = "Restart the current App"
106
+ def self.restart
107
+ current_app.restart
108
+ end
162
109
 
163
- c.action do |args, options|
164
- app = current_app
165
- app.restart
166
- say "App #{app.name} has been restarted"
110
+ end
167
111
  end
168
112
  end
169
- alias_command "restart", "app:restart"
170
-
171
- end
172
- end
173
- end
174
- end
@@ -0,0 +1,19 @@
1
+ require "dawn/cli/helpers"
2
+
3
+ module Dawn
4
+ module CLI
5
+ module Auth
6
+
7
+ extend Dawn::CLI::Helpers
8
+
9
+ # "save login details to .netrc"
10
+ # usn = ask "Username: "
11
+ # psw = password "Password: "
12
+ def self.login(username, password)
13
+ Dawn.authenticate(username: username, password: password)
14
+ say " ! login details have been saved to your .netrc"
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -1,49 +1,26 @@
1
- module Dawn
2
- module CLI
3
- class Application
4
- def domain_commands
1
+ require "dawn/cli/helpers"
5
2
 
6
- command "domain:add" do |c|
7
- c.syntax = "dawn domain:add <url>"
8
- c.description = "Add a new domain to the current app"
3
+ module Dawn
4
+ module CLI
5
+ module Domain
9
6
 
10
- c.action do |args, options|
11
- url = args.first
12
- app = current_app
7
+ extend Dawn::CLI::Helpers
13
8
 
14
- app.domains.create url: url
15
- end
16
- end
9
+ # "List all domains for the current app"
10
+ def self.list
11
+ say format_domains(current_app.domains.all)
12
+ end
17
13
 
18
- command "domain:delete" do |c|
19
- c.syntax = "dawn domain:delete <url>"
20
- c.description = "Remove an existing domain from the current app"
14
+ # "Add a new domain to the current app"
15
+ def self.add(url)
16
+ current_app.domains.create(domain: { url: url })
17
+ end
21
18
 
22
- c.action do |args, options|
23
- url = args.first
24
- app = current_app
19
+ # "Remove an existing domain from the current app"
20
+ def self.delete(url)
21
+ current_app.domains.delete(url: url)
22
+ end
25
23
 
26
- domain = app.domains.all.find { |domain| domain.url == url }
27
- if domain
28
- domain.destroy
29
- else
30
- say "Domain (url: #{url}) could not be found"
31
24
  end
32
25
  end
33
26
  end
34
-
35
- command "domain:ls" do |c|
36
- c.syntax = "dawn domain:ls"
37
- c.description = "List all domains for the current app"
38
-
39
- c.action do |args, options|
40
- app = current_app
41
-
42
- say format_domains(app.domains.all)
43
- end
44
- end
45
-
46
- end
47
- end
48
- end
49
- end
@@ -1,50 +1,26 @@
1
- module Dawn
2
- module CLI
3
- class Application
4
- def drain_commands
1
+ require "dawn/cli/helpers"
5
2
 
6
- command "drain:add" do |c|
7
- c.syntax = "dawn drain:add <url>"
8
- c.description = "Add a Drain url"
3
+ module Dawn
4
+ module CLI
5
+ module Drain
9
6
 
10
- c.action do |args, options|
11
- url = args.first
12
- app = current_app
7
+ extend Dawn::CLI::Helpers
13
8
 
14
- drain = app.drains.create url: url
15
- end
16
- end
9
+ # "List all drains for the current app"
10
+ def self.list
11
+ say format_drains(current_app.drains.all)
12
+ end
17
13
 
18
- command "drain:delete" do |c|
19
- c.syntax = "dawn drain:delete <url>"
20
- c.description = "Remove a Drain url"
14
+ # "Add a new drain to the current app"
15
+ def self.add(url)
16
+ current_app.drains.create(drain: { url: url })
17
+ end
21
18
 
22
- c.action do |args, options|
23
- url = args.first
24
- app = current_app
19
+ # "Remove an existing drain from the current app"
20
+ def self.delete(url)
21
+ current_app.drains.delete(url: url)
22
+ end
25
23
 
26
- drain = app.drains.all.find { |drain| drain.url == url }
27
- if drain
28
- drain.destroy
29
- else
30
- say "Drain (url: #{url}) could not be found"
31
24
  end
32
25
  end
33
26
  end
34
-
35
- command "drain:ls" do |c|
36
- c.syntax = "dawn drain:ls"
37
- c.description = "Lists all Drains for this App"
38
-
39
- c.action do |args, options|
40
- url = args.first
41
- app = current_app
42
- drains = app.drains.all
43
- say format_drains(drains)
44
- end
45
- end
46
-
47
- end
48
- end
49
- end
50
- end
@@ -1,62 +1,43 @@
1
- module Dawn
2
- module CLI
3
- class Application
4
- def env_commands
5
-
6
- command "env:set" do |c|
7
- c.syntax = "dawn env:set [<key_name=value>..]"
8
- c.description = "Set multiple ENV variables"
1
+ require "dawn/cli/helpers"
9
2
 
10
- c.action do |args, options|
11
- env = current_app.env
12
- vars = args.each_with_object({}) do |arg, hsh|
13
- key, value = arg.split("=", 2)
14
- hsh[key] = value
15
- end
16
- env.update(vars)
17
- env.save
18
- say "App ENV has been updated"
19
- end
20
- end
3
+ module Dawn
4
+ module CLI
5
+ module Env
21
6
 
22
- command "env:get" do |c|
23
- c.syntax = "dawn env:get [<key_name> ..]"
24
- c.description = "Get an ENV var, if none is given prints all the variables"
7
+ extend Dawn::CLI::Helpers
25
8
 
26
- c.action do |args, options|
27
- env = current_app.env
28
- if args.empty?
29
- env.each do |key, value|
30
- say "#{key}: #{value}"
9
+ # displays all the current app's ENV variables
10
+ def self.list
11
+ current_app.env.each do |k, v|
12
+ say "#{k}=#{v}"
13
+ end
31
14
  end
32
- else
33
- args.each do |key|
34
- value = env[key]
35
- say "#{key}: #{value}"
15
+
16
+ # "Get an ENV var"
17
+ def self.get(*keys)
18
+ app = current_app
19
+ env = app.env
20
+ keys.each do |k|
21
+ say "#{k}=#{env[k]}"
22
+ end
36
23
  end
37
- end
38
- end
39
- end
40
24
 
41
- command "env:unset" do |c|
42
- c.syntax = "dawn env:unset <key_name> [<key_name>..]"
43
- c.description = "Deletes an ENV var"
25
+ # "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
30
+ end
44
31
 
45
- c.action do |args, options|
46
- env = current_app.env
47
- dlt_keys = [] # list of the deleted keys
48
- arg.each do |key|
49
- if env.key?(key)
50
- env.delete(key)
51
- dlt_keys << key
32
+ # "Deletes an ENV var"
33
+ def self.unset(*keys)
34
+ app = current_app
35
+ keys.each do |k|
36
+ app.env.delete(k)
37
+ end
38
+ app.env.save
52
39
  end
40
+
53
41
  end
54
- env.save
55
- say "deleted #{dlt_keys.join(", ")}"
56
42
  end
57
43
  end
58
-
59
- end
60
- end
61
- end
62
- end
@@ -1,51 +1,34 @@
1
- module Dawn
2
- module CLI
3
- class Application
4
- def key_commands
5
-
6
- command "key:add" do |c|
7
- c.syntax = "dawn key:add"
8
- c.description = "Adds your local ssh_key"
9
-
10
- c.action do |args, options|
11
- filename = File.join(Dir.home, ".ssh/id_rsa.pub")
12
- pubkey = File.read filename
13
- key = Dawn::Key.add(pubkey)
14
- end
15
- end
16
-
17
- command "key:ls" do |c|
18
- c.syntax = "dawn key:ls"
19
- c.description = "Lists all your Keys currently on dawn"
20
-
21
- c.action do |args, options|
22
- keys = Dawn::Key.all
23
- say format_keys(keys)
24
- end
25
- end
26
-
27
- command "key:get" do |c|
28
- c.syntax = "dawn key:get <key_id>"
29
- c.description = "Retrieve a Key by ID"
1
+ require "dawn/cli/helpers"
30
2
 
31
- c.action do |args, options|
32
- key_id = args.first
33
- key = Dawn::Key.find(id: key_id)
34
- say format_keys([key])
35
- end
36
- end
37
-
38
- command "key:delete" do |c|
39
- c.syntax = "dawn key:delete <key_id>"
40
- c.description = "Delete a Key by ID"
41
-
42
- c.action do |args, options|
43
- key_id = args.first
44
- Dawn::Key.destroy(id: key_id)
3
+ module Dawn
4
+ module CLI
5
+ module Key
6
+
7
+ extend Dawn::CLI::Helpers
8
+
9
+ # "Lists all your Keys currently on dawn"
10
+ def self.list
11
+ say format_keys(Dawn::Key.all)
12
+ end
13
+
14
+ # "Adds this machine's sshkey to Dawn"
15
+ def self.add
16
+ filename = File.join(Dir.home, ".ssh/id_rsa.pub")
17
+ pubkey = File.read filename
18
+ key = Dawn::Key.create(key: pubkey)
19
+ end
20
+
21
+ # "Retrieve a Key by ID"
22
+ def self.get(id)
23
+ key = Dawn::Key.find(id: id)
24
+ say format_keys([key])
25
+ end
26
+
27
+ # "Delete a Key by ID"
28
+ def self.delete
29
+ Dawn::Key.destroy(id: id)
30
+ end
31
+
32
+ end
45
33
  end
46
34
  end
47
-
48
- end
49
- end
50
- end
51
- end
@@ -1,57 +1,25 @@
1
- module Dawn
2
- module CLI
3
- class Application
4
- def local_commands
1
+ require "dawn/cli/helpers"
5
2
 
6
- #command "ping" do |c|
7
- # c.syntax "dawn ping"
8
- # c.description = "Pings the dawn server to determine if its working correctly"
9
- # c.action do |args, options|
10
- # end
11
- #end
3
+ module Dawn
4
+ module CLI
5
+ module Local
12
6
 
13
- command "new" do |c|
14
- c.syntax = "dawn new [<app_name>]"
15
- c.description = "Create a new dawn App (with git; setup)"
7
+ extend Dawn::CLI::Helpers
16
8
 
17
- c.action do |args, options|
18
- appname = args.first
19
- app = try_create_app appname
20
- appname = app.name
9
+ def self.health_check
10
+ Dawn::API.health_check
11
+ end
21
12
 
22
- if Dir.exists? appname
23
- say " warning ! Directory #{appname} already exists"
24
- else
25
- FileUtils.mkdir_p appname
26
- say "\tCREATE\t#{appname}"
27
- end
13
+ # "Create a new dawn App (with git; setup)"
14
+ def self.create(appname=nil)
15
+ app = try_create_app appname
16
+ # since its possible for dawn to create a new app, with a random name
17
+ # setting the appname again based on the real app's name is required
18
+ appname = app.name
19
+ git_add_dawn_remote app
20
+ say "\tAPP\t#{app.name}"
21
+ end
28
22
 
29
- Dir.chdir appname do
30
- `git init`
31
- git_add_dawn_remote app
32
23
  end
33
- say "\tAPP\t#{appname}"
34
- end
35
- end
36
- alias_command "create", "new"
37
-
38
- command "init" do |c|
39
- c.syntax = "dawn init [<app_name>]"
40
- c.description = "Setup an existing App with a dawn remote, if no <app_name> is given, the App directory's name will be used"
41
-
42
- c.option "--name NAME", String, "name your App"
43
- c.option "--random", "gives you App an awesome name"
44
-
45
- c.action do |args, options|
46
- appname = args.first || options.name || File.basename(Dir.getwd)
47
- appname = nil if options.random
48
- app = try_create_app appname
49
- git_add_dawn_remote app
50
- say "\tAPP\t#{app.name}"
51
24
  end
52
25
  end
53
-
54
- end
55
- end
56
- end
57
- end
@@ -0,0 +1,21 @@
1
+ require "dawn/cli/helpers"
2
+
3
+ module Dawn
4
+ module CLI
5
+ module Release
6
+
7
+ extend Dawn::CLI::Helpers
8
+
9
+ # "List all releases for the current app"
10
+ def self.list
11
+ say format_releases(current_app.releases.all)
12
+ end
13
+
14
+ # "Add a new release to the current app"
15
+ def self.add
16
+ current_app.releases.create(release:{})
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,8 @@
1
- require 'dawn/cli/commands/app' # App management namespace
2
- require 'dawn/cli/commands/drain' # App drain management namespace
3
- require 'dawn/cli/commands/env' # App ENV management namespace
4
- require 'dawn/cli/commands/domain' # App domains management namespace
5
- require 'dawn/cli/commands/key' # Key management namespace
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
6
7
  require 'dawn/cli/commands/local' # Various functions
7
- require 'dawn/cli/commands/login' # Netrc setup and login command
8
+ require 'dawn/cli/commands/release' # App Releases functions
@@ -1,32 +1,14 @@
1
1
  require 'dawn/api'
2
2
  require 'dawn/api/hosts'
3
+ require 'dawn/cli/version'
3
4
  require 'dawn/cli/output_formatter' # CLI Console Formatters
4
- require 'dawn/cli/commands' # CLI Commands
5
5
 
6
6
  module Dawn
7
7
  module CLI
8
- class Application
8
+ module Helpers
9
9
 
10
- include Commander::Methods
11
10
  include OutputFormatter
12
11
 
13
- def run
14
- # :name is optional, otherwise uses the basename of this executable
15
- program :name, 'Dawn CLI'
16
- program :version, Dawn::CLI::VERSION + "α"
17
- program :description, 'CLI client for Dawn'
18
-
19
- default_command 'help'
20
-
21
- app_commands
22
- domain_commands
23
- drain_commands
24
- env_commands
25
- key_commands
26
- local_commands
27
- login_commands
28
- end
29
-
30
12
  ## swiped from Heroku
31
13
  def has_git?
32
14
  %x{ git --version }
@@ -43,10 +25,10 @@ module Dawn
43
25
  def try_create_app(appname=nil)
44
26
  abort "dawn remote already exists, please remove it (dawn app:delete)" if git_dawn_remote?
45
27
  begin
46
- app = Dawn::App.create name: appname
28
+ app = Dawn::App.create(app: { name: appname })
47
29
  rescue Excon::Errors::Conflict
48
- app = Dawn::App.find name: appname
49
- say " warning ! App (#{app.name}) already exists"
30
+ app = Dawn::App.find(name: appname)
31
+ puts " warning ! App (#{app.name}) already exists"
50
32
  end
51
33
  return app
52
34
  end
@@ -102,21 +84,16 @@ module Dawn
102
84
  end
103
85
 
104
86
  def current_app_name(options={})
105
- @current_app ||= if options.key?(:app)
106
- options[:app]
107
- elsif ENV.key?("DAWN_APP")
108
- ENV["DAWN_APP"]
109
- elsif app_from_dir = extract_app_in_dir(Dir.pwd, options)
110
- app_from_dir
111
- else
112
- abort "App could not be located!"
87
+ @current_app ||= begin
88
+ options[:app] || ENV["DAWN_APP"] ||
89
+ Dawn::CLI.selected_app || extract_app_in_dir(Dir.pwd, options) ||
90
+ abort("App could not be located!")
113
91
  end
114
92
  end
115
93
 
116
- def current_app
117
- app = Dawn::App.find name: current_app_name
118
- abort "App (#{current_app_name}) was not found on the dawn server!" unless app
119
- app
94
+ def current_app(options={})
95
+ name = current_app_name(options)
96
+ Dawn::App.find(name: name)
120
97
  end
121
98
 
122
99
  end
@@ -1,3 +1,6 @@
1
+ require 'time-lord'
2
+ require 'terminal-table'
3
+
1
4
  module Dawn
2
5
  module CLI
3
6
  module OutputFormatter
@@ -11,8 +14,8 @@ module Dawn
11
14
  headings: ['ID', 'Fingerprint', 'Key'],
12
15
  style: table_style
13
16
  keys.each do |key|
14
- table << [key.id, key.fingerprint, " ... "]#key.key[0, 20]] # truncate the key
15
- table << :separator
17
+ table << [key.id, key.fingerprint, key.key] #{}" ... "]#key.key[0, 20]] # truncate the key
18
+ #table << :separator
16
19
  end
17
20
 
18
21
  table
@@ -25,7 +28,7 @@ module Dawn
25
28
  apps.each do |app|
26
29
  form = app.formation.map { |k,v| "#{k}: #{v}" }.join("\n")
27
30
  table << [app.id, app.name, form]
28
- table << :separator
31
+ #table << :separator
29
32
  end
30
33
 
31
34
  table
@@ -37,7 +40,7 @@ module Dawn
37
40
  style: table_style
38
41
  domains.each do |domain|
39
42
  table << [domain.id, domain.url]
40
- table << :separator
43
+ #table << :separator
41
44
  end
42
45
 
43
46
  table
@@ -49,7 +52,7 @@ module Dawn
49
52
  style: table_style
50
53
  drains.each do |drain|
51
54
  table << [drain.id, drain.url]
52
- table << :separator
55
+ #table << :separator
53
56
  end
54
57
 
55
58
  table
@@ -68,7 +71,7 @@ module Dawn
68
71
  uptime = "just now"
69
72
  end
70
73
  table << [gear.id, gear.name, uptime]
71
- table << :separator
74
+ #table << :separator
72
75
  end
73
76
 
74
77
  table
@@ -76,4 +79,4 @@ module Dawn
76
79
 
77
80
  end
78
81
  end
79
- end
82
+ end
@@ -0,0 +1,266 @@
1
+ require "docopt"
2
+ require 'highline/import'
3
+
4
+ module Dawn
5
+ module CLI
6
+ DOC_TOP = %Q(Usage:
7
+ dawn --version
8
+ dawn [-a APPNAME] [-h] <command> [<argv>...]
9
+
10
+ Commands:
11
+ create [<name>]
12
+ ls
13
+ ps
14
+ login
15
+ logs [-f]
16
+ -f, --follow follow logs
17
+ app
18
+ domain
19
+ drain
20
+ env
21
+ key
22
+ release
23
+ run
24
+
25
+ Options:
26
+ -a APPNAME, --app=APPNAME specify app
27
+ -h, --help display help
28
+ --version print version
29
+ )
30
+
31
+ DOC_SUBCOMMAND = {}
32
+ DOC_SUBCOMMAND["app"] = %Q(Usage:
33
+ dawn app list all avaiable apps
34
+ dawn app <command>
35
+
36
+ Commands:
37
+ delete
38
+ restart
39
+ scale <gear_modifier>
40
+
41
+ GearModifier:
42
+ type=number
43
+ type+number
44
+ type-number
45
+ )
46
+
47
+ DOC_SUBCOMMAND["domain"] = %Q(Usage:
48
+ dawn domain list all domains for current app
49
+ dawn domain [<command>]
50
+
51
+ Commands:
52
+ add <url>
53
+ delete <url>
54
+ )
55
+
56
+ DOC_SUBCOMMAND["drain"] = %Q(Usage:
57
+ dawn drain list all drains for current app
58
+ dawn drain [<command>]
59
+
60
+ Commands:
61
+ add <url>
62
+ delete <url>
63
+ )
64
+
65
+ DOC_SUBCOMMAND["env"] = %Q(Usage:
66
+ dawn env print the ENV for the current app
67
+ dawn env [<command>]
68
+
69
+ Commands:
70
+ get <key_name>...
71
+ set <key_name=value>...
72
+ unset <key_name>...
73
+ )
74
+
75
+ DOC_SUBCOMMAND["key"] = %Q(Usage:
76
+ dawn key list all keys deployed to dawn
77
+ dawn key [<command>]
78
+
79
+ Commands:
80
+ add
81
+ delete <id>
82
+ get <id>
83
+ )
84
+
85
+ DOC_SUBCOMMAND["release"] = %Q(Usage:
86
+ dawn release list all releases for the current app
87
+ dawn release [<command>]
88
+
89
+ Commands:
90
+ add
91
+ )
92
+
93
+ @@selected_app = nil
94
+
95
+ ###
96
+ # @return [String]
97
+ ###
98
+ def self.selected_app
99
+ @@selected_app
100
+ end
101
+
102
+ ###
103
+ # @param [String] appname
104
+ ###
105
+ def self.selected_app=(appname)
106
+ @@selected_app = appname
107
+ end
108
+
109
+ ###
110
+ # @param [String] basename
111
+ ###
112
+ def self.not_a_command(basename, command)
113
+ # oh look, git style error message
114
+ abort "#{basename}: '#{command}' is not a #{basename} command. See '#{basename} --help'."
115
+ end
116
+
117
+ ###
118
+ # @param [String] command
119
+ # @param [Hash] options
120
+ ###
121
+ def self.run_app_command(command, options)
122
+ case command.to_s
123
+ when ""
124
+ Dawn::CLI::App.list
125
+ when "delete"
126
+ Dawn::CLI::App.delete
127
+ when "restart"
128
+ Dawn::CLI::App.restart
129
+ when "scale"
130
+ data = options["<argv>"].inject({}) do |str, hash|
131
+ if str =~ /(\S+)([+-=])(\d+)/
132
+ hash[$1] = [$2, $3.to_i]
133
+ end
134
+ end
135
+ Dawn::CLI::App.scale(data)
136
+ else
137
+ not_a_command("dawn app", command)
138
+ end
139
+ end
140
+
141
+ def self.run_domain_command(command, options)
142
+ case command.to_s
143
+ when ""
144
+ Dawn::CLI::Domain.list
145
+ when "add"
146
+ url = options["<argv>"].first
147
+ Dawn::CLI::Domain.add(url)
148
+ when "delete"
149
+ url = options["<argv>"].first
150
+ Dawn::CLI::Domain.delete(url)
151
+ else
152
+ not_a_command("dawn domain", command)
153
+ end
154
+ end
155
+
156
+ def self.run_drain_command(command, options)
157
+ case command.to_s
158
+ when ""
159
+ Dawn::CLI::Drain.list
160
+ when "add"
161
+ url = options["<argv>"].first
162
+ Dawn::CLI::Drain.add(url)
163
+ when "delete"
164
+ url = options["<argv>"].first
165
+ Dawn::CLI::Drain.delete(url)
166
+ else
167
+ not_a_command("dawn drain", command)
168
+ end
169
+ end
170
+
171
+ def self.run_env_command(command, options)
172
+ case command.to_s
173
+ when ""
174
+ Dawn::CLI::Env.list
175
+ when "get"
176
+ keys = options["<argv>"]
177
+ Dawn::CLI::Env.get(*keys)
178
+ when "set"
179
+ data = options["<argv>"].each_with_object({}) do |str, hash|
180
+ if str =~ /(\S+)=(.*)/
181
+ key, value = $1, $2
182
+ hash[key] = value
183
+ end
184
+ end
185
+ Dawn::CLI::Env.set(data)
186
+ when "unset"
187
+ keys = options["<argv>"]
188
+ Dawn::CLI::Env.unset(*keys)
189
+ else
190
+ not_a_command("dawn env", command)
191
+ end
192
+ end
193
+
194
+ def self.run_key_command(command, options)
195
+ case command.to_s
196
+ when ""
197
+ Dawn::CLI::Key.list
198
+ when "add"
199
+ Dawn::CLI::Key.add
200
+ when "get"
201
+ id = options["<argv>"].first
202
+ Dawn::CLI::Key.get(id)
203
+ when "delete"
204
+ id = options["<argv>"].first
205
+ Dawn::CLI::Key.delete(id)
206
+ else
207
+ not_a_command("dawn env", command)
208
+ end
209
+ end
210
+
211
+ def self.run_release_command(command, options)
212
+ case command.to_s
213
+ when ""
214
+ Dawn::CLI::Release.list
215
+ when "add"
216
+ Dawn::CLI::Release.add
217
+ else
218
+ not_a_command("dawn release", command)
219
+ end
220
+ end
221
+
222
+ def self.run_subcommand(command, argv)
223
+ if argv.empty?
224
+ subcommand = ""
225
+ else
226
+ result = Docopt.docopt(DOC_SUBCOMMAND[command], argv: argv,
227
+ version: Dawn::CLI::VERSION, help: false)
228
+ subcommand = result["<command>"]
229
+ end
230
+ send("run_#{command}_command", subcommand, result)
231
+ end
232
+
233
+ def self.run(argv)
234
+ result = Docopt.docopt(DOC_TOP, version: Dawn::CLI::VERSION, argv: argv)
235
+ if result["--version"]
236
+ say "Dawn CLI #{Dawn::CLI::VERSION}"
237
+ else
238
+ self.selected_app = result["--app"]
239
+
240
+ command = result["<command>"]
241
+ command_argv = result["<argv>"]
242
+ case command
243
+ when "create"
244
+ Dawn::CLI::App.create command_argv.first
245
+ when "ls"
246
+ Dawn::CLI::App.list
247
+ when "ps"
248
+ Dawn::CLI::App.list_gears
249
+ when "login"
250
+ username = ask("Username: ")
251
+ password = ask("Password: ") { |q| q.echo = false }
252
+ Dawn::CLI::Auth.login username, password
253
+ when "logs"
254
+ Dawn::CLI::App.logs
255
+ when *DOC_SUBCOMMAND.keys
256
+ run_subcommand(command, command_argv)
257
+ else
258
+ not_a_command("dawn", command)
259
+ end
260
+ end
261
+ rescue Docopt::Exit => ex
262
+ abort ex.message
263
+ end
264
+
265
+ end
266
+ end
@@ -1,7 +1,9 @@
1
+ require 'terminal-table'
2
+
1
3
  class Terminal::Table
2
4
 
3
5
  ##
4
6
  # say uses to_str instead of to_s
5
7
  alias :to_str :to_s
6
8
 
7
- end
9
+ end
@@ -2,10 +2,10 @@ module Dawn
2
2
  module CLI
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 7
5
+ MINOR = 9
6
6
  PATCH = 0
7
7
  BUILD = nil
8
- STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".").freeze
8
+ STRING = [[MAJOR, MINOR, PATCH].compact.join("."), BUILD].compact.join("-").freeze
9
9
  end
10
10
  # backward compatibility
11
11
  VERSION = Version::STRING
data/lib/dawn/cli.rb CHANGED
@@ -1,9 +1,5 @@
1
- require 'uri'
2
- require 'net/http'
3
- require 'time-lord'
4
- require 'terminal-table'
5
-
6
1
  require 'dawn/api' # Dawn::Api
7
2
  require 'dawn/cli/version' # CLI::Version information
8
3
  require 'dawn/cli/patches' # Various Monkey Patches
9
- require 'dawn/cli/application' # Various Monkey Patches
4
+ require 'dawn/cli/commands' # CLI Commands
5
+ require 'dawn/cli/parser'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dawn-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blaž Hrastnik
@@ -9,22 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-07 00:00:00.000000000 Z
12
+ date: 2014-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: commander
15
+ name: docopt
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '4.2'
20
+ version: '0.5'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '4.2'
27
+ version: '0.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: highline
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.6'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.6'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: time-lord
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -59,14 +73,14 @@ dependencies:
59
73
  requirements:
60
74
  - - "~>"
61
75
  - !ruby/object:Gem::Version
62
- version: '0.9'
76
+ version: '0.10'
63
77
  type: :runtime
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - "~>"
68
82
  - !ruby/object:Gem::Version
69
- version: '0.9'
83
+ version: '0.10'
70
84
  description: CLI for Dawn PaaS
71
85
  email:
72
86
  executables:
@@ -74,18 +88,22 @@ executables:
74
88
  extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
91
+ - CHANGELOG.md
92
+ - README.md
77
93
  - bin/dawn
78
94
  - lib/dawn/cli.rb
79
- - lib/dawn/cli/application.rb
80
95
  - lib/dawn/cli/commands.rb
81
96
  - lib/dawn/cli/commands/app.rb
97
+ - lib/dawn/cli/commands/auth.rb
82
98
  - lib/dawn/cli/commands/domain.rb
83
99
  - lib/dawn/cli/commands/drain.rb
84
100
  - lib/dawn/cli/commands/env.rb
85
101
  - lib/dawn/cli/commands/key.rb
86
102
  - lib/dawn/cli/commands/local.rb
87
- - lib/dawn/cli/commands/login.rb
103
+ - lib/dawn/cli/commands/release.rb
104
+ - lib/dawn/cli/helpers.rb
88
105
  - lib/dawn/cli/output_formatter.rb
106
+ - lib/dawn/cli/parser.rb
89
107
  - lib/dawn/cli/patches.rb
90
108
  - lib/dawn/cli/version.rb
91
109
  homepage: https://github.com/dawn/dawn-cli
@@ -1,21 +0,0 @@
1
- module Dawn
2
- module CLI
3
- class Application
4
- def login_commands
5
-
6
- command "login" do |c|
7
- c.syntax = "dawn login"
8
- c.description = "Login to dawn's API"
9
-
10
- c.action do |args, options|
11
- usn = ask "Username: "
12
- psw = password "Password: "
13
- Dawn.authenticate username: usn, password: psw
14
- say " ! login details have been saved to your .netrc"
15
- end
16
- end
17
-
18
- end
19
- end
20
- end
21
- end