dawn-cli 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/dawn +8 -0
- data/lib/dawn/cli.rb +9 -0
- data/lib/dawn/cli/application.rb +124 -0
- data/lib/dawn/cli/commands.rb +7 -0
- data/lib/dawn/cli/commands/app.rb +174 -0
- data/lib/dawn/cli/commands/domain.rb +49 -0
- data/lib/dawn/cli/commands/drain.rb +50 -0
- data/lib/dawn/cli/commands/env.rb +62 -0
- data/lib/dawn/cli/commands/key.rb +51 -0
- data/lib/dawn/cli/commands/local.rb +57 -0
- data/lib/dawn/cli/commands/login.rb +21 -0
- data/lib/dawn/cli/output_formatter.rb +79 -0
- data/lib/dawn/cli/patches.rb +7 -0
- data/lib/dawn/cli/version.rb +13 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d84982fb0b5183bfa3934340f5bab8083a68cb0
|
4
|
+
data.tar.gz: 3047933667d1f0fb125c23d4ed2f81df17983c44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80bb11d6044735d1499cdf033b4f3d0cd4ded45b103b5bf6dd7488f1554cb25452685fd430c6a6c17cc66af1b0e24cfbf1ae57e094ab875fa075248930867c7e
|
7
|
+
data.tar.gz: ac198cc5ce1c5211e46b318c4fdbe188ad11834fc3bbbcaf78b85272486d575d4e641e8f5194d6c57a816aeddbe053adffcaa032474bbcf64ab0ab573f736e6f
|
data/bin/dawn
ADDED
data/lib/dawn/cli.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'time-lord'
|
4
|
+
require 'terminal-table'
|
5
|
+
|
6
|
+
require 'dawn/api' # Dawn::Api
|
7
|
+
require 'dawn/cli/version' # CLI::Version information
|
8
|
+
require 'dawn/cli/patches' # Various Monkey Patches
|
9
|
+
require 'dawn/cli/application' # Various Monkey Patches
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'dawn/api'
|
2
|
+
require 'dawn/api/hosts'
|
3
|
+
require 'dawn/cli/output_formatter' # CLI Console Formatters
|
4
|
+
require 'dawn/cli/commands' # CLI Commands
|
5
|
+
|
6
|
+
module Dawn
|
7
|
+
module CLI
|
8
|
+
class Application
|
9
|
+
|
10
|
+
include Commander::Methods
|
11
|
+
include OutputFormatter
|
12
|
+
|
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
|
+
## swiped from Heroku
|
31
|
+
def has_git?
|
32
|
+
%x{ git --version }
|
33
|
+
$?.success?
|
34
|
+
end
|
35
|
+
|
36
|
+
def git(args)
|
37
|
+
return "" unless has_git?
|
38
|
+
flattened_args = [args].flatten.compact.join(" ")
|
39
|
+
%x{ git #{flattened_args} 2>&1 }.strip
|
40
|
+
end
|
41
|
+
|
42
|
+
### CLI App resolver
|
43
|
+
def try_create_app(appname=nil)
|
44
|
+
abort "dawn remote already exists, please remove it (dawn app:delete)" if git_dawn_remote?
|
45
|
+
begin
|
46
|
+
app = Dawn::App.create name: appname
|
47
|
+
rescue Excon::Errors::Conflict
|
48
|
+
app = Dawn::App.find name: appname
|
49
|
+
say " warning ! App (#{app.name}) already exists"
|
50
|
+
end
|
51
|
+
return app
|
52
|
+
end
|
53
|
+
|
54
|
+
def git_remotes(base_dir=Dir.pwd)
|
55
|
+
remotes = {}
|
56
|
+
original_dir = Dir.pwd
|
57
|
+
Dir.chdir(base_dir) do
|
58
|
+
return unless File.exists?(".git")
|
59
|
+
git("remote -v").split("\n").each do |remote|
|
60
|
+
name, url, method = remote.split(/\s+/)
|
61
|
+
if url =~ /^git@#{Dawn.git_host}:([\w\d-]+)\.git$/
|
62
|
+
remotes[name] = $1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
remotes.empty? ? nil : remotes
|
67
|
+
end
|
68
|
+
|
69
|
+
def git_dawn_remote?
|
70
|
+
!!(git_remotes && git_remotes["dawn"])
|
71
|
+
end
|
72
|
+
|
73
|
+
def git_remove_dawn_remote(app)
|
74
|
+
# remove old dawn remote
|
75
|
+
git "remote remove dawn"
|
76
|
+
end
|
77
|
+
|
78
|
+
def git_add_dawn_remote(app)
|
79
|
+
abort "dawn remote already exists, please `dawn app:delete` first" if git_dawn_remote?
|
80
|
+
git "remote add dawn git@#{Dawn.git_host}:#{app.git}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def extract_app_remote_from_git_config
|
84
|
+
remote = git "config dawn.remote"
|
85
|
+
remote.empty? ? nil : remote
|
86
|
+
end
|
87
|
+
|
88
|
+
def extract_app_in_dir(dir, options={})
|
89
|
+
return unless remotes = git_remotes(dir)
|
90
|
+
if remote = options[:remote]
|
91
|
+
remotes[remote]
|
92
|
+
elsif remote = extract_app_remote_from_git_config
|
93
|
+
remotes[remote]
|
94
|
+
else
|
95
|
+
apps = remotes.values.uniq
|
96
|
+
if apps.size == 1
|
97
|
+
apps.first
|
98
|
+
else
|
99
|
+
abort "Multiple apps in folder and no app specified.\nSpecify app with --app APP."
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
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!"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
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
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,7 @@
|
|
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
|
6
|
+
require 'dawn/cli/commands/local' # Various functions
|
7
|
+
require 'dawn/cli/commands/login' # Netrc setup and login command
|
@@ -0,0 +1,174 @@
|
|
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"
|
16
|
+
|
17
|
+
command "app:scale" do |c|
|
18
|
+
c.syntax = "dawn app:scale <gear_modifier>"
|
19
|
+
c.description = "Modify the gears of the current app"
|
20
|
+
|
21
|
+
c.action do |args, options|
|
22
|
+
app = current_app
|
23
|
+
formation = {}
|
24
|
+
|
25
|
+
args.each do |s|
|
26
|
+
mtch_data = s.match(/(?<type>\S+)(?<op>[+-=])(?<value>\d+)/)
|
27
|
+
next unless mtch_data
|
28
|
+
|
29
|
+
type = mtch_data[:type]
|
30
|
+
value = mtch_data[:value].to_i
|
31
|
+
old_formation = (app.formation[type] || 0).to_i
|
32
|
+
|
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
|
42
|
+
|
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"
|
46
|
+
|
47
|
+
c.option "--name APPNAME", String, "specify an app by name to remove"
|
48
|
+
|
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
|
57
|
+
|
58
|
+
app_name = app.name
|
59
|
+
app.destroy
|
60
|
+
|
61
|
+
git_remove_dawn_remote app
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
command "app:rename" do |c|
|
66
|
+
c.syntax = "dawn rename <new_name>"
|
67
|
+
c.description = "Rename the current App to <new_name>"
|
68
|
+
|
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])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
else
|
110
|
+
say chunk.to_s
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
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
|
+
end
|
120
|
+
rescue Interrupt
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
alias_command "logs", "app:logs"
|
125
|
+
|
126
|
+
command "app:gears" do |c|
|
127
|
+
c.syntax = "dawn ps [<gear_name>]"
|
128
|
+
c.description = "Lists all currently running Gears"
|
129
|
+
|
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."
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
alias_command "ps", "app:gears"
|
158
|
+
|
159
|
+
command "app:restart" do |c|
|
160
|
+
c.syntax = "dawn restart"
|
161
|
+
c.description = "Restart the current App"
|
162
|
+
|
163
|
+
c.action do |args, options|
|
164
|
+
app = current_app
|
165
|
+
app.restart
|
166
|
+
say "App #{app.name} has been restarted"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
alias_command "restart", "app:restart"
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Dawn
|
2
|
+
module CLI
|
3
|
+
class Application
|
4
|
+
def domain_commands
|
5
|
+
|
6
|
+
command "domain:add" do |c|
|
7
|
+
c.syntax = "dawn domain:add <url>"
|
8
|
+
c.description = "Add a new domain to the current app"
|
9
|
+
|
10
|
+
c.action do |args, options|
|
11
|
+
url = args.first
|
12
|
+
app = current_app
|
13
|
+
|
14
|
+
app.domains.create url: url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
command "domain:delete" do |c|
|
19
|
+
c.syntax = "dawn domain:delete <url>"
|
20
|
+
c.description = "Remove an existing domain from the current app"
|
21
|
+
|
22
|
+
c.action do |args, options|
|
23
|
+
url = args.first
|
24
|
+
app = current_app
|
25
|
+
|
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
|
+
end
|
32
|
+
end
|
33
|
+
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
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Dawn
|
2
|
+
module CLI
|
3
|
+
class Application
|
4
|
+
def drain_commands
|
5
|
+
|
6
|
+
command "drain:add" do |c|
|
7
|
+
c.syntax = "dawn drain:add <url>"
|
8
|
+
c.description = "Add a Drain url"
|
9
|
+
|
10
|
+
c.action do |args, options|
|
11
|
+
url = args.first
|
12
|
+
app = current_app
|
13
|
+
|
14
|
+
drain = app.drains.create url: url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
command "drain:delete" do |c|
|
19
|
+
c.syntax = "dawn drain:delete <url>"
|
20
|
+
c.description = "Remove a Drain url"
|
21
|
+
|
22
|
+
c.action do |args, options|
|
23
|
+
url = args.first
|
24
|
+
app = current_app
|
25
|
+
|
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
|
+
end
|
32
|
+
end
|
33
|
+
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
|
@@ -0,0 +1,62 @@
|
|
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"
|
9
|
+
|
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
|
21
|
+
|
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"
|
25
|
+
|
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}"
|
31
|
+
end
|
32
|
+
else
|
33
|
+
args.each do |key|
|
34
|
+
value = env[key]
|
35
|
+
say "#{key}: #{value}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
command "env:unset" do |c|
|
42
|
+
c.syntax = "dawn env:unset <key_name> [<key_name>..]"
|
43
|
+
c.description = "Deletes an ENV var"
|
44
|
+
|
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
|
52
|
+
end
|
53
|
+
end
|
54
|
+
env.save
|
55
|
+
say "deleted #{dlt_keys.join(", ")}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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"
|
30
|
+
|
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)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Dawn
|
2
|
+
module CLI
|
3
|
+
class Application
|
4
|
+
def local_commands
|
5
|
+
|
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
|
12
|
+
|
13
|
+
command "new" do |c|
|
14
|
+
c.syntax = "dawn new [<app_name>]"
|
15
|
+
c.description = "Create a new dawn App (with git; setup)"
|
16
|
+
|
17
|
+
c.action do |args, options|
|
18
|
+
appname = args.first
|
19
|
+
app = try_create_app appname
|
20
|
+
appname = app.name
|
21
|
+
|
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
|
28
|
+
|
29
|
+
Dir.chdir appname do
|
30
|
+
`git init`
|
31
|
+
git_add_dawn_remote app
|
32
|
+
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
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Dawn
|
2
|
+
module CLI
|
3
|
+
module OutputFormatter
|
4
|
+
|
5
|
+
def table_style
|
6
|
+
{ } #width: 80 }
|
7
|
+
end
|
8
|
+
|
9
|
+
def format_keys(keys)
|
10
|
+
table = Terminal::Table.new title: 'Keys',
|
11
|
+
headings: ['ID', 'Fingerprint', 'Key'],
|
12
|
+
style: table_style
|
13
|
+
keys.each do |key|
|
14
|
+
table << [key.id, key.fingerprint, " ... "]#key.key[0, 20]] # truncate the key
|
15
|
+
table << :separator
|
16
|
+
end
|
17
|
+
|
18
|
+
table
|
19
|
+
end
|
20
|
+
|
21
|
+
def format_apps(apps)
|
22
|
+
table = Terminal::Table.new title: 'Apps',
|
23
|
+
headings: ['ID', 'Name', 'Formation'],
|
24
|
+
style: table_style
|
25
|
+
apps.each do |app|
|
26
|
+
form = app.formation.map { |k,v| "#{k}: #{v}" }.join("\n")
|
27
|
+
table << [app.id, app.name, form]
|
28
|
+
table << :separator
|
29
|
+
end
|
30
|
+
|
31
|
+
table
|
32
|
+
end
|
33
|
+
|
34
|
+
def format_domains(domains)
|
35
|
+
table = Terminal::Table.new title: 'Domains',
|
36
|
+
headings: ['ID', 'URL'],
|
37
|
+
style: table_style
|
38
|
+
domains.each do |domain|
|
39
|
+
table << [domain.id, domain.url]
|
40
|
+
table << :separator
|
41
|
+
end
|
42
|
+
|
43
|
+
table
|
44
|
+
end
|
45
|
+
|
46
|
+
def format_drains(drains)
|
47
|
+
table = Terminal::Table.new title: 'Drains',
|
48
|
+
headings: ['ID', 'URL'],
|
49
|
+
style: table_style
|
50
|
+
drains.each do |drain|
|
51
|
+
table << [drain.id, drain.url]
|
52
|
+
table << :separator
|
53
|
+
end
|
54
|
+
|
55
|
+
table
|
56
|
+
end
|
57
|
+
|
58
|
+
def format_gears(gears)
|
59
|
+
table = Terminal::Table.new title: 'Gears',
|
60
|
+
headings: ['ID', 'Name', 'Uptime'],
|
61
|
+
style: table_style
|
62
|
+
gears.each do |gear|
|
63
|
+
n = gear.uptime.to_i
|
64
|
+
if n > 0
|
65
|
+
scale = TimeLord::Scale.new(n)
|
66
|
+
uptime = "#{scale.to_value} #{scale.to_unit}"
|
67
|
+
else
|
68
|
+
uptime = "just now"
|
69
|
+
end
|
70
|
+
table << [gear.id, gear.name, uptime]
|
71
|
+
table << :separator
|
72
|
+
end
|
73
|
+
|
74
|
+
table
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dawn-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blaž Hrastnik
|
8
|
+
- Corey Powell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: commander
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '4.2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '4.2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: time-lord
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: terminal-table
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.4'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.4'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: dawn-api
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.9'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.9'
|
70
|
+
description: CLI for Dawn PaaS
|
71
|
+
email:
|
72
|
+
executables:
|
73
|
+
- dawn
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- bin/dawn
|
78
|
+
- lib/dawn/cli.rb
|
79
|
+
- lib/dawn/cli/application.rb
|
80
|
+
- lib/dawn/cli/commands.rb
|
81
|
+
- lib/dawn/cli/commands/app.rb
|
82
|
+
- lib/dawn/cli/commands/domain.rb
|
83
|
+
- lib/dawn/cli/commands/drain.rb
|
84
|
+
- lib/dawn/cli/commands/env.rb
|
85
|
+
- lib/dawn/cli/commands/key.rb
|
86
|
+
- lib/dawn/cli/commands/local.rb
|
87
|
+
- lib/dawn/cli/commands/login.rb
|
88
|
+
- lib/dawn/cli/output_formatter.rb
|
89
|
+
- lib/dawn/cli/patches.rb
|
90
|
+
- lib/dawn/cli/version.rb
|
91
|
+
homepage: https://github.com/dawn/dawn-cli
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Dawn CLI
|
115
|
+
test_files: []
|
116
|
+
has_rdoc:
|