eac_cli 0.19.0 → 0.20.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfee9c78c899be3c4e2d36915e4d0cac08cf5f2a63269813b5c05527a06d0e75
4
- data.tar.gz: c0374336ed9fea6c351ce00b0a9e5e210b53ca7a34c201dc1a0699fcda12b943
3
+ metadata.gz: ac084c510379ffad8feceff82e7bb5f8526663a8eec785432283a2c8a567797a
4
+ data.tar.gz: 5efaada363d342f60d2aa55cc3823f39f84e64d9c422c4dabc4feb6be379decf
5
5
  SHA512:
6
- metadata.gz: d2e1c8009e10490cde982e4d8cc0fce02d67d0114ddb3a852180298c6f83edd7d5e4e2ee0bf04188199d615739297b3fdbf41a61d532e6614b86dece3c63b864
7
- data.tar.gz: fba7139e87ea3959a2498f20d83a08d19c299acd71e576ed0d446ca47a77bb97ab9e670c4280984001feb6467d6cdd01d3a989dc6b44b5e4d5345d9f87c66a0c
6
+ metadata.gz: 8e23f76ed8257b2285858741963451934c3de72f7d4de00d302e2c4cb6b8780d162455aad9a40831eb98402eec28673de8b55e69594a026214543a9b093b8ec5
7
+ data.tar.gz: f7c3e55370d73d0d9910ecdbb2c231245895862e33b84831496afe626e87e66d2f70c8863b153ad5f03e3bc1dae14663571947d91dfd3f3dba48035fc5ef1625
@@ -10,7 +10,7 @@ module EacCli
10
10
  require_sub __FILE__, include_modules: true
11
11
  enable_listable
12
12
  enable_simple_cache
13
- include ::EacCli::Speaker
13
+ enable_speaker
14
14
 
15
15
  common_constructor :config, :path, :options do
16
16
  self.path = ::EacConfig::EntryPath.assert(path)
@@ -18,7 +18,7 @@ module EacCli
18
18
  end
19
19
 
20
20
  def undefined_value_no_loop
21
- request_input("Value for entry \"#{path}\"", options.request_input_options)
21
+ input("Value for entry \"#{path}\"", options.request_input_options)
22
22
  end
23
23
  end
24
24
  end
@@ -10,6 +10,10 @@ module EacCli
10
10
  def argv
11
11
  runner.settings[:argv] || ARGV
12
12
  end
13
+
14
+ def program_name
15
+ runner.settings[:program_name] || $PROGRAM_NAME
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -6,6 +6,7 @@ require 'docopt'
6
6
  module EacCli
7
7
  class DocoptRunner
8
8
  require_sub __FILE__
9
+ extend ::EacCli::DocoptRunner::ClassMethods
9
10
  include ::EacCli::DocoptRunner::Context
10
11
 
11
12
  class << self
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'docopt'
4
+
3
5
  module EacCli
4
6
  class DocoptRunner
5
- DOCOPT_ERROR_EXIT_CODE = 0xC0
7
+ module ClassMethods
8
+ DOCOPT_ERROR_EXIT_CODE = 0xC0
6
9
 
7
- class << self
8
10
  def run(options = {})
9
11
  create(options).send(:run)
10
- rescue Docopt::Exit => e
12
+ rescue ::Docopt::Exit => e
11
13
  STDERR.write(e.message + "\n")
12
14
  ::Kernel.exit(DOCOPT_ERROR_EXIT_CODE)
13
15
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
- require 'eac_cli/patches/module/speaker'
5
4
 
6
5
  module EacCli
7
6
  class OldConfigs
@@ -70,8 +70,8 @@ module EacCli
70
70
  end
71
71
 
72
72
  def entry_value_from_input(entry_key, options)
73
- entry_value = request_input("Value for entry \"#{entry_key}\"",
74
- options.request_input_options)
73
+ entry_value = input("Value for entry \"#{entry_key}\"",
74
+ options.request_input_options)
75
75
  warn('Entered value is blank') if entry_value.blank?
76
76
  entry_value
77
77
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_cli/speaker'
4
+ require 'eac_ruby_utils/speaker'
5
+
3
6
  module EacCli
4
7
  module Runner
5
8
  module AfterClassMethods
@@ -10,9 +13,11 @@ module EacCli
10
13
  end
11
14
 
12
15
  def run(*runner_context_args)
13
- r = create(*runner_context_args)
14
- r.run_run
15
- r
16
+ on_asserted_speaker do
17
+ r = create(*runner_context_args)
18
+ r.run_run
19
+ r
20
+ end
16
21
  end
17
22
 
18
23
  def runner_definition(&block)
@@ -24,6 +29,18 @@ module EacCli
24
29
  def super_runner_definition
25
30
  superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
26
31
  end
32
+
33
+ private
34
+
35
+ def on_asserted_speaker
36
+ if ::EacRubyUtils::Speaker.context.optional_current
37
+ yield
38
+ else
39
+ ::EacRubyUtils::Speaker.context.on(::EacCli::Speaker.new) do
40
+ yield
41
+ end
42
+ end
43
+ end
27
44
  end
28
45
  end
29
46
  end
@@ -15,7 +15,7 @@ module EacCli
15
15
  end
16
16
 
17
17
  def run_parser_error(error)
18
- $stderr.write("#{error}\n")
18
+ $stderr.write("#{program_name}: #{error}\n")
19
19
  ::Kernel.exit(PARSER_ERROR_EXIT_CODE)
20
20
  end
21
21
 
@@ -33,6 +33,10 @@ module EacCli
33
33
  def parsed
34
34
  @parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
35
35
  end
36
+
37
+ def program_name
38
+ runner_context.if_present(&:program_name) || $PROGRAM_NAME
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -10,7 +10,7 @@ module EacCli
10
10
  include ::EacCli::Runner
11
11
 
12
12
  runner_definition.alt do
13
- bool_opt '-h', '--help', 'Show help.', usage: true
13
+ bool_opt '-h', '--help', 'Show help.', usage: true, required: true
14
14
  pos_arg :any_arg_with_help, repeat: true, optional: true, visible: false
15
15
  end
16
16
 
@@ -1,26 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'colorize'
4
- require 'io/console'
5
- require 'eac_ruby_utils/patches/hash/options_consumer'
6
- require 'eac_ruby_utils/require_sub'
7
- ::EacRubyUtils.require_sub __FILE__
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/speaker/receiver'
8
6
 
9
7
  module EacCli
10
- # https://github.com/fazibear/colorize
11
- module Speaker
12
- def on_speaker_node(&block)
13
- ::EacCli::Speaker.on_node(&block)
8
+ class Speaker
9
+ require_sub __FILE__, include_modules: true
10
+ include ::EacRubyUtils::Speaker::Receiver
11
+
12
+ common_constructor :options, default: [{}] do
13
+ self.options = self.class.lists.option.hash_keys_validate!(options)
14
14
  end
15
15
 
16
16
  def puts(string = '')
17
17
  string.to_s.each_line do |line|
18
- current_node.stderr.puts(current_node.stderr_line_prefix.to_s + line)
18
+ err_out.puts(err_line_prefix.to_s + line)
19
19
  end
20
20
  end
21
21
 
22
22
  def out(string = '')
23
- current_node.stdout.write(string.to_s)
23
+ out_out.write(string.to_s)
24
24
  end
25
25
 
26
26
  def fatal_error(string)
@@ -52,7 +52,7 @@ module EacCli
52
52
  # +bool+ ([Boolean], default: +false+): requires a answer "yes" or "no".
53
53
  # +list+ ([Hash] or [Array], default: +nil+): requires a answer from a list.
54
54
  # +noecho+ ([Boolean], default: +false+): does not output answer.
55
- def request_input(question, options = {})
55
+ def input(question, options = {})
56
56
  bool, list, noecho = options.to_options_consumer.consume_all(:bool, :list, :noecho)
57
57
  if list
58
58
  request_from_list(question, list, noecho)
@@ -110,22 +110,18 @@ module EacCli
110
110
  end
111
111
 
112
112
  def request_string(question, noecho)
113
- current_node.stderr.write "#{question}: ".to_s.yellow
113
+ err_out.write "#{question}: ".to_s.yellow
114
114
  noecho ? request_string_noecho : request_string_echo
115
115
  end
116
116
 
117
117
  def request_string_noecho
118
- r = current_node.stdin.noecho(&:gets).chomp.strip
119
- current_node.stderr.write("\n")
118
+ r = in_in.noecho(&:gets).chomp.strip
119
+ err_out.write("\n")
120
120
  r
121
121
  end
122
122
 
123
123
  def request_string_echo
124
- current_node.stdin.gets.chomp.strip
125
- end
126
-
127
- def current_node
128
- ::EacCli::Speaker.current_node
124
+ in_in.gets.chomp.strip
129
125
  end
130
126
  end
131
127
  end
@@ -4,7 +4,7 @@ require 'eac_ruby_utils/by_reference'
4
4
 
5
5
  module EacCli
6
6
  # https://github.com/fazibear/colorize
7
- module Speaker
7
+ class Speaker
8
8
  STDERR = ::EacRubyUtils::ByReference.new { $stderr }
9
9
  STDIN = ::EacRubyUtils::ByReference.new { $stdin }
10
10
  STDOUT = ::EacRubyUtils::ByReference.new { $stdout }
@@ -4,7 +4,7 @@ require 'active_support/hash_with_indifferent_access'
4
4
  require 'ostruct'
5
5
 
6
6
  module EacCli
7
- module Speaker
7
+ class Speaker
8
8
  class List
9
9
  class << self
