ehbrs-tools 0.13.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs/executables.rb +1 -1
- data/lib/ehbrs/runner.rb +10 -17
- 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 +8 -9
- 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 +7 -14
- data/lib/ehbrs/runner/videos/extract.rb +10 -13
- data/lib/ehbrs/runner/videos/probe.rb +32 -0
- 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/videos/file.rb +2 -1
- data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
- data/vendor/eac_cli/eac_cli.gemspec +3 -3
- data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/default_runner.rb +6 -14
- data/vendor/eac_cli/lib/eac_cli/definition.rb +94 -0
- data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +42 -0
- data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +31 -0
- data/vendor/eac_cli/lib/eac_cli/{runner/docopt_doc.rb → docopt/doc_builder.rb} +15 -8
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +46 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +60 -0
- data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +127 -0
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +38 -0
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +77 -0
- data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +25 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +68 -7
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +35 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
- 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/docopt/runner_extension_spec.rb +25 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +78 -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/blank_not_blank.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
- 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 +8 -40
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +41 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +12 -9
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/dasho_options.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/identity_file.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/quiet.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/terminal.rb +34 -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/immutable/array_accessor.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
- 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/object/if_respond.rb +22 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -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/require_sub.rb +8 -8
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- 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/inflector_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/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
- data/vendor/ehbrs_ruby_utils/Gemfile +16 -0
- data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +20 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils.rb +7 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/executables.rb +28 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +5 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos.rb +9 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +11 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +31 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +21 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb +68 -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
- data/vendor/ehbrs_ruby_utils/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +18 -0
- data/vendor/ehbrs_ruby_utils/spec/rubocop_check_spec.rb +7 -0
- data/vendor/ehbrs_ruby_utils/spec/spec_helper.rb +100 -0
- metadata +77 -10
- data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +0 -13
- data/vendor/eac_cli/lib/eac_cli/runner/base_option.rb +0 -22
- data/vendor/eac_cli/lib/eac_cli/runner/boolean_option.rb +0 -13
- data/vendor/eac_cli/lib/eac_cli/runner/definition.rb +0 -64
- data/vendor/eac_cli/lib/eac_cli/runner/positional_argument.rb +0 -23
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/docopt/runner_extension'
|
4
|
+
|
5
|
+
RSpec.describe ::EacCli::Docopt::RunnerExtension do
|
6
|
+
let(:stub_runner) do
|
7
|
+
r = Class.new(::EacRubyUtils::Console::DocoptRunner) do
|
8
|
+
def run; end
|
9
|
+
end
|
10
|
+
r.include ::EacCli::Runner
|
11
|
+
r.runner_definition do
|
12
|
+
desc 'A stub runner.'
|
13
|
+
arg_opt '-o', '--opt1', 'A argument option'
|
14
|
+
pos_arg 'pos1'
|
15
|
+
end
|
16
|
+
r
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
|
20
|
+
|
21
|
+
before { instance.run }
|
22
|
+
|
23
|
+
it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
|
24
|
+
it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
|
25
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
4
|
+
require 'eac_cli/runner'
|
5
|
+
|
6
|
+
RSpec.describe ::EacCli::Runner do
|
7
|
+
let(:runner_class) do
|
8
|
+
the_module = described_class
|
9
|
+
::Class.new do
|
10
|
+
include the_module
|
11
|
+
|
12
|
+
runner_definition do
|
13
|
+
arg_opt '-o', '--opt1', 'A arg option.'
|
14
|
+
bool_opt '-o', '--opt2', 'A boolean option'
|
15
|
+
pos_arg :pos1
|
16
|
+
pos_arg :pos2, repeat: true, optional: true
|
17
|
+
alt do
|
18
|
+
bool_opt '-a', '--opt3', 'A boolean option in a alternative.', required: true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def run; end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when all args are supplied' do
|
27
|
+
let(:instance) { runner_class.create(%w[--opt1 aaa --opt2 bbb ccc ddd]) }
|
28
|
+
|
29
|
+
it { expect(instance.parsed.opt1).to eq('aaa') }
|
30
|
+
it { expect(instance.parsed.opt2?).to eq(true) }
|
31
|
+
it { expect(instance.parsed.pos1).to eq('bbb') }
|
32
|
+
it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when only required args are supplied' do
|
36
|
+
let(:instance) { runner_class.create(%w[bbb]) }
|
37
|
+
|
38
|
+
it { expect(instance.parsed.opt1).to be_nil }
|
39
|
+
it { expect(instance.parsed.opt2?).to eq(false) }
|
40
|
+
it { expect(instance.parsed.pos1).to eq('bbb') }
|
41
|
+
it { expect(instance.parsed.pos2).to eq([]) }
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when required args are not supplied' do
|
45
|
+
let(:instance) { runner_class.create(%w[]) }
|
46
|
+
|
47
|
+
it do
|
48
|
+
expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when alternative args are supplied' do
|
53
|
+
let(:instance) { runner_class.create(%w[--opt3]) }
|
54
|
+
|
55
|
+
it { expect(instance.parsed.opt3?).to eq(true) }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when extra args are not supplied' do
|
59
|
+
let(:runner_class) do
|
60
|
+
the_module = described_class
|
61
|
+
::Class.new do
|
62
|
+
include the_module
|
63
|
+
|
64
|
+
runner_definition do
|
65
|
+
pos_arg :pos1
|
66
|
+
end
|
67
|
+
|
68
|
+
def run; end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:instance) { runner_class.create(%w[aaa bbb]) }
|
73
|
+
|
74
|
+
it do
|
75
|
+
expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
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,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,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class Boolean
|
5
|
+
class << self
|
6
|
+
def parse(value)
|
7
|
+
return parse_string(value) if value.is_a?(::String)
|
8
|
+
return parse_string(value.to_s) if value.is_a?(::Symbol)
|
9
|
+
return parse_number(value) if value.is_a?(::Number)
|
10
|
+
|
11
|
+
value ? true : false
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def parse_string(value)
|
17
|
+
['', 'n', 'no', 'f', 'false'].include?(value.strip.downcase) ? false : true
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_number(value)
|
21
|
+
value.zero?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :value
|
26
|
+
|
27
|
+
def initialize(value)
|
28
|
+
@value = self.class.parse(value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -21,10 +21,10 @@ module EacRubyUtils
|
|
21
21
|
|
22
22
|
class Setup
|
23
23
|
include ::EacRubyUtils::SimpleCache
|
24
|
-
attr_reader :a_module, :
|
24
|
+
attr_reader :a_module, :common_concern
|
25
25
|
|
26
|
-
def initialize(
|
27
|
-
@
|
26
|
+
def initialize(common_concern, a_module)
|
27
|
+
@common_concern = common_concern
|
28
28
|
@a_module = a_module
|
29
29
|
end
|
30
30
|
|
@@ -47,7 +47,7 @@ module EacRubyUtils
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def setup_after_callback(base)
|
50
|
-
|
50
|
+
common_concern.after_callback.if_present do |v|
|
51
51
|
base.instance_eval(&v)
|
52
52
|
end
|
53
53
|
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,16 +1,13 @@
|
|
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)
|
@@ -34,7 +31,7 @@ module EacRubyUtils
|
|
34
31
|
end
|
35
32
|
|
36
33
|
def read_password(entry_key, options = {})
|
37
|
-
options = options.merge(noecho: true)
|
34
|
+
options = ReadEntryOptions.new(options.merge(noecho: true))
|
38
35
|
if store_passwords?
|
39
36
|
read_entry(entry_key, options)
|
40
37
|
else
|
@@ -66,7 +63,10 @@ module EacRubyUtils
|
|
66
63
|
protected
|
67
64
|
|
68
65
|
def envvar_read_entry(entry_key)
|
69
|
-
|
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
70
|
end
|
71
71
|
|
72
72
|
def read_entry_from_console(entry_key, options)
|
@@ -98,38 +98,6 @@ module EacRubyUtils
|
|
98
98
|
warn('Entered value is blank') if entry_value.blank?
|
99
99
|
entry_value
|
100
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
|
132
|
-
end
|
133
101
|
end
|
134
102
|
end
|
135
103
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Console
|
7
|
+
class Configs
|
8
|
+
class ReadEntryOptions
|
9
|
+
enable_simple_cache
|
10
|
+
common_constructor :options
|
11
|
+
|
12
|
+
DEFAULT_VALUES = {
|
13
|
+
before_input: nil, bool: false, list: false, noecho: false, noenv: false, noinput: false,
|
14
|
+
required: true, validator: nil
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
def [](key)
|
18
|
+
values.fetch(key.to_sym)
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_input_options
|
22
|
+
values.slice(:bool, :list, :noecho)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def values_uncached
|
28
|
+
consumer = options.to_options_consumer
|
29
|
+
r = {}
|
30
|
+
DEFAULT_VALUES.each do |key, default_value|
|
31
|
+
value = consumer.consume(key)
|
32
|
+
value = default_value if value.nil?
|
33
|
+
r[key] = value
|
34
|
+
end
|
35
|
+
consumer.validate
|
36
|
+
r
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|