baf 0.10.0 → 0.14.1

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
- SHA1:
3
- metadata.gz: 68a55ae3de806571fd45ae9d85c810a34e831b50
4
- data.tar.gz: 3cf2f785dd185410dfdbed6c695b7bb3b02c3d17
2
+ SHA256:
3
+ metadata.gz: 9311e4cba4d27aee336f9983d97efd78d8296b5672ec1dccc3337056b66ba620
4
+ data.tar.gz: a9ba3e9ab48e78e71173faaa63eece4addadcc9573e28ea6d3b19adbe6fc41c9
5
5
  SHA512:
6
- metadata.gz: 6123ed05f4dc3999b15c9e55f930d5e4151cbd6078c726b01e9a6fe920a00f71b67e4023fa8a4599a4d5e2375752cd462dd31a5c3d22075abaedc7aed697e971
7
- data.tar.gz: 2a133158337ee65a02accb9654e94fb9c388342322a0feaffcd4eee507eac8cac2faa39867facc2425adf1f66cf0ff8f62b644a94caafd9bc68795ade0fe7710
6
+ metadata.gz: 7aeeb1da2a0f359a5a537580ab13384b3cba5501a6c00722c0f025760eb4c31c951ddf0616410138520bd2457972386dd1bf9bd976259aa271d6365187a0d6e7
7
+ data.tar.gz: 74267eaf156de24338b988e46960565cb1eefc6dc5b241ccb1dba4db022ed6bd313f5932d944833ab010f858b314daeb3145318e01a8a6b52925e730f753f1af
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,41 +8,52 @@ 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
- EX_USAGE = 64
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
46
+
47
+ def ruby2_keywords *; end unless Module.respond_to? :ruby2_keywords, true
37
48
  end
38
49
 
39
50
  attr_reader :arguments, :env, :parser
40
51
 
41
52
  def initialize env, arguments, **opts
42
- @env = env
43
- @arguments = arguments
44
- @parser = opts[:parser] || OptionParser.new
45
- @registrant = opts[:registrant] || OptionsRegistrant.new
53
+ @env = env
54
+ @arguments = arguments
55
+ @parser = opts.fetch(:parser) { OptionParser.new }
56
+ @registrant = opts.fetch(:registrant) { OptionsRegistrant.new }
46
57
 
47
58
  registrant.register(env, parser) { setup }
48
59
  end
@@ -54,6 +65,7 @@ module Baf
54
65
  registrant.banner = arg
55
66
  end
56
67
 
68
+ ruby2_keywords \
57
69
  def flag *args
58
70
  registrant.flag *args
59
71
  end
@@ -71,15 +83,19 @@ module Baf
71
83
  tail: true
72
84
  end
73
85
 
74
- def option *args
75
- args = [*args, Proc.new] if block_given?
86
+ def option *args, &block
87
+ args = [*args, block] if block_given?
76
88
  registrant.option *args
77
89
  end
78
90
 
79
91
  def parse_arguments!
80
92
  parser.parse! arguments
81
93
  rescue OptionParser::InvalidOption
82
- raise ArgumentError, parser
94
+ fail ArgumentError, parser
95
+ end
96
+
97
+ def usage!
98
+ fail ArgumentError, parser
83
99
  end
84
100
 
85
101
  def run
@@ -5,10 +5,20 @@ 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
10
+ def initialize input: $stdin, output: $stdout, output_error: $stderr
11
+ @input = input
11
12
  @output = output
13
+ @output_error = output_error
12
14
  end
15
+
16
+ def sync_output
17
+ output.sync = true
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :output
13
23
  end
14
24
  end
@@ -41,20 +41,20 @@ module Baf
41
41
 
42
42
  def build_attrs short, long, arg_or_desc = nil, desc_or_block = nil, block = nil
43
43
  {
44
- short: short,
45
- long: long,
46
- desc: arg_or_desc
44
+ short: short,
45
+ long: long,
46
+ desc: arg_or_desc
47
47
  }.merge case desc_or_block
48
48
  when Proc
49
49
  {
50
- desc: arg_or_desc,
51
- block: desc_or_block
50
+ desc: arg_or_desc,
51
+ block: desc_or_block
52
52
  }
53
53
  when String
54
54
  {
55
- arg: arg_or_desc,
56
- desc: desc_or_block,
57
- block: block
55
+ arg: arg_or_desc,
56
+ desc: desc_or_block,
57
+ block: block
58
58
  }
59
59
  else
60
60
  {}
@@ -14,6 +14,10 @@ def expect_output content, stream: :output
14
14
  end
15
15
 
16
16
 
17
+ Then /^the output must be empty$/ do
18
+ expect(last_command_started.output).to be_empty
19
+ end
20
+
17
21
  Then /^the output must contain:$/ do |content|
18
22
  expect(last_command_started.output).to include unescape_text content
19
23
  end
@@ -33,19 +33,19 @@ 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
40
40
  end
41
41
  end
42
42
  rescue Timeout::Error
43
- raise Baf::Testing::WaitError.new(message % timeout, timeout)
43
+ fail Baf::Testing::WaitError.new(message % timeout, timeout)
44
44
  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.10.0'.freeze
2
+ VERSION = '0.14.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-23 00:00:00.000000000 Z
11
+ date: 2020-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: baf-testing
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
@@ -60,7 +60,7 @@ homepage: https://rubygems.org/gems/baf
60
60
  licenses:
61
61
  - BSD-3-Clause
62
62
  metadata: {}
63
- post_install_message:
63
+ post_install_message:
64
64
  rdoc_options: []
65
65
  require_paths:
66
66
  - lib
@@ -75,9 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.6.11
80
- signing_key:
78
+ rubygems_version: 3.1.4
79
+ signing_key:
81
80
  specification_version: 4
82
81
  summary: Basic Application Framework
83
82
  test_files: []