dldinternet-mixlib-thor 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e514a24e53b9e7fcb0f1fa73351a0dd13094728f
4
- data.tar.gz: e84ce7160a7bb7c8f830ad1372341e44da96107f
3
+ metadata.gz: 92e001459d25a189e5430f6794b22de3a9729853
4
+ data.tar.gz: c3f18989af8e2419050f606b07ba417a7589f0b5
5
5
  SHA512:
6
- metadata.gz: ddaf17824e3cb6444869eb9d1248e06ef4c629b910b8adbaed403249156f34654f9c5c0f5e2c219364c82160909fc5c92fb338c63449a2c9f294e44376e0eeea
7
- data.tar.gz: 295010865bc6e1373a7b5f1268a38bbff5fc6066126024d8ce1874fa538de18251b90c0c44f921e1241cf3baec54d6a09b1620e280d0011b6744e3594b2825d1
6
+ metadata.gz: 5a80c92d83ba89917814d6c7581895bc1ff568e562ffee76b60f81f84821ef84a8ce6f31cab26f865ce18adfd52eca8c53b92b3a554ffbb95595b6a54079a859
7
+ data.tar.gz: c3e32340ceeae019939d0853366c89e1b226ac24d61c693b0610a11af676c6a41e37a96569960def018a6753e165b7395f9f92c0e93bc688b7b455f5f4cca2c7
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dldinternet-mixlib-thor (0.6.0)
4
+ dldinternet-mixlib-thor (0.7.0)
5
+ activesupport (~> 5.1, >= 5.1.4)
5
6
  awesome_print
6
7
  command_line_reporter (~> 3.3, >= 3.3.6)
7
8
  config-factory
@@ -9,16 +10,23 @@ PATH
9
10
  hashie
10
11
  inifile
11
12
  paint-shortcuts
12
- thor (~> 0.19, >= 0)
13
+ thor (~> 0.19, >= 0.19.4)
14
+ vcr (~> 3.0, >= 3.0.3)
13
15
 
14
16
  GEM
15
17
  remote: https://rubygems.org/
16
18
  specs:
19
+ activesupport (5.1.4)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (~> 0.7)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
17
24
  awesome_print (1.8.0)
18
25
  builder (3.2.3)
19
26
  colored (1.2)
20
27
  command_line_reporter (3.3.6)
21
28
  colored (>= 1.2)
29
+ concurrent-ruby (1.0.5)
22
30
  config-factory (0.0.9)
23
31
  cucumber (0.10.7)
24
32
  builder (>= 2.1.2)
@@ -32,13 +40,15 @@ GEM
32
40
  gherkin (2.4.21)
33
41
  json (>= 1.4.6)
34
42
  hashie (3.5.6)
43
+ i18n (0.8.6)
35
44
  inifile (3.0.0)
36
45
  json (2.0.3)
37
46
  little-plugger (1.1.4)
38
47
  logging (2.2.2)
39
48
  little-plugger (~> 1.1)
40
49
  multi_json (~> 1.10)
41
- multi_json (1.12.1)
50
+ minitest (5.10.3)
51
+ multi_json (1.12.2)
42
52
  paint (2.0.0)
43
53
  paint-shortcuts (2.0.0)
44
54
  paint (>= 1.0, < 3.0)
@@ -47,7 +57,11 @@ GEM
47
57
  term-ansicolor (1.4.0)
48
58
  tins (~> 1.0)
49
59
  thor (0.20.0)
60
+ thread_safe (0.3.6)
50
61
  tins (1.13.2)
62
+ tzinfo (1.2.3)
63
+ thread_safe (~> 0.1)
64
+ vcr (3.0.3)
51
65
 
52
66
  PLATFORMS
53
67
  ruby
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_runtime_dependency 'thor', '~> 0.19', '>= 0'
20
+ gem.add_runtime_dependency 'thor', '~> 0.19', '>= 0.19.4'
21
21
  gem.add_dependency 'awesome_print' #, '~> 1.2'
22
22
  gem.add_dependency 'paint-shortcuts', '>= 0'
23
23
  gem.add_dependency 'inifile' #, '~> '
