eac_cli 0.12.2 → 0.12.3

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
  SHA256:
3
- metadata.gz: 90408a7ab93c85784cf6f5946a034567a222ecbfb66922903302ab50a5a38d94
4
- data.tar.gz: 87f6ab796eb1c6734fa615500cb5d7721d3fb1477ce7059bf7da434f60543b01
3
+ metadata.gz: fdd062e7481cd022e3706681b1fccae579efc2ecab9378cca76871008d75d89f
4
+ data.tar.gz: b33f0432da0acd199ff02df511708a9eb56423d5b3fbc2a784b340a8eace9748
5
5
  SHA512:
6
- metadata.gz: a9a941471808a3827ff4edc8bf6f3e3533e174a62078895514e90fbb32ec53db5f4284da379357fc2bfe64edae36646400688df4386d7344c0cfb087a7887544
7
- data.tar.gz: d9e54da85eb7487bba85a30550ffd32065d7b419c5384c81d9724b6d33d0385791b9d0bd07b5733e391fd0030faf59d9b21a9a7ff2c91a384bcfcc4b0d1cff94
6
+ metadata.gz: 60b05d12fb2ea5c787193575a10fac4bead0f9177a75cf39e9dcbefe230d033412b58e2f164112eea1b2add9a95b55f8caf8f7d74831f79e0aa09f6c6889dcb8
7
+ data.tar.gz: c4b0d9cf8829b9c18a2d67e7986f187e1797fd7bc6448435534218b9bfa9be3e574adc6a1b3d278a016dc6194b8cbaf569a35f6025f2c0a036cd69ec4b54a420
@@ -12,12 +12,14 @@ module EacCli
12
12
 
13
13
  def parsed_uncached
14
14
  raise 'Definition has no alternatives' if alternatives.empty?
15
+ raise first_error unless alternatives.select(&:success?).any?
15
16
 
16
- alternatives.each do |alt_parser|
17
- return alt_parser.parsed unless alt_parser.error?
18
- end
17
+ alternatives_parsed(true).merge(alternatives_parsed(false))
18
+ end
19
19
 
20
- raise first_error
20
+ def alternatives_parsed(error)
21
+ alternatives.select { |a| error == a.error? }.map(&:parsed).reverse
22
+ .inject(::EacRubyUtils::Struct.new) { |a, e| a.merge(e) }
21
23
  end
22
24
 
23
25
  def alternatives_uncached
@@ -22,6 +22,10 @@ module EacCli
22
22
  error.present?
23
23
  end
24
24
 
25
+ def success?
26
+ !error?
27
+ end
28
+
25
29
  def parsed
26
30
  @parsed ||= collector.to_data.freeze
27
31
  end
@@ -44,6 +44,8 @@ module EacCli
44
44
  extend AfterClassMethods
45
45
  include InstanceMethods
46
46
  ::EacCli::Docopt::RunnerExtension.check(self)
47
+ include ActiveSupport::Callbacks
48
+ define_callbacks :run
47
49
  end
48
50
 
49
51
  module AfterClassMethods
@@ -55,8 +57,7 @@ module EacCli
55
57
 
56
58
  def run(*runner_context_args)
57
59
  r = create(*runner_context_args)
58
- r.parsed
59
- r.run
60
+ r.run_run
60
61
  r
61
62
  end
62
63
 
@@ -72,6 +73,13 @@ module EacCli
72
73
  end
73
74
 
74
75
  module InstanceMethods
76
+ def run_run
77
+ parsed
78
+ run_callbacks(:run) { run }
79
+ rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
80
+ # Do nothing
81
+ end
82
+
75
83
  def runner_context
76
84
  return @runner_context if @runner_context
77
85
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module Runner
5
+ class Exit < ::StandardError
6
+ attr_reader :status
7
+
8
+ def initialize(status = true)
9
+ @status = status
10
+ end
11
+ end
12
+ end
13
+ end
@@ -13,6 +13,21 @@ module EacCli
13
13
  options_argument false
14
14
  bool_opt '-h', '--help', 'Show help.', usage: true
15
15
  end
16
+
17
+ set_callback :run, :before do
18
+ help_run
19
+ end
20
+ end
21
+
22
+ def help_run
23
+ return unless parsed.help?
24
+
25
+ puts help_text
26
+ raise ::EacCli::Runner::Exit
27
+ end
28
+
29
+ def help_text
30
+ ::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
16
31
  end
17
32
  end
18
33
  end
@@ -44,7 +44,7 @@ module EacCli
44
44
 
45
45
  def run_with_subcommand
46
46
  if subcommand_name
47
- subcommand_runner.run
47
+ subcommand_runner.run_run
48
48
  else
49
49
  run_without_subcommand
50
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.12.2'
4
+ VERSION = '0.12.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-05 00:00:00.000000000 Z
11
+ date: 2020-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.50'
19
+ version: '0.55'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.50'
26
+ version: '0.55'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: eac_ruby_gem_support
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -77,6 +77,7 @@ files:
77
77
  - lib/eac_cli/patches/object/runner_with.rb
78
78
  - lib/eac_cli/runner.rb
79
79
  - lib/eac_cli/runner/context.rb
80
+ - lib/eac_cli/runner/exit.rb
80
81
  - lib/eac_cli/runner_with.rb
81
82
  - lib/eac_cli/runner_with/help.rb
82
83
  - lib/eac_cli/runner_with/output_file.rb