avm-tools 0.76.1 → 0.81.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/eac_rails_base1/runner/code_runner.rb +1 -2
  3. data/lib/avm/eac_rails_base1/runner/rails_server.rb +33 -0
  4. data/lib/avm/patches/class/i18n.rb +31 -0
  5. data/lib/avm/patches/object/i18n.rb +2 -10
  6. data/lib/avm/projects/stereotypes/ruby_gem/update.rb +4 -1
  7. data/lib/avm/projects/stereotypes/ruby_gem/version_bump.rb +1 -2
  8. data/lib/avm/tools/runner/git/subrepo/clone.rb +84 -0
  9. data/lib/avm/tools/runner/git/subrepo/fix.rb +65 -0
  10. data/lib/avm/tools/version.rb +1 -1
  11. data/template/avm/eac_redmine_base0/deploy/config/install.sh.template +12 -0
  12. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  13. data/vendor/eac_cli/lib/eac_cli/definition.rb +34 -39
  14. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  15. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  16. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  17. data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
  18. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
  19. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  20. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  21. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  22. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  23. data/vendor/eac_cli/lib/eac_cli/runner.rb +12 -4
  24. data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
  25. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +16 -1
  26. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
  27. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +1 -1
  28. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  29. data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
  30. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +10 -0
  31. data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
  32. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +17 -5
  33. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
  34. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  35. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +0 -1
  36. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +32 -1
  37. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +1 -1
  38. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  39. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  40. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
  41. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
  42. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
  43. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
  44. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
  45. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  46. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  47. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +7 -2
  48. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  49. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
  50. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
  51. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
  52. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
  53. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  54. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
  55. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  56. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  57. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  58. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
  59. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
  60. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
  61. metadata +28 -7
  62. data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +0 -36
  63. data/lib/avm/tools/runner/eac_rails_base0/runner.rb +0 -14
  64. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +0 -68
  65. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -38
  66. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -77
@@ -3,7 +3,8 @@
3
3
  require 'eac_ruby_utils/struct'
4
4
 
5
5
  RSpec.describe ::EacRubyUtils::Struct do
6
- let(:instance) { described_class.new(a: 1, b: '') }
6
+ let(:instance) { described_class.new('a' => 1, b: '') }
7
+ let(:other) { described_class.new('a' => 'm1', c: 'm2') }
7
8
 
8
9
  describe '#[]' do
9
10
  it { expect(instance[:a]).to eq(1) }
@@ -35,6 +36,12 @@ RSpec.describe ::EacRubyUtils::Struct do
35
36
  it { expect { instance.fetch('c?') }.to raise_error(::KeyError) }
36
37
  end
37
38
 
39
+ describe '#merge' do
40
+ let(:merged) { instance.merge(other) }
41
+
42
+ it { expect(merged.to_h).to eq(a: 'm1', b: '', c: 'm2') }
43
+ end
44
+
38
45
  describe '#property_method' do
39
46
  it { expect(instance.a).to eq(1) }
40
47
  it { expect(instance.a?).to eq(true) }
@@ -43,4 +50,8 @@ RSpec.describe ::EacRubyUtils::Struct do
43
50
  it { expect { instance.c }.to raise_error(::NoMethodError) }
44
51
  it { expect { instance.c? }.to raise_error(::NoMethodError) }
45
52
  end
53
+
54
+ describe '#to_h' do
55
+ it { expect(instance.to_h).to eq(a: 1, b: '') }
56
+ end
46
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.76.1
4
+ version: 0.81.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2020-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -300,6 +300,7 @@ files:
300
300
  - lib/avm/eac_rails_base1/runner.rb
301
301
  - lib/avm/eac_rails_base1/runner/bundle.rb
302
302
  - lib/avm/eac_rails_base1/runner/code_runner.rb
303
+ - lib/avm/eac_rails_base1/runner/rails_server.rb
303
304
  - lib/avm/eac_rails_base1/runner_with/bundle.rb
304
305
  - lib/avm/eac_redmine_base0.rb
305
306
  - lib/avm/eac_redmine_base0/core_update.rb
@@ -434,6 +435,7 @@ files:
434
435
  - lib/avm/local_projects.rb
435
436
  - lib/avm/local_projects/instance.rb
436
437
  - lib/avm/patches.rb
438
+ - lib/avm/patches/class/i18n.rb
437
439
  - lib/avm/patches/eac_ruby_gems_utils/gem.rb
438
440
  - lib/avm/patches/i18n.rb
439
441
  - lib/avm/patches/object/i18n.rb
@@ -485,8 +487,6 @@ files:
485
487
  - lib/avm/tools/runner.rb
486
488
  - lib/avm/tools/runner/eac_rails_base0.rb
487
489
  - lib/avm/tools/runner/eac_rails_base0/apache_path.rb
488
- - lib/avm/tools/runner/eac_rails_base0/rails_server.rb
489
- - lib/avm/tools/runner/eac_rails_base0/runner.rb
490
490
  - lib/avm/tools/runner/eac_redmine_base0.rb
491
491
  - lib/avm/tools/runner/eac_redmine_base0/core_update.rb
492
492
  - lib/avm/tools/runner/eac_redmine_base0/docker.rb
@@ -507,6 +507,8 @@ files:
507
507
  - lib/avm/tools/runner/git/revisions_test.rb
508
508
  - lib/avm/tools/runner/git/subrepo.rb
509
509
  - lib/avm/tools/runner/git/subrepo/check.rb
510
+ - lib/avm/tools/runner/git/subrepo/clone.rb
511
+ - lib/avm/tools/runner/git/subrepo/fix.rb
510
512
  - lib/avm/tools/runner/instance.rb
511
513
  - lib/avm/tools/runner/instance/info.rb
512
514
  - lib/avm/tools/runner/launcher.rb
@@ -598,31 +600,40 @@ files:
598
600
  - vendor/eac_cli/lib/eac_cli/core_ext.rb
599
601
  - vendor/eac_cli/lib/eac_cli/default_runner.rb
600
602
  - vendor/eac_cli/lib/eac_cli/definition.rb
603
+ - vendor/eac_cli/lib/eac_cli/definition/alternative.rb
601
604
  - vendor/eac_cli/lib/eac_cli/definition/argument_option.rb
602
605
  - vendor/eac_cli/lib/eac_cli/definition/base_option.rb
603
606
  - vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb
604
607
  - vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb
605
608
  - vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
606
609
  - vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb
610
+ - vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb
607
611
  - vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb
608
612
  - vendor/eac_cli/lib/eac_cli/parser.rb
613
+ - vendor/eac_cli/lib/eac_cli/parser/alternative.rb
614
+ - vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb
615
+ - vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb
616
+ - vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb
617
+ - vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb
609
618
  - vendor/eac_cli/lib/eac_cli/parser/collector.rb
610
619
  - vendor/eac_cli/lib/eac_cli/parser/error.rb
611
- - vendor/eac_cli/lib/eac_cli/parser/options_collection.rb
612
- - vendor/eac_cli/lib/eac_cli/parser/parse_result.rb
613
- - vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb
614
620
  - vendor/eac_cli/lib/eac_cli/patches.rb
615
621
  - vendor/eac_cli/lib/eac_cli/patches/object.rb
616
622
  - vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb
617
623
  - vendor/eac_cli/lib/eac_cli/runner.rb
618
624
  - vendor/eac_cli/lib/eac_cli/runner/context.rb
625
+ - vendor/eac_cli/lib/eac_cli/runner/exit.rb
619
626
  - vendor/eac_cli/lib/eac_cli/runner_with.rb
620
627
  - vendor/eac_cli/lib/eac_cli/runner_with/help.rb
621
628
  - vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb
622
629
  - vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb
623
630
  - vendor/eac_cli/lib/eac_cli/version.rb
631
+ - vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb
624
632
  - vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb
633
+ - vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb
625
634
  - vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb
635
+ - vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb
636
+ - vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb
626
637
  - vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb
627
638
  - vendor/eac_cli/spec/rubocop_spec.rb
628
639
  - vendor/eac_cli/spec/spec_helper.rb
@@ -888,18 +899,24 @@ files:
888
899
  - vendor/eac_ruby_utils/README.rdoc
889
900
  - vendor/eac_ruby_utils/eac_ruby_utils.gemspec
890
901
  - vendor/eac_ruby_utils/lib/eac_ruby_utils.rb
902
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb
891
903
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/arguments_consumer.rb
892
904
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb
893
905
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
894
906
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/by_reference.rb
895
907
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb
908
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb
909
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb
896
910
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb
897
911
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb
898
912
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb
899
913
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb
900
914
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/console.rb
901
915
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb
916
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb
917
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb
902
918
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb
919
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb
903
920
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb
904
921
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb
905
922
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_doc.rb
@@ -916,6 +933,8 @@ files:
916
933
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs.rb
917
934
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/base_env.rb
918
935
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb
936
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb
937
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb
919
938
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb
920
939
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb
921
940
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/file.rb
@@ -970,6 +989,7 @@ files:
970
989
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/options_consumer.rb
971
990
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
972
991
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module.rb
992
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb
973
993
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb
974
994
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/console_speaker.rb
975
995
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb
@@ -1019,6 +1039,7 @@ files:
1019
1039
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/hash.rb
1020
1040
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb
1021
1041
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb
1042
+ - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb
1022
1043
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/arguments_consumer_spec.rb
1023
1044
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb
1024
1045
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/eac_rails_base1/runner_with/bundle'
4
- require 'avm/instances/entry_keys'
5
- require 'eac_cli/core_ext'
6
- require 'eac_ruby_utils/console/docopt_runner'
7
- require 'shellwords'
8
-
9
- module Avm
10
- module Tools
11
- class Runner < ::EacRubyUtils::Console::DocoptRunner
12
- class EacRailsBase0 < ::Avm::EacRailsBase1::Runner
13
- class RailsServer
14
- DEFAULT_RAILS_ENVIRONMENT = 'development'
15
- runner_with ::Avm::EacRailsBase1::RunnerWith::Bundle
16
- runner_definition do
17
- desc 'Run the embbeded Rails web server.'
18
- end
19
-
20
- def run
21
- infov 'Environment', rails_environment
22
- infov 'Bundle args', ::Shellwords.join(bundle_args)
23
- infov 'Result', bundle_command.system
24
- end
25
-
26
- protected
27
-
28
- def bundle_args
29
- ['exec', 'rails', 'server', '--port',
30
- runner_context.call(:instance).read_entry(::Avm::Instances::EntryKeys::WEB_PORT)]
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/eac_rails_base1/runner/code_runner'
4
-
5
- module Avm
6
- module Tools
7
- class Runner < ::EacRubyUtils::Console::DocoptRunner
8
- class EacRailsBase0 < ::Avm::EacRailsBase1::Runner
9
- class Runner < ::Avm::EacRailsBase1::Runner::CodeRunner
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
- require 'optparse'
5
-
6
- module EacCli
7
- class Parser
8
- class OptionsCollection
9
- enable_simple_cache
10
- common_constructor(:definition, :argv, :collector) { collect }
11
- attr_reader :arguments
12
-
13
- def options_first?
14
- definition.options_first? || definition.subcommands?
15
- end
16
-
17
- private
18
-
19
- def check_required_options
20
- definition.options.each do |option|
21
- next unless option.required?
22
- next if collector.supplied?(option)
23
-
24
- raise ::EacCli::Parser::Error.new(
25
- definition, argv, "Option \"#{option}\" is required and a value was not supplied"
26
- )
27
- end
28
- end
29
-
30
- def collect
31
- build_banner
32
- build_options
33
- parse_argv
34
- check_required_options
35
- end
36
-
37
- def option_parser_uncached
38
- ::OptionParser.new
39
- end
40
-
41
- def parse_argv
42
- @arguments = options_first? ? option_parser.order(argv) : option_parser.parse(argv)
43
- rescue ::OptionParser::InvalidOption => e
44
- raise ::EacCli::Parser::Error.new(definition, argv, e.message)
45
- end
46
-
47
- def build_banner
48
- option_parser.banner = definition.help_formatter.to_banner
49
- end
50
-
51
- def build_options
52
- definition.options.each do |option|
53
- build_option(option)
54
- end
55
- end
56
-
57
- def build_option(option)
58
- option_parser.on(
59
- *[::EacCli::Definition::HelpFormatter.option_short(option),
60
- ::EacCli::Definition::HelpFormatter.option_long(option),
61
- option.description].reject(&:blank?)
62
- ) do |value|
63
- collector.collect(option, value)
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/parser/error'
4
- require 'eac_ruby_utils/core_ext'
5
-
6
- module EacCli
7
- class Parser
8
- class ParseResult
9
- common_constructor :definition, :argv
10
-
11
- def result
12
- result_or_error = parse(definition)
13
- return result_or_error unless result_or_error.is_a?(::Exception)
14
-
15
- definition.alternatives.each do |alternative|
16
- alt_result_or_error = parse(alternative)
17
- return alt_result_or_error unless alt_result_or_error.is_a?(::Exception)
18
- end
19
-
20
- raise result_or_error
21
- end
22
-
23
- private
24
-
25
- def parse(definition)
26
- ::EacCli::Parser::Collector.to_data(definition) do |collector|
27
- ::EacCli::Parser::PositionalCollection.new(
28
- definition,
29
- ::EacCli::Parser::OptionsCollection.new(definition, argv, collector).arguments,
30
- collector
31
- )
32
- end
33
- rescue ::EacCli::Parser::Error => e
34
- e
35
- end
36
- end
37
- end
38
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
- require 'eac_cli/parser/error'
5
-
6
- module EacCli
7
- class Parser
8
- class PositionalCollection
9
- common_constructor(:definition, :argv, :collector) { collect }
10
-
11
- private
12
-
13
- def argv_enum
14
- @argv_enum ||= argv.each
15
- end
16
-
17
- def argv_pending?
18
- argv_enum.ongoing?
19
- end
20
-
21
- def argv_pending_check
22
- return unless argv_pending?
23
- return unless positional_enum.stopped?
24
-
25
- raise ::EacCli::Parser::Error.new(
26
- definition, argv, "No positional left for argv \"#{argv_enum.current}\""
27
- )
28
- end
29
-
30
- def collected
31
- @collected ||= ::Set.new
32
- end
33
-
34
- def collect
35
- loop do
36
- break unless enums('pending?').any?
37
-
38
- enums('pending_check')
39
- collect_argv_value
40
- end
41
- end
42
-
43
- def collect_argv_value
44
- collector.collect(*enums('enum', &:peek))
45
- collected << positional_enum.peek
46
- positional_enum.next unless positional_enum.peek.repeat?
47
- argv_enum.next
48
- end
49
-
50
- def enums(method_suffix, &block)
51
- %w[positional argv].map do |method_prefix|
52
- v = send("#{method_prefix}_#{method_suffix}")
53
- block ? block.call(v) : v
54
- end
55
- end
56
-
57
- def positional_enum
58
- @positional_enum ||= definition.positional.each
59
- end
60
-
61
- def positional_pending?
62
- !(positional_enum.stopped? || positional_enum.current.optional? ||
63
- collected.include?(positional_enum.current))
64
- end
65
-
66
- def positional_pending_check
67
- return unless positional_pending?
68
- return unless argv_enum.stopped?
69
-
70
- raise ::EacCli::Parser::Error.new(
71
- definition, argv, 'No value for required positional ' \
72
- "\"#{positional_enum.current.identifier}\""
73
- )
74
- end
75
- end
76
- end
77
- end