10
10
  def build(list)
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ class Speaker
7
+ module Options
8
+ common_concern do
9
+ enable_listable
10
+ lists.add_symbol :option, :out_out, :err_out, :in_in, :parent, :err_line_prefix
11
+ end
12
+
13
+ def err_out
14
+ option(OPTION_ERR_OUT, ::EacCli::Speaker::STDERR)
15
+ end
16
+
17
+ def out_out
18
+ option(OPTION_OUT_OUT, ::EacCli::Speaker::STDOUT)
19
+ end
20
+
21
+ def in_in
22
+ option(OPTION_IN_IN, ::EacCli::Speaker::STDIN)
23
+ end
24
+
25
+ def err_line_prefix
26
+ option(OPTION_ERR_LINE_PREFIX, '')
27
+ end
28
+
29
+ def parent
30
+ options[OPTION_PARENT]
31
+ end
32
+
33
+ def option(key, default)
34
+ options[key] || parent.if_present(default) { |v| v.send(__METHOD__) }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.19.0'
4
+ VERSION = '0.20.4'
5
5
  end
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.19.0
4
+ version: 0.20.4
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-06-02 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.64'
61
+ version: '0.67'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.64'
68
+ version: '0.67'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: eac_ruby_gem_support
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -107,10 +107,10 @@ files:
107
107
  - lib/eac_cli/docopt/runner_context_replacement.rb
108
108
  - lib/eac_cli/docopt/runner_extension.rb
109
109
  - lib/eac_cli/docopt_runner.rb
110
- - lib/eac_cli/docopt_runner/_class_methods.rb
111
110
  - lib/eac_cli/docopt_runner/_doc.rb
112
111
  - lib/eac_cli/docopt_runner/_settings.rb
113
112
  - lib/eac_cli/docopt_runner/_subcommands.rb
113
+ - lib/eac_cli/docopt_runner/class_methods.rb
114
114
  - lib/eac_cli/docopt_runner/context.rb
115
115
  - lib/eac_cli/old_configs.rb
116
116
  - lib/eac_cli/old_configs/entry_reader.rb
@@ -130,8 +130,6 @@ files:
130
130
  - lib/eac_cli/parser/collector.rb
131
131
  - lib/eac_cli/parser/error.rb
132
132
  - lib/eac_cli/patches.rb
133
- - lib/eac_cli/patches/module.rb
134
- - lib/eac_cli/patches/module/speaker.rb
135
133
  - lib/eac_cli/patches/object.rb
136
134
  - lib/eac_cli/patches/object/runner_with.rb
137
135
  - lib/eac_cli/runner.rb
@@ -145,10 +143,9 @@ files:
145
143
  - lib/eac_cli/runner_with/subcommands/definition_concern.rb
146
144
  - lib/eac_cli/runner_with_set.rb
147
145
  - lib/eac_cli/speaker.rb
148
- - lib/eac_cli/speaker/_class_methods.rb
149
146
  - lib/eac_cli/speaker/_constants.rb
150
147
  - lib/eac_cli/speaker/list.rb
151
- - lib/eac_cli/speaker/node.rb
148
+ - lib/eac_cli/speaker/options.rb
152
149
  - lib/eac_cli/version.rb
153
150
  homepage:
154
151
  licenses: []
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/require_sub'
4
- ::EacRubyUtils.require_sub(__FILE__)
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/speaker'
4
- require 'eac_ruby_utils/patch'
5
-
6
- class Module
7
- def enable_speaker
8
- ::EacRubyUtils.patch(self, ::EacCli::Speaker)
9
- end
10
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/speaker/node'
4
-
5
- module EacCli
6
- module Speaker
7
- class << self
8
- def current_node
9
- nodes_stack.last
10
- end
11
-
12
- def on_node(&block)
13
- push
14
- yield(*(block.arity.zero? ? [] : [current_node]))
15
- ensure
16
- pop
17
- end
18
-
19
- def push
20
- nodes_stack << ::EacCli::Speaker::Node.new
21
- current_node
22
- end
23
-
24
- def pop
25
- return nodes_stack.pop if nodes_stack.count > 1
26
-
27
- raise "Cannot remove first node (nodes_stack.count: #{nodes_stack.count})"
28
- end
29
-
30
- private
31
-
32
- def nodes_stack
33
- @nodes_stack ||= [::EacCli::Speaker::Node.new]
34
- end
35
- end
36
- end
37
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/patches/object/if_present'
4
- require 'eac_cli/speaker/_constants'
5
-
6
- module EacCli
7
- module Speaker
8
- class Node
9
- attr_accessor :stdin, :stdout, :stderr, :stderr_line_prefix
10
-
11
- def initialize(parent = nil)
12
- self.stdin = parent.if_present(::EacCli::Speaker::STDIN, &:stdin)
13
- self.stdout = parent.if_present(::EacCli::Speaker::STDOUT, &:stdout)
14
- self.stderr = parent.if_present(::EacCli::Speaker::STDERR, &:stderr)
15
- self.stderr_line_prefix = parent.if_present('', &:stderr_line_prefix)
16
- end
17
-
18
- def configure
19
- yield(self)
20
- self
21
- end
22
- end
23
- end
24
- end