console_runner 0.2.0 → 0.2.2

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: 5a9dea09a8aec1d88e26ce1d6ab015aa0ecc6fda
4
- data.tar.gz: 9429df62e79606d533a9bb71da143826c2687cb7
3
+ metadata.gz: dc6386bed597d9369e063222b56ca1957a8e1fcd
4
+ data.tar.gz: 1241a02a10882d19db7cd9934bd350b285830add
5
5
  SHA512:
6
- metadata.gz: a04c74c6351bee386d658b9ea135d593c49724f0c5c61d7f7f7365652927b3bcb4eb6cffbfd2f95e5b0543e09ae24a2e2c6d7d83f3958551a58d5098fa922e02
7
- data.tar.gz: 02783cbbbe3975ff6575c454fadd83142150c3c08b5ca72546f138cbf2225a9b5e42458a39e4f41b153bf435b26fe7bc9abbbd26faf6ebc5bc2df3521d15ce5e
6
+ metadata.gz: d71bdfafb2521b87ce9d834172ce56aa8a00f21279290a5481316d215facafbae09eb0119a2aea797114020ea6f4c77272d56ef31f2d38301df40b7929be8e24
7
+ data.tar.gz: e44cd673693521010232612540c17774aa0dd20b197bccd8d94435f382835168ab01518329ae810f3d880f8386e48f50cc2e21bc0941bc43434a642aef7eb2bb
@@ -35,9 +35,11 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'rake', '~> 10.0'
36
36
  spec.add_development_dependency 'minitest', '~> 5.0'
37
37
  spec.add_development_dependency 'pry', '~> 0'
38
+ spec.add_development_dependency 'rb-readline', '~> 0'
38
39
  spec.add_development_dependency 'simplecov', '~> 0'
39
40
  spec.add_development_dependency 'coveralls', '~> 0.8'
40
41
  spec.add_dependency 'optimist', '~> 3.0'
41
42
  spec.add_dependency 'yard', '~> 0.9'
42
43
  spec.add_dependency 'colorize', '~> 0.8'
44
+ spec.add_dependency 'tty-logger', '~> 0'
43
45
  end
@@ -1,15 +1,21 @@
1
1
  require 'file_parser'
2
2
  require 'command_line_parser'
3
+ require 'tty-logger'
3
4
  require 'console_runner/version'
4
5
 
5
6
  # console_runner logic is here
6
7
  module ConsoleRunner
7
8
  CommandLineParser.debug = ARGV.any? { |a| %w(-d --debug).include? a }
8
- SEPARATOR = '==================================='.freeze
9
+
10
+ LOGGER = TTY::Logger.new do |config|
11
+ config.level = CommandLineParser.debug? ? :debug : :info
12
+ end
13
+
14
+ SEPARATOR = '=============================================================='.freeze
15
+ start_time = Time.now
9
16
  begin
10
- start_time = Time.now
11
17
  success_status = true
12
- puts "#{SEPARATOR}\nStart Time: #{start_time}\n#{SEPARATOR}".blue
18
+ LOGGER.info "Start Time: #{start_time}"
13
19
  file_from_arg = ARGV.shift
14
20
  raise ConsoleRunnerError, 'Specify file to be executed' unless file_from_arg
15
21
  file_path = File.realpath file_from_arg
@@ -20,8 +26,8 @@ module ConsoleRunner
20
26
  actions = file_parser.runnable_methods.select { |m| m.name.to_s == cmd }
21
27
  if actions.count > 1
22
28
  raise(
23
- ConsoleRunnerError,
24
- "Class and Instance methods have the same name (#{cmd}). Actions names should be unique"
29
+ ConsoleRunnerError,
30
+ "Class and Instance methods have the same name (#{cmd}). Actions names should be unique"
25
31
  )
26
32
  end
27
33
  action = actions.first
@@ -29,16 +35,14 @@ module ConsoleRunner
29
35
  c_line_parser = CommandLineParser.new(file_parser)
30
36
  c_line_parser.run(action)
31
37
 
32
- debug_message = SEPARATOR
33
38
  if c_line_parser.initialize_method
34
- debug_message += "\ninitialize method execution\n"
35
- debug_message += c_line_parser.initialize_method.cmd_opts.map { |k, v| " #{k} = #{v}" }.join("\n")
39
+ LOGGER.debug 'Executing #inistialize method...'
40
+ c_line_parser.initialize_method.cmd_opts.map { |k, v| LOGGER.debug "\t#{k} = #{v}" }
36
41
  end
37
- debug_message += "\n#{action.name} method execution\n"
38
- debug_message += c_line_parser.method.cmd_opts.map { |k, v| " #{k} = #{v}" }.join("\n")
39
- debug_message += "\nRemaining arguments: #{ARGV.inspect}" if ARGV != []
40
- debug_message += "\n#{SEPARATOR}"
41
- puts debug_message if CommandLineParser.debug?
42
+ LOGGER.debug "Executing ##{action.name} method..."
43
+ c_line_parser.method.cmd_opts.map { |k, v| LOGGER.debug "\t#{k} = #{v}" }
44
+ LOGGER.debug("Remaining arguments: #{ARGV.inspect}") if ARGV != []
45
+ LOGGER.info SEPARATOR
42
46
 
43
47
  require file_path
44
48
  class_full_name = file_parser.clazz.title
@@ -48,26 +52,30 @@ module ConsoleRunner
48
52
  method_params = c_line_parser.method.params_array
49
53
 
50
54
  case method_type
51
- when :class
52
- klass_obj.send(action.name, *method_params)
53
- when :instance
54
- init_method = c_line_parser.initialize_method
55
- init_params = []
56
- init_params = init_method.params_array if init_method
57
- obj = klass_obj.new(*init_params)
58
- obj.send(action.name, *method_params)
59
- else
60
- raise ConsoleRunnerError, "Unknown method type: #{method_type}"
55
+ when :class
56
+ klass_obj.send(action.name, *method_params)
57
+ when :instance
58
+ init_method = c_line_parser.initialize_method
59
+ init_params = []
60
+ init_params = init_method.params_array if init_method
61
+ obj = klass_obj.new(*init_params)
62
+ obj.send(action.name, *method_params)
63
+ else
64
+ raise ConsoleRunnerError, "Unknown method type: #{method_type}"
61
65
  end
62
66
  rescue => e
63
67
  success_status = false
64
68
  raise e
65
69
  ensure
66
- finish_time = Time.now
67
70
  status = success_status ? 'Success'.green : 'Error'.red
68
- puts "\n#{SEPARATOR}".blue
69
- puts 'Execution status: '.blue + status
70
- puts "Finish Time: #{finish_time} (Duration: #{((finish_time - start_time) / 60).round(2) } minutes)
71
- #{SEPARATOR}\n".blue
71
+ finish_time = Time.now
72
+ LOGGER.info SEPARATOR
73
+ if success_status
74
+ LOGGER.info "Finish Time: #{finish_time} (Duration: #{((finish_time - start_time) / 60).round(2) } minutes)"
75
+ LOGGER.success 'Execution status: ' + status
76
+ else
77
+ LOGGER.error 'Execution status: ' + status
78
+ end
79
+
72
80
  end
73
81
  end
@@ -1,3 +1,3 @@
1
1
  module ConsoleRunner
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Karpovich
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rb-readline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: simplecov
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0.8'
139
+ - !ruby/object:Gem::Dependency
140
+ name: tty-logger
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  description: This gem provides you an ability to run any Ruby method from command-line
126
154
  (no any code modifications required!!!)
127
155
  email: