baf 0.12.0 → 0.13.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: 7c878d63bf70ca36b0bd43debe7273fc91519af8
4
- data.tar.gz: 025664c475f918487385db132eda3a72f1c86fb3
3
+ metadata.gz: 4b953e86f4f36c48b3401c8415ebad766276a775
4
+ data.tar.gz: b25cb6a092dc3d54fae9696a8104fde2ff25b7c7
5
5
  SHA512:
6
- metadata.gz: db69b563b42dec2cc38203eb2a8d0bc1b50224ad01e610118ff4c3257b1a2f1cf87286f6b9eee878fa3b1a2bf2ea4de72e4ae48715b718fdf0c1069c37601c19
7
- data.tar.gz: 521eb1afa2711fa730b8ff1b22162c85c070dc82bfa73d6b9364238b81b97e70ed9a34c0476cdd3ca38a2f0a39ebd9110ce9976c1b02791f90f444675cc3afd7
6
+ metadata.gz: 357dde19820d28cbffabe4f9edc9ba71992af6c341214c74c815db8978e989415f56f6ef8ddc6fee6a8a33c1ba4a5a09e409e82fb9800ce9203e03f26790919e
7
+ data.tar.gz: 0a1bc15eab8fb67eab0b0baa1a3bdd9e4c13a93ff364fcc9e16dedc2ca36ef2d698b2678d44e5208f85fd929dc8388f088ffd2c6fda3ebdc1512c1d423fd6720
data/lib/baf.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Baf
2
- Error = Class.new(::StandardError)
3
- ArgumentError = Class.new(Error)
2
+ Error = Class.new ::StandardError
3
+ ArgumentError = Class.new Error
4
4
  end
@@ -8,30 +8,39 @@ require 'baf/options_registrant'
8
8
 
9
9
  module Baf
10
10
  class CLI
11
- ArgumentError = Class.new(::Baf::ArgumentError)
11
+ ArgumentError = Class.new ::Baf::ArgumentError
12
12
 
13
13
  EX_USAGE = 64
14
14
  EX_SOFTWARE = 70
15
15
 
16
16
  class << self
17
17
  def run arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr
18
- cli = new env_class.new(input: stdin, output: stdout), arguments
18
+ cli = new env = build_env(stdin, stdout, stderr), arguments
19
19
  cli.parse_arguments!
20
20
  cli.run
21
21
  rescue ArgumentError => e
22
22
  stderr.puts e
23
23
  exit EX_USAGE
24
24
  rescue StandardError => e
25
- stderr.puts "#{e.class.name}: #{e}"
26
- stderr.puts e.backtrace.map { |l| ' %s' % l }
25
+ if respond_to? :handle_error
26
+ status = handle_error cli.env, e
27
+ exit status if status.respond_to? :to_int
28
+ else
29
+ stderr.puts "#{e.class.name}: #{e}"
30
+ stderr.puts e.backtrace.map { |l| ' %s' % l }
31
+ end
27
32
  exit EX_SOFTWARE
28
33
  end
29
34
 
30
35
  private
31
36
 
37
+ def build_env stdin, stdout, stderr
38
+ env_class.new input: stdin, output: stdout, output_error: stderr
39
+ end
40
+
32
41
  def env_class
33
42
  return Env unless parent_name = name =~ /::[^:]+\Z/ ? $` : nil
34
- parent = Object.const_get(parent_name)
43
+ parent = Object.const_get parent_name
35
44
  parent.const_defined?(:Env) ? parent.const_get(:Env) : Env
36
45
  end
37
46
  end
@@ -5,10 +5,12 @@ module Baf
5
5
  extend Forwardable
6
6
  def_delegators :@input, :gets
7
7
  def_delegators :@output, :print, :puts
8
+ def_delegator :@output_error, :puts, :puts_error
8
9
 
9
- def initialize input: $input, output: $stdout
10
- @input = input
11
- @output = output
10
+ def initialize input: $input, output: $stdout, output_error: $stderr
11
+ @input = input
12
+ @output = output
13
+ @output_error = output_error
12
14
  end
13
15
  end
14
16
  end
@@ -33,7 +33,7 @@ def wait_until message: 'condition not met after %d seconds'
33
33
  timeout = ENV.key?('BAF_TEST_TIMEOUT') ?
34
34
  ENV['BAF_TEST_TIMEOUT'].to_i :
35
35
  2
36
- Timeout.timeout(timeout) do
36
+ Timeout.timeout timeout do
37
37
  loop do
38
38
  break if yield
39
39
  sleep 0.05
@@ -45,7 +45,7 @@ end
45
45
 
46
46
 
47
47
  Then /^the output will match \/([^\/]+)\/([a-z]*)$/ do |pattern, options|
48
- wait_output! build_regexp(pattern, options)
48
+ wait_output! build_regexp pattern, options
49
49
  end
50
50
 
51
51
  Then /^the output will contain:$/ do |content|
@@ -1,3 +1,3 @@
1
1
  module Baf
2
- VERSION = '0.12.0'.freeze
2
+ VERSION = '0.13.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-11 00:00:00.000000000 Z
11
+ date: 2017-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: baf-testing
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 2.6.12
79
+ rubygems_version: 2.6.14
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Basic Application Framework