console_runner 0.1.20 → 0.1.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/command_line_parser.rb +3 -4
- data/lib/console_runner.rb +11 -10
- data/lib/console_runner/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada21ff65dc0e2c0a9b1507be918b6f106136c18
|
4
|
+
data.tar.gz: 9296ab89bdb38ef21b3d93224c8cc940e31a0f20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0899daa95e9d73083b7880314a3fa2fb144e7efc597a19aa72a376c5a388e0c8729958d2d96b904f53d8fd9d5917be2466267c9f67a0eb9e981adb56c5103602
|
7
|
+
data.tar.gz: ae4e372b0dce5c371c0ee213fb69fcd1feb587fce471790af879e3a60044edd1dc9b9ec884609a004faa6ca788d60d9cf15047d3159335ec8e09d3076b2b3dca
|
data/lib/command_line_parser.rb
CHANGED
@@ -19,6 +19,7 @@ class CommandLineParser
|
|
19
19
|
]
|
20
20
|
end.to_h
|
21
21
|
@parser = Trollop::Parser.new
|
22
|
+
@parser.opt(:debug, 'Run in debug mode.', type: :flag)
|
22
23
|
@parser.stop_on @sub_commands
|
23
24
|
@initialize_method = nil
|
24
25
|
end
|
@@ -28,7 +29,7 @@ class CommandLineParser
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def self.debug=(value)
|
31
|
-
@debug=value
|
32
|
+
@debug = value unless @debug
|
32
33
|
end
|
33
34
|
|
34
35
|
def tool_banner
|
@@ -66,7 +67,6 @@ class CommandLineParser
|
|
66
67
|
raise_on_action_absence @sub_commands
|
67
68
|
@initialize_method ||= MethodParser.new(@file_parser.initialize_method) if @file_parser.initialize_method
|
68
69
|
@method = MethodParser.new action
|
69
|
-
@parser.opt(:debug, 'Run in debug mode.', type: :flag)
|
70
70
|
[@initialize_method, @method].each do |method|
|
71
71
|
next unless method
|
72
72
|
method.trollop_opts.each { |a| @parser.opt(*a) }
|
@@ -86,5 +86,4 @@ class CommandLineParser
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
end
|
90
|
-
|
89
|
+
end
|
data/lib/console_runner.rb
CHANGED
@@ -13,10 +13,12 @@ Start Time: #{start_time}".blue
|
|
13
13
|
|
14
14
|
file_from_arg = ARGV.shift
|
15
15
|
raise ConsoleRunnerError, 'Specify file to be executed' unless file_from_arg
|
16
|
-
file_path
|
17
|
-
file_parser
|
18
|
-
|
19
|
-
|
16
|
+
file_path = File.realpath file_from_arg
|
17
|
+
file_parser = FileParser.new(file_path)
|
18
|
+
next_arguments = ARGV.dup
|
19
|
+
%w(-d --debug -h --help).each { |a| next_arguments.delete a }
|
20
|
+
cmd = next_arguments[0]
|
21
|
+
actions = file_parser.runnable_methods.select { |m| m.name.to_s == cmd }
|
20
22
|
if actions.count > 1
|
21
23
|
raise(
|
22
24
|
ConsoleRunnerError,
|
@@ -28,18 +30,17 @@ Start Time: #{start_time}".blue
|
|
28
30
|
c_line_parser = CommandLineParser.new(file_parser)
|
29
31
|
c_line_parser.run(action)
|
30
32
|
|
31
|
-
debug_message =
|
33
|
+
debug_message = SEPARATOR
|
32
34
|
if c_line_parser.initialize_method
|
33
|
-
debug_message += "
|
35
|
+
debug_message += "\ninitialize method execution\n"
|
34
36
|
debug_message += c_line_parser.initialize_method.cmd_opts.map { |k, v| " #{k} = #{v}" }.join("\n")
|
35
37
|
end
|
36
|
-
debug_message += "#{action.name} method
|
38
|
+
debug_message += "\n#{action.name} method execution\n"
|
37
39
|
debug_message += c_line_parser.method.cmd_opts.map { |k, v| " #{k} = #{v}" }.join("\n")
|
38
|
-
debug_message +=
|
39
|
-
debug_message += SEPARATOR
|
40
|
+
debug_message += "\nRemaining arguments: #{ARGV.inspect}" if ARGV != []
|
41
|
+
debug_message += "\n#{SEPARATOR}"
|
40
42
|
puts debug_message if CommandLineParser.debug?
|
41
43
|
|
42
|
-
|
43
44
|
require file_path
|
44
45
|
class_full_name = file_parser.clazz.title
|
45
46
|
raise ConsoleRunnerError, "#{class_full_name} is not defined" unless Module.const_defined?(class_full_name)
|