eac_cli 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_cli/config.rb +19 -0
- data/lib/eac_cli/config/entry.rb +46 -0
- data/lib/eac_cli/config/entry/options.rb +57 -0
- data/lib/eac_cli/config/entry/undefined.rb +26 -0
- data/lib/eac_cli/docopt_runner.rb +3 -8
- data/lib/eac_cli/docopt_runner/context.rb +18 -0
- data/lib/eac_cli/old_configs_bridge.rb +37 -0
- data/lib/eac_cli/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24ca129d2aa0ed0babd8928e4f3d2b20462566e0a3bc88e1255ba63513e11442
|
4
|
+
data.tar.gz: 249aa6c5592be11f6e831972342f5be95b9783524df4176616e643b44fdacac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 645a80ceb7ef1af1444f88c753eeb2034cac3e78d6eb6a192103c4eb507c35f8b51756a9ba1f30ba25b8770cf61f74d7cb46341571946479943c7805873b5c46
|
7
|
+
data.tar.gz: 594439ed558f99ebe910faa4b060b32a0916479d92baa230fd2fac5e61da4f0f8557fed270978cd7ee62db577454fd53ab0acdc7da2ffebae709f47613dfb0c2
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_config/envvars_node'
|
4
|
+
require 'eac_config/yaml_file_node'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
class Config
|
8
|
+
require_sub __FILE__
|
9
|
+
attr_reader :sub
|
10
|
+
|
11
|
+
def initialize(sub_node)
|
12
|
+
@sub = sub_node
|
13
|
+
end
|
14
|
+
|
15
|
+
def entry(path, options = {})
|
16
|
+
::EacCli::Config::Entry.new(self, path, options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/speaker'
|
4
|
+
require 'eac_config/entry_path'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module EacCli
|
8
|
+
class Config
|
9
|
+
class Entry
|
10
|
+
require_sub __FILE__, include_modules: true
|
11
|
+
enable_listable
|
12
|
+
enable_simple_cache
|
13
|
+
include ::EacCli::Speaker
|
14
|
+
|
15
|
+
common_constructor :config, :path, :options do
|
16
|
+
self.path = ::EacConfig::EntryPath.assert(path)
|
17
|
+
self.options = ::EacCli::Config::Entry::Options.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def value
|
21
|
+
return sub_value_to_return if sub_entry.found?
|
22
|
+
return nil unless options.required?
|
23
|
+
|
24
|
+
puts "|#{sub_entry.path}|"
|
25
|
+
|
26
|
+
input_value
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def sub_value_to_return
|
32
|
+
sub_entry.value.presence || ::EacRubyUtils::BlankNotBlank.instance
|
33
|
+
end
|
34
|
+
|
35
|
+
def sub_entry_uncached
|
36
|
+
config.sub.entry(path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def input_value_uncached
|
40
|
+
r = send("#{options.type}_value")
|
41
|
+
sub_entry.value = r if options.store?
|
42
|
+
r
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
class Config
|
7
|
+
class Entry
|
8
|
+
class Options
|
9
|
+
enable_simple_cache
|
10
|
+
enable_listable
|
11
|
+
|
12
|
+
lists.add_symbol :type, :undefined
|
13
|
+
|
14
|
+
DEFAULT_VALUES = {
|
15
|
+
before_input: nil, bool: false, list: false, noecho: false, noenv: false, noinput: false,
|
16
|
+
required: true, store: true, type: TYPE_UNDEFINED, validator: nil
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
lists.add_symbol :option, *DEFAULT_VALUES.keys
|
20
|
+
|
21
|
+
common_constructor :options do
|
22
|
+
self.options = self.class.lists.option.hash_keys_validate!(options)
|
23
|
+
end
|
24
|
+
|
25
|
+
delegate :to_h, to: :options
|
26
|
+
|
27
|
+
def [](key)
|
28
|
+
values.fetch(key.to_sym)
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_input_options
|
32
|
+
values.slice(:bool, :list, :noecho)
|
33
|
+
end
|
34
|
+
|
35
|
+
DEFAULT_VALUES.each do |attr, default_value|
|
36
|
+
define_method(attr.to_s + ([true, false].include?(default_value) ? '?' : '')) do
|
37
|
+
self[attr]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def values_uncached
|
44
|
+
consumer = options.to_options_consumer
|
45
|
+
r = {}
|
46
|
+
DEFAULT_VALUES.each do |key, default_value|
|
47
|
+
value = consumer.consume(key)
|
48
|
+
value = default_value if value.nil?
|
49
|
+
r[key] = value
|
50
|
+
end
|
51
|
+
consumer.validate
|
52
|
+
r
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
class Config
|
7
|
+
class Entry
|
8
|
+
module Undefined
|
9
|
+
private
|
10
|
+
|
11
|
+
def undefined_value
|
12
|
+
loop do
|
13
|
+
entry_value = undefined_value_no_loop
|
14
|
+
next unless options[:validator].if_present(true) { |v| v.call(entry_value) }
|
15
|
+
|
16
|
+
return entry_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def undefined_value_no_loop
|
21
|
+
request_input("Value for entry \"#{path}\"", options.request_input_options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,17 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'active_support/core_ext/hash/slice'
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
5
4
|
require 'docopt'
|
6
|
-
require 'eac_ruby_utils/contextualizable'
|
7
|
-
require 'eac_ruby_utils/patches/hash/sym_keys_hash'
|
8
|
-
Dir["#{__dir__}/#{::File.basename(__FILE__, '.*')}/_*.rb"].sort.each do |partial|
|
9
|
-
require partial
|
10
|
-
end
|
11
5
|
|
12
6
|
module EacCli
|
13
7
|
class DocoptRunner
|
14
|
-
|
8
|
+
require_sub __FILE__
|
9
|
+
include ::EacCli::DocoptRunner::Context
|
15
10
|
|
16
11
|
class << self
|
17
12
|
def create(settings = {})
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class DocoptRunner
|
5
|
+
# Provides the method context which search and call a method in self and ancestor objects.
|
6
|
+
module Context
|
7
|
+
def context(method)
|
8
|
+
current = self
|
9
|
+
while current
|
10
|
+
return current.send(method) if current.respond_to?(method)
|
11
|
+
|
12
|
+
current = current.respond_to?(:parent) ? current.parent : nil
|
13
|
+
end
|
14
|
+
raise "Context method \"#{method}\" not found for #{self.class}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/config'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
class OldConfigsBridge < ::EacCli::Config
|
8
|
+
ENTRY_KEY = 'core.store_passwords'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def new_configs_path(configs_key, options)
|
12
|
+
options[:storage_path] || ::File.join(ENV['HOME'], '.config', configs_key, 'settings.yml')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(configs_key, options = {})
|
17
|
+
options.assert_argument(::Hash, 'options')
|
18
|
+
envvar_node = ::EacConfig::EnvvarsNode.new
|
19
|
+
file_node = ::EacConfig::YamlFileNode.new(self.class.new_configs_path(configs_key, options))
|
20
|
+
envvar_node.load_path.push(file_node.url)
|
21
|
+
envvar_node.write_node = file_node
|
22
|
+
super(envvar_node)
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_entry(entry_key, options = {})
|
26
|
+
entry(entry_key, options).value
|
27
|
+
end
|
28
|
+
|
29
|
+
def read_password(entry_key, options = {})
|
30
|
+
entry(entry_key, options.merge(noecho: true, store: store_passwords?)).value
|
31
|
+
end
|
32
|
+
|
33
|
+
def store_passwords?
|
34
|
+
read_entry(ENTRY_KEY, bool: true)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/eac_cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -88,6 +88,10 @@ extra_rdoc_files: []
|
|
88
88
|
files:
|
89
89
|
- Gemfile
|
90
90
|
- lib/eac_cli.rb
|
91
|
+
- lib/eac_cli/config.rb
|
92
|
+
- lib/eac_cli/config/entry.rb
|
93
|
+
- lib/eac_cli/config/entry/options.rb
|
94
|
+
- lib/eac_cli/config/entry/undefined.rb
|
91
95
|
- lib/eac_cli/core_ext.rb
|
92
96
|
- lib/eac_cli/default_runner.rb
|
93
97
|
- lib/eac_cli/definition.rb
|
@@ -107,11 +111,13 @@ files:
|
|
107
111
|
- lib/eac_cli/docopt_runner/_doc.rb
|
108
112
|
- lib/eac_cli/docopt_runner/_settings.rb
|
109
113
|
- lib/eac_cli/docopt_runner/_subcommands.rb
|
114
|
+
- lib/eac_cli/docopt_runner/context.rb
|
110
115
|
- lib/eac_cli/old_configs.rb
|
111
116
|
- lib/eac_cli/old_configs/entry_reader.rb
|
112
117
|
- lib/eac_cli/old_configs/password_entry_reader.rb
|
113
118
|
- lib/eac_cli/old_configs/read_entry_options.rb
|
114
119
|
- lib/eac_cli/old_configs/store_passwords_entry_reader.rb
|
120
|
+
- lib/eac_cli/old_configs_bridge.rb
|
115
121
|
- lib/eac_cli/parser.rb
|
116
122
|
- lib/eac_cli/parser/alternative.rb
|
117
123
|
- lib/eac_cli/parser/alternative/argv.rb
|