action_command 0.1.5 → 0.1.6
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 +4 -4
- data/Gemfile.lock +1 -1
- data/doc/ActionCommand/Executable.html +1 -1
- data/doc/ActionCommand/InputOutput.html +1 -1
- data/doc/ActionCommand/Result.html +168 -160
- data/doc/ActionCommand.html +76 -62
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +50 -50
- data/doc/top-level-namespace.html +1 -1
- data/lib/action_command/result.rb +37 -8
- data/lib/action_command/version.rb +1 -1
- data/lib/action_command.rb +10 -2
- metadata +2 -2
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
</div>
|
|
104
104
|
|
|
105
105
|
<div id="footer">
|
|
106
|
-
Generated on
|
|
106
|
+
Generated on Wed May 25 10:31:52 2016 by
|
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
108
108
|
0.8.7.6 (ruby-2.2.3).
|
|
109
109
|
</div>
|
|
@@ -13,11 +13,12 @@ module ActionCommand
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
# set the logger for this result
|
|
16
|
-
def
|
|
16
|
+
def configure_logger(logger, format)
|
|
17
17
|
return unless logger
|
|
18
18
|
@sequence = SecureRandom.hex
|
|
19
19
|
@stack = []
|
|
20
20
|
@logger = logger
|
|
21
|
+
@log_format = format
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
# @return true if logging is enabled.
|
|
@@ -29,8 +30,8 @@ module ActionCommand
|
|
|
29
30
|
# @yield return a message or hash
|
|
30
31
|
def debug(msg = nil)
|
|
31
32
|
if @logger
|
|
32
|
-
|
|
33
|
-
@logger.info(
|
|
33
|
+
msg = build_log(msg || yield, ActionCommand::LOG_KIND_DEBUG)
|
|
34
|
+
@logger.info(format_log(msg))
|
|
34
35
|
end
|
|
35
36
|
end
|
|
36
37
|
|
|
@@ -38,14 +39,17 @@ module ActionCommand
|
|
|
38
39
|
# @yield return a message or hash
|
|
39
40
|
def info(msg = nil)
|
|
40
41
|
if @logger
|
|
41
|
-
|
|
42
|
-
@logger.info(
|
|
42
|
+
msg = build_log(msg || yield, ActionCommand::LOG_KIND_INFO)
|
|
43
|
+
@logger.info(format_log(msg))
|
|
43
44
|
end
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
# display an error message to the logger, if there is one.
|
|
47
48
|
def error(msg)
|
|
48
|
-
|
|
49
|
+
if @logger
|
|
50
|
+
msg = build_log(msg, ActionCommand::LOG_KIND_ERROR)
|
|
51
|
+
@logger.error(format_log(msg))
|
|
52
|
+
end
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
# Call this if your command implementation fails. Sets
|
|
@@ -153,7 +157,8 @@ module ActionCommand
|
|
|
153
157
|
|
|
154
158
|
def log_info_hash(params, kind)
|
|
155
159
|
return unless @logger
|
|
156
|
-
|
|
160
|
+
msg = build_log(params, kind)
|
|
161
|
+
@logger.info(format_log(msg))
|
|
157
162
|
end
|
|
158
163
|
|
|
159
164
|
def build_log(msg, kind)
|
|
@@ -166,7 +171,31 @@ module ActionCommand
|
|
|
166
171
|
out[:key] = cur[:key] if cur[:key]
|
|
167
172
|
out[:kind] = kind
|
|
168
173
|
out[:msg] = msg if msg
|
|
169
|
-
return
|
|
174
|
+
return out
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def format_log(msg)
|
|
178
|
+
return JSON.generate(msg) unless @log_format == :human
|
|
179
|
+
|
|
180
|
+
depth = msg[:depth]
|
|
181
|
+
kind = msg[:kind]
|
|
182
|
+
message = msg[:msg]
|
|
183
|
+
cmd = msg[:cmd]
|
|
184
|
+
return format_human_log(depth, cmd, kind, message)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def format_human_log(depth, cmd, kind, msg)
|
|
188
|
+
base_depth = 2 * depth
|
|
189
|
+
extra_depth = base_depth + 2
|
|
190
|
+
if kind == ActionCommand::LOG_KIND_COMMAND_INPUT
|
|
191
|
+
cmd = "#{cmd}: #{msg}"
|
|
192
|
+
return cmd.rjust(cmd.length + base_depth)
|
|
193
|
+
elsif kind == ActionCommand::LOG_KIND_COMMAND_OUTPUT
|
|
194
|
+
out = "output: #{msg}"
|
|
195
|
+
return out.rjust(out.length + extra_depth)
|
|
196
|
+
elsif msg
|
|
197
|
+
return msg.rjust(msg.to_s.length + extra_depth)
|
|
198
|
+
end
|
|
170
199
|
end
|
|
171
200
|
end
|
|
172
201
|
end
|
data/lib/action_command.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'logger'
|
|
1
2
|
require 'action_command/version'
|
|
2
3
|
require 'action_command/result'
|
|
3
4
|
require 'action_command/input_output'
|
|
@@ -88,6 +89,10 @@ module ActionCommand
|
|
|
88
89
|
return
|
|
89
90
|
end
|
|
90
91
|
|
|
92
|
+
# by default, use human logging if a logger is enabled.
|
|
93
|
+
args[:logger] = Logger.new(STDOUT) unless args.key?(:logger)
|
|
94
|
+
args[:log_format] = :human unless args.key?(:log_format)
|
|
95
|
+
|
|
91
96
|
result = create_result
|
|
92
97
|
ActionCommand.create_and_execute(cls, io.rake_input(args), CONTEXT_RAKE, result)
|
|
93
98
|
io.print_output(result)
|
|
@@ -154,8 +159,11 @@ module ActionCommand
|
|
|
154
159
|
def self.create_and_execute(cls, params, parent, result)
|
|
155
160
|
check_params(cls, params)
|
|
156
161
|
params[:parent] = parent
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
logger = params[:logger]
|
|
163
|
+
logger = @@logger unless logger
|
|
164
|
+
log_format = :json
|
|
165
|
+
log_format = params[:log_format] if params.key?(:log_format)
|
|
166
|
+
result.configure_logger(logger, log_format)
|
|
159
167
|
result.root_command(cls) if parent.is_a? Symbol
|
|
160
168
|
action = cls.new(params)
|
|
161
169
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: action_command
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Jones
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-05-
|
|
11
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|