ehbrs-tools 0.19.0 → 0.20.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/cooking_book/project.rb +8 -2
- data/lib/ehbrs/music.rb +9 -0
- data/lib/ehbrs/music/album.rb +42 -0
- data/lib/ehbrs/observers/base.rb +1 -1
- data/lib/ehbrs/observers/with_persistence.rb +1 -1
- data/lib/ehbrs/runner/music.rb +16 -0
- data/lib/ehbrs/runner/music/selected.rb +63 -0
- data/lib/ehbrs/runner/web_utils/videos/upload.rb +1 -1
- data/lib/ehbrs/tools/version.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/core_ext.rb +2 -0
- data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +4 -7
- data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +8 -0
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +21 -9
- data/vendor/eac_cli/lib/eac_cli/definition/base_option/initialize_args_parser.rb +47 -0
- data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +8 -0
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +12 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +15 -1
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +3 -17
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
- data/vendor/eac_cli/lib/eac_cli/runner.rb +0 -48
- data/vendor/eac_cli/lib/eac_cli/runner/after_class_methods.rb +29 -0
- data/vendor/eac_cli/lib/eac_cli/runner/instance_methods.rb +31 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with_set.rb +50 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +4 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +21 -3
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/jobs_runner.rb +31 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches.rb +4 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/class.rb +4 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/class/jobs_runner.rb +10 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/object.rb +5 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/object/runner_with.rb +5 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with.rb +9 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/confirmable.rb +21 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/filesystem_traverser.rb +52 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb +12 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/settings_provider.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/required_zone.rb +11 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- metadata +26 -7
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9197f68f8849f5b939a2209bd1b5659aa2aa9544286e80b5290a06620f680628
|
4
|
+
data.tar.gz: 75f0b60d3f0971aa33913374932630dfa101378698f0210f28619f59f0a63aaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e675d639a57fc2f6d4d14ab8733cdb9cc96be6818d18252443e575eb3b21c2f1d25139a1c237720c1473b6b369f7c47c5fe1ba547ad49319d9cd1411fdc70f7
|
7
|
+
data.tar.gz: 25b77dab28684229355feb9295073fadaf42ed78c4ef27d347e907cf959fa5ff2c822ba96f99a955a6b2adc561b138d241fc9ce3f31026b9b3fdfb398d4c1d36
|
@@ -6,6 +6,8 @@ require 'ehbrs/cooking_book/recipe'
|
|
6
6
|
module Ehbrs
|
7
7
|
module CookingBook
|
8
8
|
class Project
|
9
|
+
RECIPES_ROOT_SUBPATH = 'recipes'
|
10
|
+
|
9
11
|
enable_simple_cache
|
10
12
|
common_constructor :root do
|
11
13
|
self.root = root.to_pathname
|
@@ -15,9 +17,13 @@ module Ehbrs
|
|
15
17
|
|
16
18
|
private
|
17
19
|
|
20
|
+
def recipes_root_uncached
|
21
|
+
root.join(RECIPES_ROOT_SUBPATH)
|
22
|
+
end
|
23
|
+
|
18
24
|
def recipes_uncached
|
19
|
-
::Dir.glob(File.join('**', '*.{yml,yaml}'), base:
|
20
|
-
::Ehbrs::CookingBook::Recipe.from_file(
|
25
|
+
::Dir.glob(File.join('**', '*.{yml,yaml}'), base: recipes_root.to_path).map do |subpath|
|
26
|
+
::Ehbrs::CookingBook::Recipe.from_file(recipes_root.join(subpath))
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
data/lib/ehbrs/music.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Ehbrs
|
6
|
+
module Music
|
7
|
+
class Album
|
8
|
+
include ::Comparable
|
9
|
+
common_constructor :path do
|
10
|
+
self.path = path.to_pathname.expand_path
|
11
|
+
end
|
12
|
+
|
13
|
+
def <=>(other)
|
14
|
+
to_a <=> other.to_a
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_a
|
18
|
+
[category, artist, name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_label
|
22
|
+
(to_a + [id]).map(&:light_white).join(' | '.blue)
|
23
|
+
end
|
24
|
+
|
25
|
+
def id
|
26
|
+
[artist, name].join('_').variableize
|
27
|
+
end
|
28
|
+
|
29
|
+
def name
|
30
|
+
path.basename.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def artist
|
34
|
+
path.parent.basename.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def category
|
38
|
+
path.parent.parent.basename.to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/ehbrs/observers/base.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_base0/patches'
|
4
|
+
require 'eac_ruby_utils/fs/clearable_directory'
|
5
|
+
require 'ehbrs/music/album'
|
6
|
+
|
7
|
+
module Ehbrs
|
8
|
+
class Runner
|
9
|
+
class Music
|
10
|
+
class Selected
|
11
|
+
DEFAULT_TRAVERSER_RECURSIVE = true
|
12
|
+
|
13
|
+
enable_jobs_runner
|
14
|
+
runner_with :help, :filesystem_traverser do
|
15
|
+
desc 'Seleciona álbuns de música.'
|
16
|
+
arg_opt '-b', '--build-dir', 'Constrói diretório de músicas selecionadas.'
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
infov 'Recursive', traverser_recursive
|
21
|
+
run_jobs :show, :build
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build
|
27
|
+
infom 'Building...'
|
28
|
+
build_dir.clear
|
29
|
+
selected_albums.each do |album|
|
30
|
+
::EacRubyUtils::Envs.local.command('ln', '-s', album.path,
|
31
|
+
build_dir.join(album.id)).system!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_dir_uncached
|
36
|
+
parsed.build_dir.if_present { |v| ::EacRubyUtils::Fs::ClearableDirectory.new(v) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_build?
|
40
|
+
build_dir.present?
|
41
|
+
end
|
42
|
+
|
43
|
+
def selected_albums_uncached
|
44
|
+
infom 'Searching selected albums...'
|
45
|
+
@selected = []
|
46
|
+
run_filesystem_traverser
|
47
|
+
@selected.sort
|
48
|
+
end
|
49
|
+
|
50
|
+
def show
|
51
|
+
infov 'Albums found', selected_albums.count
|
52
|
+
selected_albums.each do |album|
|
53
|
+
puts album.to_label
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def traverser_check_directory(path)
|
58
|
+
@selected << ::Ehbrs::Music::Album.new(path) if path.join('.selected').exist?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -42,7 +42,7 @@ module Ehbrs
|
|
42
42
|
def process_response(response)
|
43
43
|
infov 'Response status', response.status
|
44
44
|
if response.status == 200
|
45
|
-
pp ::JSON.parse(response.body)
|
45
|
+
pp ::JSON.parse(response.body)
|
46
46
|
else
|
47
47
|
error_file = '/tmp/ehbrsutils.html'
|
48
48
|
::File.write(error_file, response.body)
|
data/lib/ehbrs/tools/version.rb
CHANGED
@@ -10,15 +10,12 @@ module EacCli
|
|
10
10
|
SUBCOMMAND_NAME_ARG = :subcommand
|
11
11
|
SUBCOMMAND_ARGS_ARG = :subcommand_args
|
12
12
|
|
13
|
-
def arg_opt(
|
14
|
-
options_set << ::EacCli::Definition::ArgumentOption.
|
15
|
-
short, long, description, option_options
|
16
|
-
)
|
13
|
+
def arg_opt(*args)
|
14
|
+
options_set << ::EacCli::Definition::ArgumentOption.from_args(args)
|
17
15
|
end
|
18
16
|
|
19
|
-
def bool_opt(
|
20
|
-
options_set << ::EacCli::Definition::BooleanOption.
|
21
|
-
option_options)
|
17
|
+
def bool_opt(*args)
|
18
|
+
options_set << ::EacCli::Definition::BooleanOption.from_args(args)
|
22
19
|
end
|
23
20
|
|
24
21
|
def options
|
@@ -5,24 +5,36 @@ require 'eac_ruby_utils/core_ext'
|
|
5
5
|
module EacCli
|
6
6
|
class Definition
|
7
7
|
class BaseOption
|
8
|
+
require_sub __FILE__
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def from_args(args)
|
12
|
+
p = ::EacCli::Definition::BaseOption::InitializeArgsParser.new(args)
|
13
|
+
new(p.short, p.long, p.description, p.options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
8
17
|
DEFAULT_REQUIRED = false
|
9
18
|
|
10
19
|
enable_listable
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@options.assert_valid_keys(::EacCli::Definition::BaseOption.lists.option.values)
|
20
|
+
enable_abstract_methods :build_value, :default_value
|
21
|
+
lists.add_symbol :option, :optional, :usage, :repeat, :required
|
22
|
+
common_constructor :short, :long, :description, :options, default: [{}] do
|
23
|
+
raise 'Nor short neither long selector was set' if short.blank? && long.blank?
|
24
|
+
|
25
|
+
self.options = ::EacCli::Definition::BaseOption.lists.option.hash_keys_validate!(
|
26
|
+
options.symbolize_keys
|
27
|
+
)
|
20
28
|
end
|
21
29
|
|
22
30
|
def identifier
|
23
31
|
long.to_s.variableize.to_sym
|
24
32
|
end
|
25
33
|
|
34
|
+
def repeat?
|
35
|
+
options[OPTION_REPEAT]
|
36
|
+
end
|
37
|
+
|
26
38
|
def required?
|
27
39
|
return true if options.key?(:required) && options.fetch(:required)
|
28
40
|
return false if options.key?(:optional) && options.fetch(:optional)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Definition
|
5
|
+
class BaseOption
|
6
|
+
class InitializeArgsParser
|
7
|
+
PROPERTIES = %i[short long description options].freeze
|
8
|
+
attr_reader(*PROPERTIES)
|
9
|
+
|
10
|
+
def initialize(args)
|
11
|
+
self.options = args.extract_options!.freeze
|
12
|
+
args.each { |arg| absorb_arg(arg) }
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_writer(*PROPERTIES)
|
18
|
+
|
19
|
+
def absorb_arg(arg)
|
20
|
+
arg_ext = ArgumentParser.new(arg)
|
21
|
+
send("#{arg_ext.type}=", arg_ext.value)
|
22
|
+
end
|
23
|
+
|
24
|
+
class ArgumentParser
|
25
|
+
TYPES = %i[short long description].freeze
|
26
|
+
common_constructor :value
|
27
|
+
|
28
|
+
def type
|
29
|
+
TYPES.find { |type| send("#{type}?") } || raise("Unknown type for \"#{value}\"")
|
30
|
+
end
|
31
|
+
|
32
|
+
def short?
|
33
|
+
value.start_with?('-') && !long?
|
34
|
+
end
|
35
|
+
|
36
|
+
def long?
|
37
|
+
value.start_with?('--')
|
38
|
+
end
|
39
|
+
|
40
|
+
def description?
|
41
|
+
!short? || !long?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -13,6 +13,18 @@ module EacCli
|
|
13
13
|
options.assert_valid_keys(self.class.lists.option.values)
|
14
14
|
end
|
15
15
|
|
16
|
+
def build_value(new_value, previous_value)
|
17
|
+
if previous_value.is_a?(::Array)
|
18
|
+
previous_value + [new_value]
|
19
|
+
else
|
20
|
+
new_value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_value
|
25
|
+
repeat? ? [] : nil
|
26
|
+
end
|
27
|
+
|
16
28
|
def identifier
|
17
29
|
name.to_s.variableize.to_sym
|
18
30
|
end
|
@@ -19,10 +19,24 @@ module EacCli
|
|
19
19
|
b += '=<value>' if option.argument?
|
20
20
|
b
|
21
21
|
end
|
22
|
+
|
23
|
+
def option_short(option)
|
24
|
+
b = option.short
|
25
|
+
b += '=<value>' if option.argument?
|
26
|
+
b
|
27
|
+
end
|
28
|
+
|
29
|
+
def option_usage_full(option)
|
30
|
+
if option.long.present?
|
31
|
+
[option.short, option_long(option)].reject(&:blank?).join(SEP)
|
32
|
+
else
|
33
|
+
option_short(option)
|
34
|
+
end
|
35
|
+
end
|
22
36
|
end
|
23
37
|
|
24
38
|
def option_definition(option)
|
25
|
-
|
39
|
+
self.class.option_usage_full(option) + OPTION_DESC_SEP + option.description
|
26
40
|
end
|
27
41
|
|
28
42
|
def section(header, include_header = true)
|
@@ -24,11 +24,7 @@ module EacCli
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def collect(option, value)
|
27
|
-
|
28
|
-
data[option] << value
|
29
|
-
else
|
30
|
-
data[option] = value
|
31
|
-
end
|
27
|
+
data[option] = option.build_value(value, data[option])
|
32
28
|
end
|
33
29
|
|
34
30
|
def supplied?(option)
|
@@ -42,18 +38,8 @@ module EacCli
|
|
42
38
|
end
|
43
39
|
|
44
40
|
def default_values
|
45
|
-
definition.options.each { |option| data[option] =
|
46
|
-
definition.positional.each
|
47
|
-
data[positional] = positional_default_value(positional)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def option_default_value(option)
|
52
|
-
option.argument? ? nil : false
|
53
|
-
end
|
54
|
-
|
55
|
-
def positional_default_value(positional)
|
56
|
-
positional.repeat? ? [] : nil
|
41
|
+
definition.options.each { |option| data[option] = option.default_value }
|
42
|
+
definition.positional.each { |positional| data[positional] = positional.default_value }
|
57
43
|
end
|
58
44
|
end
|
59
45
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
4
|
require 'eac_cli/runner'
|
5
5
|
require 'eac_cli/runner_with'
|
6
|
+
require 'eac_cli/runner_with_set'
|
6
7
|
|
7
8
|
class Object
|
8
9
|
def runner_with(*runners, &block)
|
@@ -10,7 +11,7 @@ class Object
|
|
10
11
|
enable_simple_cache
|
11
12
|
enable_console_speaker
|
12
13
|
runners.each do |runner|
|
13
|
-
include
|
14
|
+
include ::EacCli::RunnerWithSet.default.item_to_module(runner)
|
14
15
|
end
|
15
16
|
runner_definition(&block) if block
|
16
17
|
end
|
@@ -47,53 +47,5 @@ module EacCli
|
|
47
47
|
include ActiveSupport::Callbacks
|
48
48
|
define_callbacks :run
|
49
49
|
end
|
50
|
-
|
51
|
-
module AfterClassMethods
|
52
|
-
def create(*runner_context_args)
|
53
|
-
r = new
|
54
|
-
r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
|
55
|
-
r
|
56
|
-
end
|
57
|
-
|
58
|
-
def run(*runner_context_args)
|
59
|
-
r = create(*runner_context_args)
|
60
|
-
r.run_run
|
61
|
-
r
|
62
|
-
end
|
63
|
-
|
64
|
-
def runner_definition(&block)
|
65
|
-
@runner_definition ||= super_runner_definition
|
66
|
-
@runner_definition.instance_eval(&block) if block
|
67
|
-
@runner_definition
|
68
|
-
end
|
69
|
-
|
70
|
-
def super_runner_definition
|
71
|
-
superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
|
72
|
-
end
|
73
|
-
end
|
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
|
-
|
83
|
-
def runner_context
|
84
|
-
return @runner_context if @runner_context
|
85
|
-
|
86
|
-
raise 'Context was required, but was not set yet'
|
87
|
-
end
|
88
|
-
|
89
|
-
def runner_context=(new_runner_context)
|
90
|
-
@runner_context = new_runner_context
|
91
|
-
@parsed = nil
|
92
|
-
end
|
93
|
-
|
94
|
-
def parsed
|
95
|
-
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
|
96
|
-
end
|
97
|
-
end
|
98
50
|
end
|
99
51
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
module Runner
|
5
|
+
module AfterClassMethods
|
6
|
+
def create(*runner_context_args)
|
7
|
+
r = new
|
8
|
+
r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
|
9
|
+
r
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(*runner_context_args)
|
13
|
+
r = create(*runner_context_args)
|
14
|
+
r.run_run
|
15
|
+
r
|
16
|
+
end
|
17
|
+
|
18
|
+
def runner_definition(&block)
|
19
|
+
@runner_definition ||= super_runner_definition
|
20
|
+
@runner_definition.instance_eval(&block) if block
|
21
|
+
@runner_definition
|
22
|
+
end
|
23
|
+
|
24
|
+
def super_runner_definition
|
25
|
+
superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
module Runner
|
5
|
+
module InstanceMethods
|
6
|
+
def run_run
|
7
|
+
parsed
|
8
|
+
run_callbacks(:run) { run }
|
9
|
+
rescue ::EacCli::Parser::Error => e
|
10
|
+
$stderr.write("#{e}\n")
|
11
|
+
rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
|
12
|
+
# Do nothing
|
13
|
+
end
|
14
|
+
|
15
|
+
def runner_context
|
16
|
+
return @runner_context if @runner_context
|
17
|
+
|
18
|
+
raise 'Context was required, but was not set yet'
|
19
|
+
end
|
20
|
+
|
21
|
+
def runner_context=(new_runner_context)
|
22
|
+
@runner_context = new_runner_context
|
23
|
+
@parsed = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def parsed
|
27
|
+
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class RunnerWithSet
|
5
|
+
class << self
|
6
|
+
def default
|
7
|
+
@default ||= new
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_namespace(namespace)
|
12
|
+
namespace = sanitize_namespace(namespace)
|
13
|
+
raise "\"#{namespace}\" already was included" if namespace_set.include?(namespace)
|
14
|
+
|
15
|
+
namespace_set << namespace
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def item_to_module(item)
|
20
|
+
item.is_a?(::Module) ? item : key_to_module(item)
|
21
|
+
end
|
22
|
+
|
23
|
+
def namespaces
|
24
|
+
namespace_set.dup
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def namespace_set
|
30
|
+
@namespace_set ||= ::Array.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def key_to_module(key)
|
34
|
+
namespace_set.lazy
|
35
|
+
.map { |namespace| key_to_module_in_namespace(namespace, key) }
|
36
|
+
.find(&:present?) ||
|
37
|
+
raise("Not module found with key \"#{key}\" (Namespaces: #{namespace_set})")
|
38
|
+
end
|
39
|
+
|
40
|
+
def key_to_module_in_namespace(namespace, key)
|
41
|
+
namespace.const_get(key.to_s.camelize)
|
42
|
+
rescue ::NameError
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def sanitize_namespace(source)
|
47
|
+
source.is_a?(::Module) ? source : source.to_s.constantize
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -7,6 +7,10 @@ RSpec.describe ::EacCli::Definition::Alternative do
|
|
7
7
|
|
8
8
|
it { expect { instance.arg_opt '-a', '--opt2', 'A argument option' }.not_to raise_error }
|
9
9
|
it { expect { instance.bool_opt '-b', '--opt1', 'A boolean option' }.not_to raise_error }
|
10
|
+
it { expect { instance.bool_opt '-b', '--no-description' }.not_to raise_error }
|
11
|
+
it { expect { instance.bool_opt '--opt1', 'A option without short' }.not_to raise_error }
|
12
|
+
it { expect { instance.bool_opt '-b', 'A option without long' }.not_to raise_error }
|
13
|
+
it { expect { instance.bool_opt 'A option without selectors' }.to raise_error(::StandardError) }
|
10
14
|
it { expect { instance.options_argument(true) }.not_to raise_error }
|
11
15
|
it { expect { instance.pos_arg :pos1 }.not_to raise_error }
|
12
16
|
it { expect { instance.pos_arg :pos2, optional: true, repeat: true }.not_to raise_error }
|
@@ -12,6 +12,8 @@ RSpec.describe ::EacCli::Runner do
|
|
12
12
|
runner_definition do
|
13
13
|
arg_opt '-o', '--opt1', 'A arg option.'
|
14
14
|
bool_opt '-p', '--opt2', 'A boolean option'
|
15
|
+
arg_opt '-q', '--opt4', 'A repeatable argument option.', repeat: true
|
16
|
+
bool_opt '-r', '--opt5', 'A repeatable boolean option', repeat: true
|
15
17
|
pos_arg :pos1
|
16
18
|
pos_arg :pos2, repeat: true, optional: true
|
17
19
|
alt do
|
@@ -29,7 +31,7 @@ RSpec.describe ::EacCli::Runner do
|
|
29
31
|
context 'when all args are supplied' do
|
30
32
|
let(:argv) { %w[--opt1 aaa --opt2 bbb ccc ddd] }
|
31
33
|
let(:parsed_expected) do
|
32
|
-
{ opt1: 'aaa', opt2: true, opt3: false, pos1: 'bbb',
|
34
|
+
{ opt1: 'aaa', opt2: true, opt3: false, opt4: [], opt5: 0, pos1: 'bbb',
|
33
35
|
pos2: %w[ccc ddd] }
|
34
36
|
end
|
35
37
|
|
@@ -63,7 +65,10 @@ RSpec.describe ::EacCli::Runner do
|
|
63
65
|
|
64
66
|
context 'when only required args are supplied' do
|
65
67
|
let(:argv) { %w[bbb] }
|
66
|
-
let(:parsed_expected)
|
68
|
+
let(:parsed_expected) do
|
69
|
+
{ opt1: nil, opt2: false, opt3: false, opt4: [], opt5: 0, pos1: 'bbb',
|
70
|
+
pos2: [] }
|
71
|
+
end
|
67
72
|
|
68
73
|
it { expect(parsed_actual).to eq(parsed_expected) }
|
69
74
|
it { expect(instance.parsed.opt1).to be_nil }
|
@@ -82,12 +87,25 @@ RSpec.describe ::EacCli::Runner do
|
|
82
87
|
|
83
88
|
context 'when alternative args are supplied' do
|
84
89
|
let(:argv) { %w[--opt3] }
|
85
|
-
let(:parsed_expected)
|
90
|
+
let(:parsed_expected) do
|
91
|
+
{ opt1: nil, opt2: false, opt3: true, opt4: [], opt5: 0, pos1: nil,
|
92
|
+
pos2: [] }
|
93
|
+
end
|
86
94
|
|
87
95
|
it { expect(parsed_actual).to eq(parsed_expected) }
|
88
96
|
it { expect(instance.parsed.opt3?).to eq(true) }
|
89
97
|
end
|
90
98
|
|
99
|
+
context 'when repeated options are supplied' do
|
100
|
+
let(:argv) { %w[--opt5 -rrr --opt4=A -q B --opt4 C AAA] }
|
101
|
+
let(:parsed_expected) do
|
102
|
+
{ opt1: nil, opt2: false, opt3: false, opt4: %w[A B C], opt5: 4, pos1: 'AAA',
|
103
|
+
pos2: [] }
|
104
|
+
end
|
105
|
+
|
106
|
+
it { expect(parsed_actual).to eq(parsed_expected) }
|
107
|
+
end
|
108
|
+
|
91
109
|
context 'when extra args are not supplied' do
|
92
110
|
let(:runner_class) do
|
93
111
|
the_module = described_class
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/speaker'
|
4
|
+
require 'eac_ruby_utils/settings_provider'
|
5
|
+
|
6
|
+
module EacRubyBase0
|
7
|
+
module JobsRunner
|
8
|
+
common_concern do
|
9
|
+
include ::EacRubyUtils::Console::Speaker
|
10
|
+
include ::EacRubyUtils::SettingsProvider
|
11
|
+
end
|
12
|
+
|
13
|
+
def run_job(job)
|
14
|
+
return unless run_job?(job)
|
15
|
+
|
16
|
+
infom "Running job \"#{job}\"..."
|
17
|
+
send(job)
|
18
|
+
end
|
19
|
+
|
20
|
+
def run_job?(job)
|
21
|
+
the_method = "run_#{job}?"
|
22
|
+
respond_to?(the_method, true) ? send(the_method) : true
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_jobs(*jobs)
|
26
|
+
jobs = setting_value(:jobs) if jobs.empty?
|
27
|
+
jobs.each { |job| run_job(job) }
|
28
|
+
success 'Done'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner'
|
4
|
+
require 'eac_ruby_utils/fs/traversable'
|
5
|
+
|
6
|
+
module EacRubyBase0
|
7
|
+
module RunnerWith
|
8
|
+
module Confirmable
|
9
|
+
extend ::ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include ::EacCli::Runner
|
13
|
+
runner_definition do
|
14
|
+
bool_opt '-c', '--confirm', 'Confirm changes.'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
delegate :confirm?, to: :parsed
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'eac_ruby_utils/fs/traversable'
|
6
|
+
require 'eac_ruby_utils/settings_provider'
|
7
|
+
|
8
|
+
module EacRubyBase0
|
9
|
+
module RunnerWith
|
10
|
+
module FilesystemTraverser
|
11
|
+
DEFAULT_DEFAULT_TRAVERSER_RECURSIVE = false
|
12
|
+
|
13
|
+
common_concern do
|
14
|
+
include ::EacCli::Runner
|
15
|
+
include ::EacRubyUtils::Fs::Traversable
|
16
|
+
enable_settings_provider
|
17
|
+
include TopMethods
|
18
|
+
runner_definition do
|
19
|
+
bool_opt '-R', '--recursive', 'Recursive.'
|
20
|
+
bool_opt '--no-recursive', 'No recursive.'
|
21
|
+
pos_arg :paths, optional: true, repeat: true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module TopMethods
|
26
|
+
def on_none_path_informed
|
27
|
+
infom 'Warning: none path informed'
|
28
|
+
end
|
29
|
+
|
30
|
+
def paths
|
31
|
+
parsed.paths.map(&:to_pathname)
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_filesystem_traverser
|
35
|
+
if parsed.paths.any?
|
36
|
+
parsed.paths.each { |path| traverser_check_path(path) }
|
37
|
+
else
|
38
|
+
on_none_path_informed
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def traverser_recursive
|
43
|
+
return false if parsed.no_recursive?
|
44
|
+
return true if parsed.recursive?
|
45
|
+
|
46
|
+
setting_value(:default_traverser_recursive, required: false)
|
47
|
+
.if_not_nil(DEFAULT_DEFAULT_TRAVERSER_RECURSIVE)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -10,26 +10,36 @@ module EacRubyUtils
|
|
10
10
|
class << self
|
11
11
|
TIMEDATECTL_TIMEZONE_LINE_PATTERN = %r{\s*Time zone:\s*(\S+/\S+)\s}.freeze
|
12
12
|
|
13
|
+
# @return [ActiveSupport::TimeZone]
|
13
14
|
def auto
|
14
15
|
%w[tz_env debian_config offset].lazy.map { |s| send("by_#{s}") }.find(&:present?)
|
15
16
|
end
|
16
17
|
|
18
|
+
def auto_set
|
19
|
+
::Time.zone = auto
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [ActiveSupport::TimeZone]
|
17
23
|
def by_debian_config
|
18
24
|
path = ::Pathname.new(DEBIAN_CONFIG_PATH)
|
19
|
-
path.exist? ? path.read.strip.
|
25
|
+
path.exist? ? path.read.strip.if_present { |v| ::ActiveSupport::TimeZone[v] } : nil
|
20
26
|
end
|
21
27
|
|
28
|
+
# @return [ActiveSupport::TimeZone]
|
22
29
|
def by_offset
|
23
|
-
::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset]
|
30
|
+
::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset]
|
24
31
|
end
|
25
32
|
|
33
|
+
# @return [ActiveSupport::TimeZone]
|
26
34
|
def by_timedatectl
|
27
35
|
executable = ::EacRubyUtils::Envs.local.executable('timedatectl', '--version')
|
28
36
|
return nil unless executable.exist?
|
29
37
|
|
30
38
|
TIMEDATECTL_TIMEZONE_LINE_PATTERN.if_match(executable.command.execute!) { |m| m[1] }
|
39
|
+
.if_present { |v| ::ActiveSupport::TimeZone[v] }
|
31
40
|
end
|
32
41
|
|
42
|
+
# @return [ActiveSupport::TimeZone]
|
33
43
|
def by_tz_env
|
34
44
|
ENV['TZ'].presence
|
35
45
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Object
|
4
|
+
# @return +block.call(self)+ if +self+ is not nil, +default_value+ otherwise.
|
5
|
+
def if_not_nil(default_value = nil)
|
6
|
+
return default_value if nil?
|
7
|
+
|
8
|
+
block_given? ? yield(self) : self
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return +yield+ if +self+ is nil, +self+ otherwise.
|
12
|
+
def if_nil
|
13
|
+
return yield if nil? && block_given?
|
14
|
+
|
15
|
+
self
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehbrs-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.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: 2021-
|
11
|
+
date: 2021-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avm-tools
|
@@ -37,9 +37,9 @@ dependencies:
|
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0.12'
|
40
|
-
- - "
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.12.
|
42
|
+
version: 0.12.5
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -47,9 +47,9 @@ dependencies:
|
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0.12'
|
50
|
-
- - "
|
50
|
+
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 0.12.
|
52
|
+
version: 0.12.5
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: eac_ruby_utils
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,6 +147,8 @@ files:
|
|
147
147
|
- lib/ehbrs/google.rb
|
148
148
|
- lib/ehbrs/google/translate.rb
|
149
149
|
- lib/ehbrs/google/translate/session.rb
|
150
|
+
- lib/ehbrs/music.rb
|
151
|
+
- lib/ehbrs/music/album.rb
|
150
152
|
- lib/ehbrs/observers.rb
|
151
153
|
- lib/ehbrs/observers/base.rb
|
152
154
|
- lib/ehbrs/observers/with_persistence.rb
|
@@ -162,6 +164,8 @@ files:
|
|
162
164
|
- lib/ehbrs/runner/fs/used_space.rb
|
163
165
|
- lib/ehbrs/runner/google.rb
|
164
166
|
- lib/ehbrs/runner/google/translate.rb
|
167
|
+
- lib/ehbrs/runner/music.rb
|
168
|
+
- lib/ehbrs/runner/music/selected.rb
|
165
169
|
- lib/ehbrs/runner/self.rb
|
166
170
|
- lib/ehbrs/runner/self/test.rb
|
167
171
|
- lib/ehbrs/runner/telegram.rb
|
@@ -294,6 +298,7 @@ files:
|
|
294
298
|
- vendor/eac_cli/lib/eac_cli/definition/alternative.rb
|
295
299
|
- vendor/eac_cli/lib/eac_cli/definition/argument_option.rb
|
296
300
|
- vendor/eac_cli/lib/eac_cli/definition/base_option.rb
|
301
|
+
- vendor/eac_cli/lib/eac_cli/definition/base_option/initialize_args_parser.rb
|
297
302
|
- vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb
|
298
303
|
- vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb
|
299
304
|
- vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
|
@@ -316,12 +321,15 @@ files:
|
|
316
321
|
- vendor/eac_cli/lib/eac_cli/patches/object.rb
|
317
322
|
- vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb
|
318
323
|
- vendor/eac_cli/lib/eac_cli/runner.rb
|
324
|
+
- vendor/eac_cli/lib/eac_cli/runner/after_class_methods.rb
|
319
325
|
- vendor/eac_cli/lib/eac_cli/runner/context.rb
|
320
326
|
- vendor/eac_cli/lib/eac_cli/runner/exit.rb
|
327
|
+
- vendor/eac_cli/lib/eac_cli/runner/instance_methods.rb
|
321
328
|
- vendor/eac_cli/lib/eac_cli/runner_with.rb
|
322
329
|
- vendor/eac_cli/lib/eac_cli/runner_with/help.rb
|
323
330
|
- vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb
|
324
331
|
- vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb
|
332
|
+
- vendor/eac_cli/lib/eac_cli/runner_with_set.rb
|
325
333
|
- vendor/eac_cli/lib/eac_cli/version.rb
|
326
334
|
- vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb
|
327
335
|
- vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb
|
@@ -356,8 +364,17 @@ files:
|
|
356
364
|
- vendor/eac_ruby_base0/eac_ruby_base0.gemspec
|
357
365
|
- vendor/eac_ruby_base0/lib/eac_ruby_base0.rb
|
358
366
|
- vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb
|
367
|
+
- vendor/eac_ruby_base0/lib/eac_ruby_base0/jobs_runner.rb
|
368
|
+
- vendor/eac_ruby_base0/lib/eac_ruby_base0/patches.rb
|
369
|
+
- vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/class.rb
|
370
|
+
- vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/class/jobs_runner.rb
|
371
|
+
- vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/object.rb
|
372
|
+
- vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/object/runner_with.rb
|
359
373
|
- vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb
|
360
374
|
- vendor/eac_ruby_base0/lib/eac_ruby_base0/runner/test_all.rb
|
375
|
+
- vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with.rb
|
376
|
+
- vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/confirmable.rb
|
377
|
+
- vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/filesystem_traverser.rb
|
361
378
|
- vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb
|
362
379
|
- vendor/eac_ruby_base0/spec/rubocop_spec.rb
|
363
380
|
- vendor/eac_ruby_base0/spec/spec_helper.rb
|
@@ -451,6 +468,7 @@ files:
|
|
451
468
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches.rb
|
452
469
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class.rb
|
453
470
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/common_constructor.rb
|
471
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/settings_provider.rb
|
454
472
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb
|
455
473
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb
|
456
474
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb
|
@@ -474,6 +492,7 @@ files:
|
|
474
492
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object.rb
|
475
493
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb
|
476
494
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
|
495
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
|
477
496
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
|
478
497
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
|
479
498
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb
|
@@ -485,7 +504,7 @@ files:
|
|
485
504
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb
|
486
505
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb
|
487
506
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time.rb
|
488
|
-
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/
|
507
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/required_zone.rb
|
489
508
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb
|
490
509
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb
|
491
510
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb
|