@@ -25,6 +25,8 @@ Gem::Specification.new do |gem|
25
25
  gem.add_dependency 'command_line_reporter', '~> 3.3', '>= 3.3.6'
26
26
  gem.add_dependency 'dldinternet-mixlib-logging', '>= 0.7.0'
27
27
  gem.add_dependency 'config-factory' #, '~> '
28
+ gem.add_dependency 'vcr', '~> 3.0', '>= 3.0.3'
29
+ gem.add_dependency 'activesupport', '~> 5.1', '>= 5.1.4'
28
30
 
29
31
  gem.add_development_dependency 'bundler', '~> 1.0'
30
32
  gem.add_development_dependency 'rake', '~> 10'
@@ -1,4 +1,5 @@
1
1
  require 'thor'
2
+ require 'dldinternet/thor/dynamic_command'
2
3
  require 'awesome_print'
3
4
 
4
5
  module DLDInternet
@@ -11,6 +12,8 @@ module DLDInternet
11
12
 
12
13
  end
13
14
 
15
+ attr_reader :cassette,:vcr_logger
16
+
14
17
  class << self
15
18
  attr_accessor :invocations
16
19
 
@@ -33,6 +36,10 @@ module DLDInternet
33
36
  0
34
37
  end
35
38
 
39
+ def dynamic_command_class #:nodoc:
40
+ ::DLDInternet::Thor::DynamicCommand
41
+ end
42
+
36
43
  def handle_argument_error(command, error, args, arity) #:nodoc:
37
44
  command_s = banner(command)
38
45
  # msg = "ERROR: \"#{basename} #{command.name}\" was called with "
@@ -43,6 +50,11 @@ module DLDInternet
43
50
  raise ::Thor::InvocationError, msg
44
51
  end
45
52
 
53
+ def handle_no_command_error(command, has_namespace = $thor_runner) #:nodoc:
54
+ raise ::Thor::UndefinedCommandError, "Could not find command #{command.inspect} in #{namespace.inspect} namespace." if has_namespace
55
+ raise ::Thor::UndefinedCommandError, "Could not find command #{command.inspect}."
56
+ end
57
+
46
58
  protected
47
59
 
48
60
  def banner(command, namespace = nil, subcommand = false)
@@ -0,0 +1,34 @@
1
+ require 'thor'
2
+ require 'thor/command'
3
+
4
+ module DLDInternet
5
+ module Thor
6
+ class DynamicCommand < ::Thor::DynamicCommand
7
+ # By default, a command invokes a method in the thor class. You can change this
8
+ # implementation to create custom commands.
9
+ def run(instance, args = [])
10
+ arity = nil
11
+
12
+ if private_method?(instance)
13
+ instance.class.handle_no_command_error(name)
14
+ elsif public_method?(instance)
15
+ arity = instance.method(name).arity
16
+ instance.__send__(name, *args)
17
+ elsif local_method?(instance, :method_missing)
18
+ instance.__send__(:method_missing, name.to_sym, *args)
19
+ else
20
+ if instance.class.instance_methods.include?(:handle_no_command_error)
21
+ instance.handle_no_command_error(name)
22
+ else
23
+ instance.class.handle_no_command_error(name)
24
+ end
25
+ end
26
+ rescue ArgumentError => e
27
+ handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e, args, arity) : (raise e)
28
+ rescue ::Thor::NoMethodError => e
29
+ handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (raise e)
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -6,6 +6,39 @@ require 'hashie/mash'
6
6
  require 'dldinternet/thor/version'
7
7
  require 'inifile'
8
8
  require 'config/factory'
9
+ require 'dldinternet/thor/vcr'
10
+ require 'active_support/core_ext/object/blank'
11
+
12
+ class String
13
+ def to_bool
14
+ return true if self == true || !self.match(/^(true|t|yes|y|1|on)$/i).nil?
15
+ return false if self == false || self.blank? || !self.match(/^(false|f|no|n|0|off)$/i).nil?
16
+ raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
17
+ end
18
+ alias :to_b :to_bool
19
+
20
+ def class_from
21
+ self.split('::').inject(Object) do |mod, class_name|
22
+ mod.const_get(class_name)
23
+ end
24
+ end
25
+ alias :to_class :class_from
26
+
27
+ end
28
+
29
+ class TrueClass
30
+ def to_bool
31
+ true
32
+ end
33
+ alias :to_b :to_bool
34
+ end
35
+
36
+ class FalseClass
37
+ def to_bool
38
+ false
39
+ end
40
+ alias :to_b :to_bool
41
+ end
9
42
 
10
43
  module DLDInternet
11
44
  module Thor
@@ -19,8 +52,7 @@ module DLDInternet
19
52
  include DLDInternet::Mixlib::Logging
20
53
 
21
54
  def validate_options
22
- OptionsMash.disable_warnings
23
- @options = OptionsMash.new(@options.to_h)
55
+ writeable_options
24
56
  if options[:log_level]
25
57
  log_level = options[:log_level].to_sym
26
58
  raise "Invalid log-level: #{log_level}" unless LOG_LEVELS.include?(log_level)
@@ -31,8 +63,14 @@ module DLDInternet
31
63
  @options[:output] ||= @options[:format]
32
64
  end
33
65
 
66
+ def writeable_options
67
+ return if @options.is_a?(OptionsMash)
68
+ OptionsMash.disable_warnings
69
+ @options = OptionsMash.new(@options.to_h)
70
+ end
71
+
34
72
  def load_inifile
35
- unless File.exist?(@options[:inifile])
73
+ unless !@options[:inifile].blank? && File.exist?(@options[:inifile])
36
74
  raise "#{@options[:inifile]} not found!"
37
75
  end
38
76
  begin
@@ -75,36 +113,73 @@ module DLDInternet
75
113
  end
76
114
 
77
115
  def load_config
78
- if File.exist?(@options[:config])
79
- begin
80
- envs = ::Config::Factory::Environments.load_file(@options[:config])
81
- if envs and envs.is_a?(Hash) and @options[:environment]
82
- @options[:environments] = ::Hashie::Mash.new(envs)
83
- else
84
- yaml = ::YAML.load(File.read(@options[:config]))
85
- if yaml
86
- yaml.each {|key, value|
87
- @options[key.to_s.gsub(%r{[-]}, '_').to_sym]=value
88
- }
116
+ unless @options[:config].blank?
117
+ @options[:config] = File.expand_path(@options[:config])
118
+ if ::File.exist?(@options[:config])
119
+ begin
120
+ envs = ::Config::Factory::Environments.load_file(@options[:config])
121
+ if envs and envs.is_a?(Hash) and @options[:environment]
122
+ @options[:environments] = ::Hashie::Mash.new(envs)
89
123
  else
90
- msg = "#{options.config} is not a valid configuration!"
91
- @logger.error msg
92
- raise StandardError.new(msg)
124
+ yaml = ::YAML.load(File.read(@options[:config]))
125
+ if yaml
126
+ yaml.each {|key, value|
127
+ @options[key.to_s.gsub(%r{[-]}, '_').to_sym]=value
128
+ }
129
+ else
130
+ msg = "#{options.config} is not a valid configuration!"
131
+ @logger.error msg
132
+ raise StandardError.new(msg)
133
+ end
93
134
  end
135
+ rescue ::Exception => e
136
+ @logger.error "#{e.class.name} #{e.message}"
137
+ raise e
94
138
  end
95
- rescue ::Exception => e
96
- @logger.error "#{e.class.name} #{e.message}"
97
- raise e
139
+ else
140
+ @logger.warn "#{options.config} not found"
141
+ @logger.error "Invalid/No configuration file specified"
142
+ exit 2
143
+ #@options[:environments] = ::Hashie::Mash.new
98
144
  end
99
145
  else
100
- @logger.warn "#{options.config} not found"
146
+ @logger.error 'Invalid/No configuration file specified'
101
147
  end
102
148
  end
103
149
 
104
150
  def parse_options
105
151
  validate_options
106
152
 
107
- lcs = ::Logging::ColorScheme.new( 'compiler', :levels => {
153
+ get_logger(true)
154
+
155
+ if @options[:inifile]
156
+ @options[:inifile] = File.expand_path(@options[:inifile])
157
+ load_inifile
158
+ elsif @options[:config]
159
+ if @options[:config] =~ /\.ini/i
160
+ @options[:inifile] = @options[:config]
161
+ load_inifile
162
+ else
163
+ load_config
164
+ end
165
+ end
166
+ if options[:debug]
167
+ @logger.info "Options:\n#{options.ai}"
168
+ end
169
+ if options[:stubber].is_a?(String)
170
+ options[:stubber] = options[:stubber].split(/\s*,\s*/).map(&:to_sym)
171
+ elsif options[:stubber].is_a?(Array) && options[:stubber].size == 1 && options[:stubber][0].is_a?(String)
172
+ options[:stubber] = options[:stubber][0].split(/\s*,\s*/).map(&:to_sym)
173
+ elsif options[:stubber].is_a?(Array) && options[:stubber].size > 1 && options[:stubber][0].is_a?(String)
174
+ options[:stubber] = options[:stubber].map(&:to_sym)
175
+ end
176
+
177
+ end
178
+
179
+ def get_logger(force=false)
180
+ return unless force || @logger.nil?
181
+ writeable_options
182
+ lcs = ::Logging::ColorScheme.new('compiler', :levels => {
108
183
  :trace => :blue,
109
184
  :debug => :cyan,
110
185
  :info => :green,
@@ -114,13 +189,13 @@ module DLDInternet
114
189
  :fatal => :red,
115
190
  :todo => :purple,
116
191
  })
117
- scheme = lcs.scheme
192
+ scheme = lcs.scheme
118
193
  scheme['trace'] = "\e[38;5;33m"
119
194
  scheme['fatal'] = "\e[38;5;89m"
120
195
  scheme['todo'] = "\e[38;5;55m"
121
196
  lcs.scheme scheme
122
- @config = @options.dup
123
- @config[:log_opts] = lambda{|mlll| {
197
+ @config = @options.dup
198
+ @config[:log_opts] = lambda {|mlll| {
124
199
  :pattern => "%#{mlll}l: %m %g\n",
125
200
  :date_pattern => '%Y-%m-%d %H:%M:%S',
126
201
  :color_scheme => 'compiler',
@@ -130,27 +205,10 @@ module DLDInternet
130
205
  # :level => @config[:log_level],
131
206
  }
132
207
  }
133
- @config[:log_levels] ||= LOG_LEVELS
208
+ @config[:log_levels] ||= LOG_LEVELS
134
209
  @options[:log_config] = @config
135
210
  # initLogging(@config)
136
211
  @logger = getLogger(@config)
137
-
138
- if @options[:inifile]
139
- @options[:inifile] = File.expand_path(@options[:inifile])
140
- load_inifile
141
- elsif @options[:config]
142
- @options[:config] = File.expand_path(@options[:config])
143
- if @options[:config] =~ /\.ini/i
144
- @options[:inifile] = @options[:config]
145
- load_inifile
146
- else
147
- load_config
148
- end
149
- end
150
- if options[:debug]
151
- @logger.info "Options:\n#{options.ai}"
152
- end
153
-
154
212
  end
155
213
 
156
214
  def abort!(msg)
@@ -233,8 +291,16 @@ module DLDInternet
233
291
  end
234
292
 
235
293
  def command_pre(*args)
294
+ args.flatten!
236
295
  parse_options
237
296
  @logger.info @_invocations.map{ |_,v| v[0]}.join(' ') if options[:verbose]
297
+ command_pre_start_vcr(args)
298
+ end
299
+
300
+ def command_post(rc=0)
301
+ command_post_stop_vcr
302
+ @command_post = true
303
+ rc
238
304
  end
239
305
 
240
306
  def command_out(res, fmtr=nil)
@@ -284,6 +350,45 @@ module DLDInternet
284
350
  super
285
351
  end
286
352
 
353
+ def handle_no_command_error(command, has_namespace = $thor_runner)
354
+ get_logger unless @logger#:nodoc:
355
+ @logger.error "Could not find command #{command.inspect} in #{namespace.inspect} namespace." if has_namespace
356
+ @logger.error "Could not find command #{command.inspect}."
357
+ 1
358
+ end
359
+
360
+ protected
361
+
362
+ def command_pre_start_vcr(*args)
363
+ args.flatten!
364
+ if options[:vcr]
365
+ unless options[:cassette_path].match(%r{^#{File::SEPARATOR}})
366
+ if File.dirname($0).eql?(Dir.pwd)
367
+ @logger.error "Saving fixtures to #{Dir.pwd}!"
368
+ exit 1
369
+ end
370
+ end
371
+
372
+ @vcr_logger ||= ::DLDInternet::Thor::VCR::Logger.new(nil, @logger)
373
+ ::VCR.configure do |config|
374
+ config.cassette_library_dir = options[:cassette_path]
375
+ config.hook_into *options[:stubber]
376
+ config.logger = @vcr_logger
377
+ end
378
+ opts = args[0].is_a?(Hash) ? args.shift : {}
379
+ options[:cassette] ||= @_invocations.map{ |_,v| v[0]}.join('-')
380
+ @cassette = ::VCR.insert_cassette(opts[:cassette] || options[:cassette], match_requests_on: [:method,:uri,:headers,:body], record: options[:record_mode])
381
+ end
382
+ yield if block_given?
383
+ end
384
+
385
+ def command_post_stop_vcr
386
+ if options[:vcr]
387
+ ::VCR.eject_cassette
388
+ @cassette = nil
389
+ @vcr_logger = nil
390
+ end
391
+ end
287
392
  end
288
393
  end
289
394
  end
@@ -0,0 +1,20 @@
1
+ require 'vcr'
2
+ require 'dldinternet/thor/vcr/logger'
3
+
4
+
5
+ module VCR
6
+ class Configuration
7
+
8
+ attr_accessor :logger
9
+
10
+ end
11
+ end
12
+
13
+ module VCR
14
+ # The media VCR uses to store HTTP interactions for later re-use.
15
+ class Cassette
16
+
17
+ attr_reader :options
18
+
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ require 'vcr/util/logger'
2
+
3
+ module DLDInternet
4
+ module Thor
5
+ module VCR
6
+ class Logger < ::VCR::Logger
7
+ attr_reader :options
8
+
9
+ def initialize(stream, logger=nil, options = {})
10
+ super(stream)
11
+ @logger = logger
12
+ @options = options
13
+ end
14
+
15
+ def log(message, log_prefix, indentation_level = 0)
16
+ indentation = ' ' * indentation_level
17
+ log_message = indentation + log_prefix + message
18
+ @logger.debug(log_message)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,7 +1,7 @@
1
1
  module Dldinternet
2
2
  module Mixlib
3
3
  module Thor
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
 
6
6
  module Version # :nodoc: all
7
7
  MAJOR, MINOR, RELEASE, *OTHER = VERSION.split '.'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dldinternet-mixlib-thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christo De Lange
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2017-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.19'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '0'
22
+ version: 0.19.4
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.19'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: 0.19.4
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: awesome_print
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -134,6 +134,46 @@ dependencies:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
+ - !ruby/object:Gem::Dependency
138
+ name: vcr
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '3.0'
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: 3.0.3
147
+ type: :runtime
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '3.0'
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: 3.0.3
157
+ - !ruby/object:Gem::Dependency
158
+ name: activesupport
159
+ requirement: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - "~>"
162
+ - !ruby/object:Gem::Version
163
+ version: '5.1'
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 5.1.4
167
+ type: :runtime
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '5.1'
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: 5.1.4
137
177
  - !ruby/object:Gem::Dependency
138
178
  name: bundler
139
179
  requirement: !ruby/object:Gem::Requirement
@@ -198,7 +238,10 @@ files:
198
238
  - lib/dldinternet/formatters/errors.rb
199
239
  - lib/dldinternet/formatters/table.rb
200
240
  - lib/dldinternet/thor/command.rb
241
+ - lib/dldinternet/thor/dynamic_command.rb
201
242
  - lib/dldinternet/thor/mixins/no_commands.rb
243
+ - lib/dldinternet/thor/vcr.rb
244
+ - lib/dldinternet/thor/vcr/logger.rb
202
245
  - lib/dldinternet/thor/version.rb
203
246
  homepage: https://rubygems.org/gems/dldinternet-mixlib-thor
204
247
  licenses: