ec2ctl 0.7.9 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/LICENSE +21 -0
- data/README.md +32 -2
- data/Rakefile +0 -5
- data/ec2ctl.gemspec +17 -15
- data/lib/ec2ctl/cli.rb +202 -72
- data/lib/ec2ctl/client.rb +549 -21
- data/lib/ec2ctl/logger.rb +179 -0
- data/lib/ec2ctl/version.rb +1 -1
- metadata +43 -38
@@ -0,0 +1,179 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "forwardable"
|
3
|
+
|
4
|
+
module EC2Ctl
|
5
|
+
class Logger
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
InvalidOutputFormat = Class.new RuntimeError
|
9
|
+
|
10
|
+
VALID_FORMATS = %w(json yaml table markdown backlog)
|
11
|
+
|
12
|
+
def initialize(
|
13
|
+
output_format: :json,
|
14
|
+
null_output: false,
|
15
|
+
pretty: false,
|
16
|
+
verbose: false,
|
17
|
+
std_io: STDOUT,
|
18
|
+
err_io: STDERR
|
19
|
+
)
|
20
|
+
@output_format = output_format
|
21
|
+
@null_output = null_output
|
22
|
+
@std_logger = ::Logger.new std_io
|
23
|
+
@err_logger = ::Logger.new err_io
|
24
|
+
|
25
|
+
@std_logger.level = verbose ? ::Logger::DEBUG : ::Logger::INFO
|
26
|
+
@err_logger.level = verbose ? ::Logger::DEBUG : ::Logger::INFO
|
27
|
+
|
28
|
+
@std_logger.formatter = formatter(std_io, pretty)
|
29
|
+
@err_logger.formatter = formatter(err_io, pretty)
|
30
|
+
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
%i(debug info warn).each do |m|
|
35
|
+
define_method m do |args|
|
36
|
+
@std_logger.send m, to_hash(args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
%i(error fatal).each do |m|
|
41
|
+
define_method m do |args|
|
42
|
+
@err_logger.send m, to_hash(args)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def_delegators :@std_logger, :debug?, :info?, :warn?, :error?, :fatal?
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def to_hash(object)
|
51
|
+
case object
|
52
|
+
when Struct
|
53
|
+
object.each_pair.to_a.map {|a|
|
54
|
+
[a.first, to_hash(a.last)]
|
55
|
+
}.to_h
|
56
|
+
when Hash
|
57
|
+
object.to_a.map {|a|
|
58
|
+
[a.first, to_hash(a.last)]
|
59
|
+
}.to_h
|
60
|
+
when Array, Aws::Resources::Collection
|
61
|
+
object.map {|o| to_hash(o)}
|
62
|
+
when Aws::Resources::Resource
|
63
|
+
to_hash object.data
|
64
|
+
else
|
65
|
+
object
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def formatter(io, pretty)
|
70
|
+
-> (severity, time, progname, message) {
|
71
|
+
return "" if @null_output
|
72
|
+
|
73
|
+
data = {
|
74
|
+
time: time,
|
75
|
+
severity: severity,
|
76
|
+
}.merge(
|
77
|
+
if message.is_a? Hash
|
78
|
+
message
|
79
|
+
else
|
80
|
+
{message: message}
|
81
|
+
end
|
82
|
+
)
|
83
|
+
|
84
|
+
case @output_format
|
85
|
+
when /\Ajson\z/i
|
86
|
+
require "json"
|
87
|
+
|
88
|
+
json = JSON.send((pretty ? :pretty_generate : :generate), data) + "\n"
|
89
|
+
|
90
|
+
if io.tty?
|
91
|
+
require "coderay"
|
92
|
+
CodeRay.scan(json, :json).terminal
|
93
|
+
else
|
94
|
+
json
|
95
|
+
end
|
96
|
+
when /\Ayaml\z/i
|
97
|
+
require "yaml"
|
98
|
+
|
99
|
+
# korehahidoi
|
100
|
+
require "json"
|
101
|
+
yaml = YAML.dump(JSON.load(JSON.generate(data)))
|
102
|
+
|
103
|
+
if io.tty?
|
104
|
+
require "coderay"
|
105
|
+
CodeRay.scan(yaml, :yaml).terminal
|
106
|
+
else
|
107
|
+
yaml
|
108
|
+
end
|
109
|
+
when /\Atable|markdown|backlog\z/i
|
110
|
+
require "terminal-table"
|
111
|
+
require "json"
|
112
|
+
|
113
|
+
title, content = data.find {|k, v| !%i(time severity).include?(k)}
|
114
|
+
|
115
|
+
headings, rows = begin
|
116
|
+
case content
|
117
|
+
when Hash
|
118
|
+
row = content.values.map do |value|
|
119
|
+
case value
|
120
|
+
when Hash, Array
|
121
|
+
JSON.generate value
|
122
|
+
else
|
123
|
+
value.to_s
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
[content.keys.map(&:to_s), [row]]
|
128
|
+
when Array
|
129
|
+
if content.first.is_a? Hash
|
130
|
+
rows = content.map do |item|
|
131
|
+
item.values.map do |value|
|
132
|
+
case value
|
133
|
+
when Hash, Array
|
134
|
+
JSON.generate value
|
135
|
+
else
|
136
|
+
value.to_s
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
[content.first.keys, rows]
|
142
|
+
else
|
143
|
+
[["items"], [content]]
|
144
|
+
end
|
145
|
+
else
|
146
|
+
fail
|
147
|
+
end
|
148
|
+
rescue
|
149
|
+
[["data"], [[content.to_json]]]
|
150
|
+
end
|
151
|
+
|
152
|
+
table = Terminal::Table.new(
|
153
|
+
title: (@output_format == :table ? title : nil),
|
154
|
+
headings: headings,
|
155
|
+
rows: rows,
|
156
|
+
).to_s
|
157
|
+
|
158
|
+
output = case @output_format
|
159
|
+
when /\Atable\z/i
|
160
|
+
table + "\n"
|
161
|
+
when /\Amarkdown\z/i
|
162
|
+
lines = table.lines[1..-2]
|
163
|
+
lines[1].gsub!("+", "|")
|
164
|
+
lines.join
|
165
|
+
when /\Abacklog\z/i
|
166
|
+
lines = table.lines[1..-2]
|
167
|
+
lines[0].sub!("\n", "h\n")
|
168
|
+
lines[1] = nil
|
169
|
+
lines.compact.join
|
170
|
+
end
|
171
|
+
|
172
|
+
output + "\n"
|
173
|
+
else
|
174
|
+
fail InvalidOutputFormat, "Valid output formats are #{VALID_FORMATS}"
|
175
|
+
end
|
176
|
+
}
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
data/lib/ec2ctl/version.rb
CHANGED
metadata
CHANGED
@@ -1,114 +1,114 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ec2ctl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Yoriki Yamaguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: aws-sdk
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: commander
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '4.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: coderay
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '1.1'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: terminal-table
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
62
|
-
type: :
|
61
|
+
version: '1.6'
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
68
|
+
version: '1.6'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.12'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1.12'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
89
|
+
version: '10.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
96
|
+
version: '10.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: pry
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
103
|
+
version: '0.10'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
description: A
|
110
|
+
version: '0.10'
|
111
|
+
description: A small command line tool for managing EC2/ELB.
|
112
112
|
email:
|
113
113
|
- email@y13i.com
|
114
114
|
executables:
|
@@ -117,7 +117,10 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CODE_OF_CONDUCT.md
|
120
122
|
- Gemfile
|
123
|
+
- LICENSE
|
121
124
|
- README.md
|
122
125
|
- Rakefile
|
123
126
|
- bin/console
|
@@ -127,9 +130,11 @@ files:
|
|
127
130
|
- lib/ec2ctl.rb
|
128
131
|
- lib/ec2ctl/cli.rb
|
129
132
|
- lib/ec2ctl/client.rb
|
133
|
+
- lib/ec2ctl/logger.rb
|
130
134
|
- lib/ec2ctl/version.rb
|
131
135
|
homepage: https://github.com/y13i/ec2ctl
|
132
|
-
licenses:
|
136
|
+
licenses:
|
137
|
+
- MIT
|
133
138
|
metadata: {}
|
134
139
|
post_install_message:
|
135
140
|
rdoc_options: []
|
@@ -139,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
144
|
requirements:
|
140
145
|
- - ">="
|
141
146
|
- !ruby/object:Gem::Version
|
142
|
-
version:
|
147
|
+
version: 2.1.0
|
143
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
149
|
requirements:
|
145
150
|
- - ">="
|
@@ -150,5 +155,5 @@ rubyforge_project:
|
|
150
155
|
rubygems_version: 2.5.1
|
151
156
|
signing_key:
|
152
157
|
specification_version: 4
|
153
|
-
summary: A
|
158
|
+
summary: A small command line tool for managing EC2/ELB.
|
154
159
|
test_files: []
|