eac_cli 0.30.1 → 0.32.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/runner_with/confirmation.rb +44 -0
- data/lib/eac_cli/runner_with/help/builder.rb +38 -21
- data/lib/eac_cli/runner_with/help/list_section.rb +22 -0
- data/lib/eac_cli/runner_with/help.rb +3 -4
- data/lib/eac_cli/runner_with/input.rb +36 -0
- data/lib/eac_cli/runner_with/output.rb +58 -0
- data/lib/eac_cli/runner_with/subcommands.rb +5 -2
- data/lib/eac_cli/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1e50e2a284a092f29a86d4ed6871c5f72d60cd0b655f8ab991d281bc0245786
|
4
|
+
data.tar.gz: 88e1aac4d700544a32debe645752a192f2732ee2e4f248796a952acf33853dab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cfe95828490465373b2cacb1f7a8a087903466b89ec0a7fb208cbe05742c5a8c498834350aa35d606cefe900e088853c9b6f5fd5213c71e4a25bb1843616564
|
7
|
+
data.tar.gz: 9d38a66bd9b3b1f3dea27c386a50a26c430cc94ed142ab5733297ab499ad4bf718b04f17d81b765e54e6d9c08e3517abc519877b54bf521e2c15e6704c80db75
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module RunnerWith
|
8
|
+
module Confirmation
|
9
|
+
DEFAULT_CONFIRM_QUESTION_TEXT = 'Confirm?'
|
10
|
+
|
11
|
+
common_concern do
|
12
|
+
include ::EacCli::Runner
|
13
|
+
enable_settings_provider
|
14
|
+
enable_simple_cache
|
15
|
+
runner_definition do
|
16
|
+
bool_opt '--no', 'Deny confirmation without question.'
|
17
|
+
bool_opt '--yes', 'Accept confirmation without question.'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def confirm?(message = nil)
|
22
|
+
return false if parsed.no?
|
23
|
+
return true if parsed.yes?
|
24
|
+
|
25
|
+
input(
|
26
|
+
message || setting_value(:confirm_question_text, default: DEFAULT_CONFIRM_QUESTION_TEXT),
|
27
|
+
bool: true
|
28
|
+
)
|
29
|
+
rescue ::EacCli::Speaker::InputRequested => e
|
30
|
+
fatal_error e.message
|
31
|
+
end
|
32
|
+
|
33
|
+
def run_confirm(message = nil)
|
34
|
+
yield if confirm?(message)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def cached_confirm_uncached?(message = nil)
|
40
|
+
confirm?(message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_cli/runner_with/help/list_section'
|
3
4
|
require 'eac_ruby_utils/core_ext'
|
4
5
|
|
5
6
|
module EacCli
|
@@ -9,9 +10,8 @@ module EacCli
|
|
9
10
|
require_sub __FILE__, require_dependency: true
|
10
11
|
common_constructor :runner
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
OPTION_DESC_SEP = IDENT * 2
|
13
|
+
OPTION_DESC_SEP = ::EacCli::RunnerWith::Help::ListSection::IDENTATION * 2
|
14
|
+
SECTION_SEPARATOR = "\n"
|
15
15
|
|
16
16
|
class << self
|
17
17
|
def option_long(option)
|
@@ -35,7 +35,7 @@ module EacCli
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def word_separator
|
38
|
-
|
38
|
+
::EacCli::RunnerWith::Help::ListSection::WORD_SEPARATOR
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -45,36 +45,53 @@ module EacCli
|
|
45
45
|
runner.class.runner_definition
|
46
46
|
end
|
47
47
|
|
48
|
+
# @return [String, nil]
|
49
|
+
def extra_section
|
50
|
+
ess = extra_sections
|
51
|
+
return nil if ess.none?
|
52
|
+
|
53
|
+
ess.join(SECTION_SEPARATOR)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Enumerable<String>]
|
57
|
+
def extra_sections
|
58
|
+
runner.if_respond(:help_extra_text, []) do |v|
|
59
|
+
if v.is_a?(::Hash)
|
60
|
+
v.map do |title, lines|
|
61
|
+
::EacCli::RunnerWith::Help::ListSection.new(title, lines)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
[v.to_s]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
48
69
|
def option_definition(option)
|
49
70
|
[self.class.option_usage_full(option), option.description,
|
50
71
|
option.default_value? ? "[Default: \"#{option.default_value}\"]" : nil]
|
51
72
|
.reject(&:blank?).join(OPTION_DESC_SEP)
|
52
73
|
end
|
53
74
|
|
54
|
-
|
55
|
-
b = include_header ? "#{header.humanize}:\n" : ''
|
56
|
-
b += send("self_#{header}") + "\n"
|
57
|
-
definition.alternatives.each do |alternative|
|
58
|
-
b += IDENT + self.alternative(alternative) + "\n"
|
59
|
-
end
|
60
|
-
b
|
61
|
-
end
|
62
|
-
|
75
|
+
# @return [String]
|
63
76
|
def options_section
|
64
|
-
|
65
|
-
|
66
|
-
|
77
|
+
::EacCli::RunnerWith::Help::ListSection.new(
|
78
|
+
'Options',
|
79
|
+
definition.alternatives.flat_map(&:options).map { |option| option_definition(option) }
|
80
|
+
)
|
67
81
|
end
|
68
82
|
|
83
|
+
# @return [String]
|
69
84
|
def usage_section
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
85
|
+
::EacCli::RunnerWith::Help::ListSection.new(
|
86
|
+
'Usage',
|
87
|
+
definition.alternatives.map { |alternative| self.alternative(alternative) }
|
88
|
+
)
|
74
89
|
end
|
75
90
|
|
76
91
|
def to_s
|
77
|
-
"#{definition.description}\n
|
92
|
+
r = ["#{definition.description}\n", usage_section, options_section]
|
93
|
+
.map { |s| "#{s}#{SECTION_SEPARATOR}" }.join
|
94
|
+
extra_section.if_present(r) { |v| r + v }
|
78
95
|
end
|
79
96
|
end
|
80
97
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
module RunnerWith
|
7
|
+
module Help
|
8
|
+
class ListSection
|
9
|
+
WORD_SEPARATOR = ' '
|
10
|
+
IDENTATION = WORD_SEPARATOR * 2
|
11
|
+
|
12
|
+
common_constructor :title, :items
|
13
|
+
|
14
|
+
# @return [String]
|
15
|
+
def to_s
|
16
|
+
(["#{title}:"] + items.map { |line| "#{IDENTATION}#{line}" })
|
17
|
+
.map { |line| "#{line}\n" }.join
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -6,7 +6,7 @@ require 'eac_ruby_utils/core_ext'
|
|
6
6
|
module EacCli
|
7
7
|
module RunnerWith
|
8
8
|
module Help
|
9
|
-
require_sub __FILE__,
|
9
|
+
require_sub __FILE__, require_mode: :kernel
|
10
10
|
common_concern do
|
11
11
|
include ::EacCli::Runner
|
12
12
|
|
@@ -27,10 +27,9 @@ module EacCli
|
|
27
27
|
raise ::EacCli::Runner::Exit
|
28
28
|
end
|
29
29
|
|
30
|
+
# @return [String]
|
30
31
|
def help_text
|
31
|
-
|
32
|
-
r += help_extra_text if respond_to?(:help_extra_text)
|
33
|
-
r
|
32
|
+
::EacCli::RunnerWith::Help::Builder.new(self).to_s
|
34
33
|
end
|
35
34
|
|
36
35
|
def show_help?
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'eac_ruby_utils/abstract_methods'
|
6
|
+
|
7
|
+
module EacCli
|
8
|
+
module RunnerWith
|
9
|
+
module Input
|
10
|
+
STDIN_OPTION = '-'
|
11
|
+
BLANK_OPTION = '+'
|
12
|
+
DEFAULT_DEFAULT_INPUT_OPTION = BLANK_OPTION
|
13
|
+
|
14
|
+
common_concern do
|
15
|
+
enable_settings_provider
|
16
|
+
include ::EacCli::Runner
|
17
|
+
|
18
|
+
runner_definition do
|
19
|
+
arg_opt '-i', '--input', 'Input from file.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def input_content
|
24
|
+
case input_option
|
25
|
+
when STDIN_OPTION then $stdin.read
|
26
|
+
when BLANK_OPTION then ''
|
27
|
+
else input_option.to_pathname.read
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def input_option
|
32
|
+
parsed.input || setting_value(:default_input_option, default: DEFAULT_DEFAULT_INPUT_OPTION)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'eac_ruby_utils/abstract_methods'
|
6
|
+
|
7
|
+
module EacCli
|
8
|
+
module RunnerWith
|
9
|
+
module Output
|
10
|
+
STDOUT_OPTION = '-'
|
11
|
+
DEFAULT_FILE_OPTION = '+'
|
12
|
+
DEFAULT_DEFAULT_OUTPUT_OPTION = STDOUT_OPTION
|
13
|
+
DEFAULT_DEFAULT_FILE_TO_OUTPUT = 'output'
|
14
|
+
|
15
|
+
common_concern do
|
16
|
+
enable_abstract_methods
|
17
|
+
enable_settings_provider
|
18
|
+
include ::EacCli::Runner
|
19
|
+
|
20
|
+
abstract_methods :output_content
|
21
|
+
|
22
|
+
runner_definition do
|
23
|
+
arg_opt '-o', '--output', 'Output to file.'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_output
|
28
|
+
file = file_to_output
|
29
|
+
if file
|
30
|
+
file.to_pathname.write(output_content)
|
31
|
+
else
|
32
|
+
$stdout.write(output_content)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def output_option
|
37
|
+
parsed.output || default_output_option_value
|
38
|
+
end
|
39
|
+
|
40
|
+
def file_to_output
|
41
|
+
case output_option
|
42
|
+
when STDOUT_OPTION then nil
|
43
|
+
when DEFAULT_FILE_OPTION then default_file_to_output_value
|
44
|
+
else output_option
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_output_option_value
|
49
|
+
setting_value(:default_output_option,
|
50
|
+
default: DEFAULT_DEFAULT_OUTPUT_OPTION)
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_file_to_output_value
|
54
|
+
setting_value(:default_file_to_output, default: DEFAULT_DEFAULT_FILE_TO_OUTPUT)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -51,9 +51,12 @@ module EacCli
|
|
51
51
|
available_subcommands.keys.sort.join(', ')
|
52
52
|
end
|
53
53
|
|
54
|
+
# @return [Hash<String, Enumerable<String>]
|
54
55
|
def help_extra_text
|
55
|
-
|
56
|
-
|
56
|
+
{
|
57
|
+
'Subcommands' =>
|
58
|
+
available_subcommands.keys.sort
|
59
|
+
}
|
57
60
|
end
|
58
61
|
|
59
62
|
def method_missing(method_name, *arguments, &block)
|
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.32.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: 2023-
|
11
|
+
date: 2023-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0.
|
53
|
+
version: '0.113'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0.
|
60
|
+
version: '0.113'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: eac_ruby_gem_support
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,9 +122,13 @@ files:
|
|
122
122
|
- lib/eac_cli/runner/exit.rb
|
123
123
|
- lib/eac_cli/runner/instance_methods.rb
|
124
124
|
- lib/eac_cli/runner_with.rb
|
125
|
+
- lib/eac_cli/runner_with/confirmation.rb
|
125
126
|
- lib/eac_cli/runner_with/help.rb
|
126
127
|
- lib/eac_cli/runner_with/help/builder.rb
|
127
128
|
- lib/eac_cli/runner_with/help/builder/alternative.rb
|
129
|
+
- lib/eac_cli/runner_with/help/list_section.rb
|
130
|
+
- lib/eac_cli/runner_with/input.rb
|
131
|
+
- lib/eac_cli/runner_with/output.rb
|
128
132
|
- lib/eac_cli/runner_with/subcommands.rb
|
129
133
|
- lib/eac_cli/runner_with/subcommands/definition_concern.rb
|
130
134
|
- lib/eac_cli/runner_with_set.rb
|