ehbrs-tools 0.14.0 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs/runner.rb +4 -7
- data/lib/ehbrs/runner/finances.rb +4 -7
- data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
- data/lib/ehbrs/runner/fs.rb +4 -7
- data/lib/ehbrs/runner/fs/used_space.rb +4 -5
- data/lib/ehbrs/runner/google.rb +4 -7
- data/lib/ehbrs/runner/google/translate.rb +7 -12
- data/lib/ehbrs/runner/self.rb +4 -7
- data/lib/ehbrs/runner/self/test.rb +5 -10
- data/lib/ehbrs/runner/vg.rb +4 -7
- data/lib/ehbrs/runner/vg/ips.rb +9 -14
- data/lib/ehbrs/runner/vg/wii.rb +10 -13
- data/lib/ehbrs/runner/videos.rb +3 -5
- data/lib/ehbrs/runner/videos/extract.rb +10 -13
- data/lib/ehbrs/runner/videos/probe.rb +6 -9
- data/lib/ehbrs/runner/videos/series.rb +5 -8
- data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
- data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
- data/lib/ehbrs/runner/web_utils.rb +24 -0
- data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
- data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
- data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
- data/lib/ehbrs/videos/file.rb +4 -8
- data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
- data/lib/ehbrs/videos/track.rb +20 -10
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +2 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +2 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +2 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +2 -0
- data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
- data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +1 -1
- data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
- data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
- data/vendor/aranha-parsers/Gemfile +5 -0
- data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
- data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
- data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
- data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/definition.rb +49 -22
- data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
- data/vendor/eac_cli/lib/eac_cli/{parser/options_collection.rb → definition/help_formatter.rb} +20 -49
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +21 -3
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +88 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
- data/vendor/eac_cli/lib/eac_cli/runner.rb +7 -3
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +19 -2
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +35 -0
- data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +57 -40
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +7 -104
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +46 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
- metadata +78 -7
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner_with/output_file'
|
4
|
+
require 'eac_ruby_utils/fs/temp'
|
5
|
+
|
6
|
+
RSpec.describe ::EacCli::RunnerWith::OutputFile do
|
7
|
+
let(:runner) do
|
8
|
+
the_module = described_class
|
9
|
+
Class.new do
|
10
|
+
include the_module
|
11
|
+
|
12
|
+
runner_definition do
|
13
|
+
desc 'A stub root runner.'
|
14
|
+
pos_arg :input_text
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
run_output
|
19
|
+
end
|
20
|
+
|
21
|
+
def output_content
|
22
|
+
parsed.input_text
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:stub_text) { 'STUB_TEXT' }
|
28
|
+
let(:instance) { runner.create(argv: runner_argv) }
|
29
|
+
|
30
|
+
context 'without --output-file option' do
|
31
|
+
let(:runner_argv) { [stub_text] }
|
32
|
+
|
33
|
+
it do
|
34
|
+
expect { instance.run }.to output(stub_text).to_stdout_from_any_process
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with --output-file option' do
|
39
|
+
let(:output_file) { ::EacRubyUtils::Fs::Temp.file }
|
40
|
+
let(:runner_argv) { ['--output-file', output_file.to_path, stub_text] }
|
41
|
+
|
42
|
+
before do
|
43
|
+
instance.run
|
44
|
+
end
|
45
|
+
|
46
|
+
after do
|
47
|
+
output_file.remove
|
48
|
+
end
|
49
|
+
|
50
|
+
it { expect(output_file).to exist }
|
51
|
+
it { expect(output_file.read).to eq(stub_text) }
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner'
|
4
|
+
require 'eac_cli/runner_with/subcommands'
|
5
|
+
|
6
|
+
RSpec.describe ::EacCli::RunnerWith::Subcommands do
|
7
|
+
let(:parent_runner) do
|
8
|
+
the_module = described_class
|
9
|
+
the_child = child_runner
|
10
|
+
Class.new do
|
11
|
+
include ::EacCli::Runner
|
12
|
+
include the_module
|
13
|
+
const_set('ChildCmd', the_child)
|
14
|
+
|
15
|
+
runner_definition do
|
16
|
+
desc 'A stub root runner.'
|
17
|
+
arg_opt '-r', '--root-var', 'A root variable.'
|
18
|
+
subcommands
|
19
|
+
end
|
20
|
+
|
21
|
+
delegate :root_var, to: :parsed
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:child_runner) do
|
26
|
+
::Class.new do
|
27
|
+
include ::EacCli::Runner
|
28
|
+
|
29
|
+
runner_definition do
|
30
|
+
bool_opt '-c', '--child-opt', 'A boolean option.'
|
31
|
+
pos_arg :child_var
|
32
|
+
end
|
33
|
+
|
34
|
+
def run; end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:instance) { parent_runner.create(argv: parent_argv) }
|
39
|
+
|
40
|
+
context 'when subcommand is supplied' do
|
41
|
+
let(:parent_argv) { %w[--root-var 123 child-cmd --child-opt 456] }
|
42
|
+
|
43
|
+
it { expect(instance.parsed.root_var).to eq('123') }
|
44
|
+
it { expect(instance.parsed.subcommand).to eq('child-cmd') }
|
45
|
+
it { expect(instance.parsed.subcommand_args).to eq(%w[--child-opt 456]) }
|
46
|
+
it { expect(instance.subcommand_runner.parsed.child_opt).to eq(true) }
|
47
|
+
it { expect(instance.subcommand_runner.parsed.child_var).to eq('456') }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when subcommand is not supplied' do
|
51
|
+
let(:instance) { parent_runner.create(%w[456]) }
|
52
|
+
|
53
|
+
it do
|
54
|
+
expect { instance.run }.to raise_error(::EacCli::Parser::Error)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/module/common_concern'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
# Support to abstract methods.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
#
|
10
|
+
# require 'eac_ruby_utils/abstract_methods'
|
11
|
+
#
|
12
|
+
# class BaseClass
|
13
|
+
# include EacRubyUtils::AbstractMethods
|
14
|
+
#
|
15
|
+
# abstract_methods :mymethod
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# BaseClass.new.mymethod # raise "Abstract method: mymethod"
|
19
|
+
#
|
20
|
+
# class SubClass
|
21
|
+
# def mymethod
|
22
|
+
# "Implemented"
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# SubClass.new.mymethod # return "Implemented"
|
27
|
+
module AbstractMethods
|
28
|
+
common_concern
|
29
|
+
|
30
|
+
module ClassMethods
|
31
|
+
def abstract_methods(*methods_names)
|
32
|
+
methods_names.each do |method_name|
|
33
|
+
define_method method_name do
|
34
|
+
raise_abstract_method(method_name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module InstanceMethods
|
41
|
+
def respond_to_missing?(method_name, include_private = false)
|
42
|
+
super || abstract_method?(method_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(method_name, *arguments, &block)
|
46
|
+
raise_abstract_method(method_name) if abstract_method?(method_name)
|
47
|
+
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
def abstract_method?(method_name)
|
52
|
+
self.class.abstract_methods.include?(method_name.to_sym)
|
53
|
+
end
|
54
|
+
|
55
|
+
def raise_abstract_method(method_name)
|
56
|
+
raise ::NoMethodError, "Abstract method \"#{method_name}\" hit in \"#{self}\""
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
# A blank string which returns +false+ for +blank?+ method.
|
8
|
+
class BlankNotBlank < String
|
9
|
+
include ::Singleton
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super('')
|
13
|
+
end
|
14
|
+
|
15
|
+
def blank?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/blank_not_blank'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'eac_ruby_utils/paths_hash'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
class Configs
|
9
|
+
class Base
|
10
|
+
enable_simple_cache
|
11
|
+
|
12
|
+
common_constructor :data, default: [{}] do
|
13
|
+
self.data = ::EacRubyUtils::PathsHash.new(data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def []=(entry_key, entry_value)
|
17
|
+
write(entry_key, entry_value)
|
18
|
+
end
|
19
|
+
|
20
|
+
def [](entry_key)
|
21
|
+
read(entry_key)
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear
|
25
|
+
replace({})
|
26
|
+
end
|
27
|
+
|
28
|
+
def read(entry_key)
|
29
|
+
return nil unless data.key?(entry_key)
|
30
|
+
|
31
|
+
data.fetch(entry_key).if_present(::EacRubyUtils::BlankNotBlank.instance)
|
32
|
+
end
|
33
|
+
|
34
|
+
def replace(new_data)
|
35
|
+
self.data = ::EacRubyUtils::PathsHash.new(new_data)
|
36
|
+
end
|
37
|
+
|
38
|
+
def write(entry_key, entry_value)
|
39
|
+
data[entry_key] = entry_value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,27 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'eac_ruby_utils/configs/base'
|
4
4
|
require 'yaml'
|
5
|
-
require 'eac_ruby_utils/patches/hash/sym_keys_hash'
|
6
|
-
require 'eac_ruby_utils/paths_hash'
|
7
|
-
require 'eac_ruby_utils/simple_cache'
|
8
5
|
|
9
6
|
module EacRubyUtils
|
10
7
|
class Configs
|
11
|
-
class File
|
12
|
-
include ::EacRubyUtils::SimpleCache
|
13
|
-
|
8
|
+
class File < ::EacRubyUtils::Configs::Base
|
14
9
|
attr_reader :path, :options
|
15
10
|
|
16
11
|
# Valid options: [:autosave]
|
17
12
|
def initialize(path, options = {})
|
18
13
|
@path = path
|
19
14
|
@options = options.to_sym_keys_hash.freeze
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def clear
|
24
|
-
self.data = ::EacRubyUtils::PathsHash.new({})
|
15
|
+
super(raw_data_from_file)
|
25
16
|
end
|
26
17
|
|
27
18
|
def save
|
@@ -30,37 +21,27 @@ module EacRubyUtils
|
|
30
21
|
end
|
31
22
|
|
32
23
|
def load
|
33
|
-
|
34
|
-
::EacRubyUtils::PathsHash.new(YAML.load_file(path))
|
35
|
-
else
|
36
|
-
{}
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def []=(entry_key, entry_value)
|
41
|
-
write(entry_key, entry_value)
|
24
|
+
replace(raw_data_from_file)
|
42
25
|
end
|
43
26
|
|
44
27
|
def write(entry_key, entry_value)
|
45
|
-
|
28
|
+
super
|
46
29
|
save if autosave?
|
47
30
|
end
|
48
31
|
|
49
|
-
def [](entry_key)
|
50
|
-
read(entry_key)
|
51
|
-
end
|
52
|
-
|
53
|
-
def read(entry_key)
|
54
|
-
data[entry_key]
|
55
|
-
end
|
56
|
-
|
57
32
|
def autosave?
|
58
33
|
options[:autosave] ? true : false
|
59
34
|
end
|
60
35
|
|
61
36
|
private
|
62
37
|
|
63
|
-
|
38
|
+
def raw_data_from_file
|
39
|
+
if ::File.exist?(path) && ::File.size(path).positive?
|
40
|
+
::YAML.load_file(path)
|
41
|
+
else
|
42
|
+
{}
|
43
|
+
end
|
44
|
+
end
|
64
45
|
end
|
65
46
|
end
|
66
47
|
end
|
@@ -1,31 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_ruby_utils/common_constructor'
|
4
3
|
require 'eac_ruby_utils/configs'
|
5
|
-
require 'eac_ruby_utils/
|
6
|
-
require 'eac_ruby_utils/options_consumer'
|
7
|
-
require 'eac_ruby_utils/patches/object/asserts'
|
8
|
-
require 'eac_ruby_utils/simple_cache'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
9
5
|
|
10
6
|
module EacRubyUtils
|
11
7
|
module Console
|
12
8
|
class Configs
|
13
|
-
|
9
|
+
require_sub __FILE__
|
10
|
+
enable_console_speaker
|
14
11
|
|
15
12
|
class << self
|
16
13
|
def entry_key_to_envvar_name(entry_key)
|
17
|
-
|
18
|
-
entry_key
|
19
|
-
else
|
20
|
-
::EacRubyUtils::PathsHash.parse_entry_key(entry_key)
|
21
|
-
end
|
22
|
-
path.join('_').gsub(/[^a-z0-9_]/i, '').gsub(/\A_+/, '').gsub(/_+\z/, '')
|
23
|
-
.gsub(/_{2,}/, '_').upcase
|
14
|
+
::EacRubyUtils::Console::Configs::EntryReader.entry_key_to_envvar_name(entry_key)
|
24
15
|
end
|
25
16
|
end
|
26
17
|
|
27
|
-
STORE_PASSWORDS_KEY = 'core.store_passwords'
|
28
|
-
|
29
18
|
attr_reader :configs
|
30
19
|
|
31
20
|
def initialize(configs_key, options = {})
|
@@ -34,101 +23,15 @@ module EacRubyUtils
|
|
34
23
|
end
|
35
24
|
|
36
25
|
def read_password(entry_key, options = {})
|
37
|
-
|
38
|
-
if store_passwords?
|
39
|
-
read_entry(entry_key, options)
|
40
|
-
else
|
41
|
-
looped_entry_value_from_input(entry_key, options)
|
42
|
-
end
|
26
|
+
::EacRubyUtils::Console::Configs::PasswordEntryReader.new(self, entry_key, options).read
|
43
27
|
end
|
44
28
|
|
45
29
|
def read_entry(entry_key, options = {})
|
46
|
-
|
47
|
-
unless options[:noenv]
|
48
|
-
envvar_value = envvar_read_entry(entry_key)
|
49
|
-
return envvar_value if envvar_value.present?
|
50
|
-
end
|
51
|
-
stored_value = configs.read_entry(entry_key)
|
52
|
-
return stored_value if stored_value
|
53
|
-
return read_entry_from_console(entry_key, options) unless options[:noinput]
|
54
|
-
|
55
|
-
raise "No value found for entry \"#{entry_key}\"" if options[:required]
|
30
|
+
::EacRubyUtils::Console::Configs::EntryReader.new(self, entry_key, options).read
|
56
31
|
end
|
57
32
|
|
58
33
|
def store_passwords?
|
59
|
-
|
60
|
-
STORE_PASSWORDS_KEY,
|
61
|
-
before_input: -> { store_password_banner },
|
62
|
-
validator: ->(entry_value) { %w[yes no].include?(entry_value) }
|
63
|
-
) == 'yes'
|
64
|
-
end
|
65
|
-
|
66
|
-
protected
|
67
|
-
|
68
|
-
def envvar_read_entry(entry_key)
|
69
|
-
ENV[self.class.entry_key_to_envvar_name(entry_key)]
|
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
|
100
|
-
end
|
101
|
-
|
102
|
-
class ReadEntryOptions
|
103
|
-
include ::EacRubyUtils::SimpleCache
|
104
|
-
::EacRubyUtils::CommonConstructor.new(:options).setup_class(self)
|
105
|
-
|
106
|
-
DEFAULT_VALUES = {
|
107
|
-
before_input: nil, bool: false, list: false, noecho: false, noenv: false, noinput: false,
|
108
|
-
required: true, validator: nil
|
109
|
-
}.freeze
|
110
|
-
|
111
|
-
def [](key)
|
112
|
-
values.fetch(key.to_sym)
|
113
|
-
end
|
114
|
-
|
115
|
-
def request_input_options
|
116
|
-
values.slice(:bool, :list, :noecho)
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
def values_uncached
|
122
|
-
consumer = ::EacRubyUtils::OptionsConsumer.new(options)
|
123
|
-
r = {}
|
124
|
-
DEFAULT_VALUES.each do |key, default_value|
|
125
|
-
value = consumer.consume(key)
|
126
|
-
value = default_value if value.nil?
|
127
|
-
r[key] = value
|
128
|
-
end
|
129
|
-
consumer.validate
|
130
|
-
r
|
131
|
-
end
|
34
|
+
::EacRubyUtils::Console::Configs::StorePasswordsEntryReader.new(self) == 'yes'
|
132
35
|
end
|
133
36
|
end
|
134
37
|
end
|