ehbrs-tools 0.16.0 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/tools/version.rb +1 -1
  3. data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
  4. data/vendor/aranha-parsers/Gemfile +5 -0
  5. data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
  6. data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
  7. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
  8. data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
  9. data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
  10. data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
  11. data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
  12. data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
  13. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
  14. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
  15. data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
  16. data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
  17. data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
  18. data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
  19. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
  20. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
  21. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
  22. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
  23. data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
  24. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +70 -0
  25. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
  26. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
  27. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
  28. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
  29. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
  30. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
  31. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
  32. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
  33. data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
  34. data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
  35. data/vendor/eac_cli/lib/eac_cli/definition.rb +14 -4
  36. data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
  37. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +15 -2
  38. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +4 -63
  39. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  40. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
  41. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  42. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  43. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +7 -2
  44. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  45. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  46. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  47. metadata +38 -2
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/source_address'
4
+
5
+ RSpec.describe ::Aranha::Parsers::SourceAddress do
6
+ describe '#detect_sub' do
7
+ {
8
+ { method: :post, url: 'http://postdata.net', params: { key1: :value1 } } => {
9
+ klass: ::Aranha::Parsers::SourceAddress::HashHttpPost,
10
+ url: 'http://postdata.net',
11
+ serialization: <<~SERIALIZATION
12
+ --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
13
+ method: :post
14
+ url: http://postdata.net
15
+ params: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
16
+ key1: :value1
17
+ SERIALIZATION
18
+ },
19
+ { method: :get, url: 'http://getdata.net', params: { headers: %w[abc] } } => {
20
+ klass: ::Aranha::Parsers::SourceAddress::HashHttpPost,
21
+ url: 'http://getdata.net',
22
+ serialization: <<~SERIALIZATION
23
+ --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
24
+ method: :get
25
+ url: http://getdata.net
26
+ params: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
27
+ headers:
28
+ - abc
29
+ SERIALIZATION
30
+ },
31
+ 'http://postdata.net' => {
32
+ klass: ::Aranha::Parsers::SourceAddress::HttpGet,
33
+ url: 'http://postdata.net',
34
+ serialization: 'http://postdata.net'
35
+ },
36
+ 'https://getdata.com.br' => {
37
+ klass: ::Aranha::Parsers::SourceAddress::HttpGet,
38
+ url: 'https://getdata.com.br',
39
+ serialization: 'https://getdata.com.br'
40
+ },
41
+ 'file:///postdata.net' => {
42
+ klass: ::Aranha::Parsers::SourceAddress::File,
43
+ url: 'file:///postdata.net',
44
+ serialization: 'file:///postdata.net'
45
+ },
46
+ '/postdata.net' => {
47
+ klass: ::Aranha::Parsers::SourceAddress::File,
48
+ url: 'file:///postdata.net',
49
+ serialization: 'file:///postdata.net'
50
+ }
51
+ }.each do |source, expected|
52
+ context "when source is #{source}" do
53
+ let(:sub) { described_class.detect_sub(source) }
54
+ let(:deserialized) { described_class.deserialize(sub.serialize).sub }
55
+
56
+ it "sub is a #{expected.fetch(:klass)}" do
57
+ expect(sub).to be_a(expected.fetch(:klass))
58
+ end
59
+
60
+ it "sub #{expected.fetch(:klass)} return properly URL" do
61
+ expect(sub.url).to eq(expected.fetch(:url))
62
+ end
63
+
64
+ it "sub #{expected.fetch(:klass)} serialize properly" do
65
+ expect(sub.serialize).to eq(expected.fetch(:serialization))
66
+ end
67
+
68
+ it 'deserialize properly' do
69
+ expect(deserialized).to eq(sub)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/source_target_fixtures'
4
+
5
+ RSpec.describe ::Aranha::Parsers::SourceTargetFixtures do
6
+ let(:fixtures_dir) { ::File.join(__dir__, 'source_target_fixtures_spec_files') }
7
+ let(:instance) { described_class.new(fixtures_dir) }
8
+
9
+ describe '#source_target_files' do
10
+ it { expect(instance.source_target_files.count).to eq(3) }
11
+
12
+ (1..3).each do |index|
13
+ basename = "stub#{index}"
14
+ let(basename) { instance.source_target_files.find { |stf| stf.basename == basename } }
15
+
16
+ it { expect(send(basename)).to be_present }
17
+ it { expect(send(basename).basename).to eq(basename) }
18
+ end
19
+
20
+ it { expect(stub1.source).to eq(::File.join(fixtures_dir, 'stub1.source.txt')) }
21
+ it { expect(stub1.target).to eq(::File.join(fixtures_dir, 'stub1.target.html')) }
22
+ it { expect(stub2.source).to eq(::File.join(fixtures_dir, 'stub2.source.html')) }
23
+ it { expect(stub2.target).to eq(nil) }
24
+ it { expect(stub3.source).to eq(nil) }
25
+ it { expect(stub3.target).to eq(::File.join(fixtures_dir, 'stub3.target.yaml')) }
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gem_support/spec/examples/rubocop_check'
4
+
5
+ RSpec.describe ::RuboCop do
6
+ include_examples 'rubocop_check', ::File.expand_path('../..', __dir__)
7
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __dir__)
4
+ require 'tmpdir'
5
+
6
+ RSpec.configure do |config|
7
+ config.example_status_persistence_file_path = ::File.join(::Dir.tmpdir, 'aranha-parsers_rspec')
8
+ end
@@ -45,6 +45,10 @@ module EacCli
45
45
  self.description = description
46
46
  end
47
47
 
48
+ def help_formatter
49
+ @help_formatter ||= ::EacCli::Definition::HelpFormatter.new(self)
50
+ end
51
+
48
52
  def options_arg(options_argument)
49
53
  self.options_argument = options_argument
50
54
  end
@@ -54,17 +58,23 @@ module EacCli
54
58
  end
55
59
 
56
60
  def pos_arg(name, arg_options = {})
57
- raise 'Positional arguments are blocked' if positional_arguments_blocked?
61
+ new_pos_arg = ::EacCli::Definition::PositionalArgument.new(name, arg_options)
62
+ raise 'Positional arguments are blocked' if positional_arguments_blocked?(new_pos_arg)
58
63
 
59
- pos_set << ::EacCli::Definition::PositionalArgument.new(name, arg_options)
64
+ pos_set << new_pos_arg
60
65
  end
61
66
 
62
67
  def positional
63
68
  pos_set.to_a
64
69
  end
65
70
 
66
- def positional_arguments_blocked?
67
- pos_set.any? { |e| e.optional? || e.repeat? }
71
+ def positional_arguments_blocked?(new_pos_arg)
72
+ last = pos_set.last
73
+ return false unless last
74
+ return true if last.repeat?
75
+ return true if last.optional? && new_pos_arg.required?
76
+
77
+ false
68
78
  end
69
79
 
70
80
  def subcommands
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ class Definition
7
+ class HelpFormatter
8
+ SEP = ' '
9
+ IDENT = SEP * 2
10
+ OPTION_DESC_SEP = IDENT * 2
11
+
12
+ class << self
13
+ def option_long(option)
14
+ b = option.long
15
+ b += '=VALUE' if option.argument?
16
+ b
17
+ end
18
+
19
+ def option_short(option)
20
+ b = option.short
21
+ b += 'VALUE' if option.argument?
22
+ b
23
+ end
24
+ end
25
+
26
+ common_constructor :definition
27
+
28
+ def positional_argument(positional)
29
+ if positional.subcommand?
30
+ ::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
31
+ else
32
+ r = "<#{positional.name}>"
33
+ r += '...' if positional.repeat?
34
+ r = "[#{r}]" if positional.optional?
35
+ r
36
+ end
37
+ end
38
+
39
+ def section(header, include_header = true)
40
+ b = include_header ? "#{header.humanize}:\n" : ''
41
+ b += send("self_#{header}") + "\n"
42
+ # TO-DO: implement alternatives
43
+ b
44
+ end
45
+
46
+ def self_options
47
+ definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
48
+ end
49
+
50
+ def self_usage
51
+ IDENT + self_usage_arguments.join(SEP)
52
+ end
53
+
54
+ def self_usage_arguments
55
+ [::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
56
+ definition.options_argument.if_present([]) { |_v| ['[options]'] } +
57
+ self_usage_arguments_options +
58
+ self_usage_arguments_positional
59
+ end
60
+
61
+ def self_usage_arguments_options
62
+ definition.options.select(&:show_on_usage?).map do |option|
63
+ self.class.option_long(option)
64
+ end
65
+ end
66
+
67
+ def self_usage_arguments_positional
68
+ definition.positional.map { |p| positional_argument(p) }
69
+ end
70
+
71
+ def to_banner
72
+ "#{definition.description}\n\n#{section('usage')}"
73
+ end
74
+ end
75
+ end
76
+ end
@@ -5,8 +5,10 @@ require 'eac_ruby_utils/core_ext'
5
5
  module EacCli
6
6
  class Definition
7
7
  class PositionalArgument
8
+ DEFAULT_REQUIRED = true
9
+
8
10
  enable_listable
9
- lists.add_symbol :option, :optional, :repeat, :subcommand
11
+ lists.add_symbol :option, :optional, :repeat, :required, :subcommand
10
12
  common_constructor :name, :options, default: [{}] do
11
13
  options.assert_valid_keys(self.class.lists.option.values)
12
14
  end
@@ -16,16 +18,27 @@ module EacCli
16
18
  end
17
19
 
18
20
  def optional?
19
- options[OPTION_OPTIONAL]
21
+ !required?
20
22
  end
21
23
 
22
24
  def repeat?
23
25
  options[OPTION_REPEAT]
24
26
  end
25
27
 
28
+ def required?
29
+ return true if options.key?(OPTION_REQUIRED) && options.fetch(OPTION_REQUIRED)
30
+ return false if options.key?(OPTION_OPTIONAL) && options.fetch(OPTION_OPTIONAL)
31
+
32
+ DEFAULT_REQUIRED
33
+ end
34
+
26
35
  def subcommand?
27
36
  options[OPTION_SUBCOMMAND]
28
37
  end
38
+
39
+ def to_s
40
+ "#{self.class.name.demodulize}[#{identifier}]"
41
+ end
29
42
  end
30
43
  end
31
44
  end
@@ -6,10 +6,6 @@ require 'optparse'
6
6
  module EacCli
7
7
  class Parser
8
8
  class OptionsCollection
9
- SEP = ' '
10
- IDENT = SEP * 2
11
- OPTION_DESC_SEP = IDENT * 2
12
-
13
9
  enable_simple_cache
14
10
  common_constructor(:definition, :argv, :collector) { collect }
15
11
  attr_reader :arguments
@@ -49,7 +45,7 @@ module EacCli
49
45
  end
50
46
 
51
47
  def build_banner
52
- option_parser.banner = "#{definition.description}\n\n#{section('usage')}"
48
+ option_parser.banner = definition.help_formatter.to_banner
53
49
  end
54
50
 
55
51
  def build_options
@@ -60,68 +56,13 @@ module EacCli
60
56
 
61
57
  def build_option(option)
62
58
  option_parser.on(
63
- *[option_short(option), option_long(option), option.description].reject(&:blank?)
59
+ *[::EacCli::Definition::HelpFormatter.option_short(option),
60
+ ::EacCli::Definition::HelpFormatter.option_long(option),
61
+ option.description].reject(&:blank?)
64
62
  ) do |value|
65
63
  collector.collect(option, value)
66
64
  end
67
65
  end
68
-
69
- def positional_argument(positional)
70
- if positional.subcommand?
71
- ::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
72
- else
73
- r = "<#{positional.name}>"
74
- r += '...' if positional.repeat?
75
- r = "[#{r}]" if positional.optional?
76
- r
77
- end
78
- end
79
-
80
- def option_argument(option)
81
- option_long(option)
82
- end
83
-
84
- def option_long(option)
85
- b = option.long
86
- b += '=VALUE' if option.argument?
87
- b
88
- end
89
-
90
- def option_short(option)
91
- b = option.short
92
- b += 'VALUE' if option.argument?
93
- b
94
- end
95
-
96
- def section(header, include_header = true)
97
- b = include_header ? "#{header.humanize}:\n" : ''
98
- b += send("self_#{header}") + "\n"
99
- # TO-DO: implement alternatives
100
- b
101
- end
102
-
103
- def self_options
104
- definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
105
- end
106
-
107
- def self_usage
108
- IDENT + self_usage_arguments.join(SEP)
109
- end
110
-
111
- def self_usage_arguments
112
- [::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
113
- definition.options_argument.if_present([]) { |_v| ['[options]'] } +
114
- self_usage_arguments_options +
115
- self_usage_arguments_positional
116
- end
117
-
118
- def self_usage_arguments_options
119
- definition.options.select(&:show_on_usage?).map { |option| option_argument(option) }
120
- end
121
-
122
- def self_usage_arguments_positional
123
- definition.positional.map { |p| positional_argument(p) }
124
- end
125
66
  end
126
67
  end
127
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.10.0'
4
+ VERSION = '0.11.1'
5
5
  end
@@ -11,18 +11,10 @@ module EacRubyUtils
11
11
 
12
12
  class << self
13
13
  def entry_key_to_envvar_name(entry_key)
14
- path = if entry_key.is_a?(::Array)
15
- entry_key
16
- else
17
- ::EacRubyUtils::PathsHash.parse_entry_key(entry_key)
18
- end
19
- path.join('_').gsub(/[^a-z0-9_]/i, '').gsub(/\A_+/, '').gsub(/_+\z/, '')
20
- .gsub(/_{2,}/, '_').upcase
14
+ ::EacRubyUtils::Console::Configs::EntryReader.entry_key_to_envvar_name(entry_key)
21
15
  end
22
16
  end
23
17
 
24
- STORE_PASSWORDS_KEY = 'core.store_passwords'
25
-
26
18
  attr_reader :configs
27
19
 
28
20
  def initialize(configs_key, options = {})
@@ -31,72 +23,15 @@ module EacRubyUtils
31
23
  end
32
24
 
33
25
  def read_password(entry_key, options = {})
34
- options = ReadEntryOptions.new(options.merge(noecho: true))
35
- if store_passwords?
36
- read_entry(entry_key, options)
37
- else
38
- looped_entry_value_from_input(entry_key, options)
39
- end
26
+ ::EacRubyUtils::Console::Configs::PasswordEntryReader.new(self, entry_key, options).read
40
27
  end
41
28
 
42
29
  def read_entry(entry_key, options = {})
43
- options = ReadEntryOptions.new(options)
44
- unless options[:noenv]
45
- envvar_value = envvar_read_entry(entry_key)
46
- return envvar_value if envvar_value.present?
47
- end
48
- stored_value = configs.read_entry(entry_key)
49
- return stored_value if stored_value
50
- return read_entry_from_console(entry_key, options) unless options[:noinput]
51
-
52
- raise "No value found for entry \"#{entry_key}\"" if options[:required]
30
+ ::EacRubyUtils::Console::Configs::EntryReader.new(self, entry_key, options).read
53
31
  end
54
32
 
55
33
  def store_passwords?
56
- read_entry(
57
- STORE_PASSWORDS_KEY,
58
- before_input: -> { store_password_banner },
59
- validator: ->(entry_value) { %w[yes no].include?(entry_value) }
60
- ) == 'yes'
61
- end
62
-
63
- protected
64
-
65
- def envvar_read_entry(entry_key)
66
- env_entry_key = self.class.entry_key_to_envvar_name(entry_key)
67
- return nil unless ENV.key?(env_entry_key)
68
-
69
- ENV.fetch(env_entry_key).if_present(::EacRubyUtils::BlankNotBlank.instance)
70
- end
71
-
72
- def read_entry_from_console(entry_key, options)
73
- options[:before_input].call if options[:before_input].present?
74
- entry_value = looped_entry_value_from_input(entry_key, options)
75
- configs.write_entry(entry_key, entry_value)
76
- entry_value
77
- end
78
-
79
- def store_password_banner
80
- infom 'Do you wanna to store passwords?'
81
- infom "Warning: the passwords will be store in clear text in \"#{configs.storage_path}\""
82
- infom 'Enter "yes" or "no"'
83
- end
84
-
85
- def looped_entry_value_from_input(entry_key, options)
86
- loop do
87
- entry_value = entry_value_from_input(entry_key, options)
88
- next if entry_value.blank?
89
- next if options[:validator] && !options[:validator].call(entry_value)
90
-
91
- return entry_value
92
- end
93
- end
94
-
95
- def entry_value_from_input(entry_key, options)
96
- entry_value = request_input("Value for entry \"#{entry_key}\"",
97
- options.request_input_options)
98
- warn('Entered value is blank') if entry_value.blank?
99
- entry_value
34
+ ::EacRubyUtils::Console::Configs::StorePasswordsEntryReader.new(self) == 'yes'
100
35
  end
101
36
  end
102
37
  end