eac_tools 0.103.0 → 0.103.1
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 +4 -4
- data/Gemfile.lock +22 -27
- data/lib/eac_tools/version.rb +1 -1
- data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +1 -1
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/apache_host.rb +0 -2
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/database.rb +0 -3
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/files.rb +0 -4
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/gitolite.rb +0 -3
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/install.rb +0 -3
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/nodejs.rb +0 -3
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/web.rb +0 -3
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base.rb +1 -7
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/deploy.rb +0 -3
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/docker_image.rb +0 -6
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/entity_base.rb +0 -4
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/project.rb +0 -5
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/root.rb +0 -4
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/wiki_page.rb +0 -4
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api.rb +0 -4
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/docker.rb +0 -2
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project/wiki_page/read.rb +0 -2
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project/wiki_page/write.rb +0 -2
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project/wiki_page.rb +0 -4
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project.rb +0 -4
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project_rename.rb +0 -3
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/base.rb +0 -4
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/core_update.rb +0 -6
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/core_update.rb +0 -4
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/docker.rb +0 -3
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
- data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/instances/docker_image/Dockerfile.template +1 -0
- data/sub/eac_cli/eac_cli.gemspec +23 -0
- data/sub/eac_cli/lib/eac_cli/config/entry/options.rb +55 -0
- data/sub/eac_cli/lib/eac_cli/config/entry/undefined.rb +26 -0
- data/sub/eac_cli/lib/eac_cli/config/entry.rb +55 -0
- data/sub/eac_cli/lib/eac_cli/config.rb +15 -0
- data/sub/eac_cli/lib/eac_cli/core_ext.rb +4 -0
- data/sub/eac_cli/lib/eac_cli/default_runner.rb +12 -0
- data/sub/eac_cli/lib/eac_cli/definition/alternative.rb +101 -0
- data/sub/eac_cli/lib/eac_cli/definition/argument_option.rb +19 -0
- data/sub/eac_cli/lib/eac_cli/definition/boolean_option.rb +25 -0
- data/sub/eac_cli/lib/eac_cli/definition/error.rb +8 -0
- data/sub/eac_cli/lib/eac_cli/definition/option/initialize_args_parser.rb +48 -0
- data/sub/eac_cli/lib/eac_cli/definition/option.rb +70 -0
- data/sub/eac_cli/lib/eac_cli/definition/option_or_positional.rb +41 -0
- data/sub/eac_cli/lib/eac_cli/definition/positional.rb +50 -0
- data/sub/eac_cli/lib/eac_cli/definition.rb +104 -0
- data/sub/eac_cli/lib/eac_cli/enum.rb +42 -0
- data/sub/eac_cli/lib/eac_cli/old_configs/entry_reader.rb +76 -0
- data/sub/eac_cli/lib/eac_cli/old_configs/password_entry_reader.rb +14 -0
- data/sub/eac_cli/lib/eac_cli/old_configs/read_entry_options.rb +42 -0
- data/sub/eac_cli/lib/eac_cli/old_configs/store_passwords_entry_reader.rb +23 -0
- data/sub/eac_cli/lib/eac_cli/old_configs.rb +31 -0
- data/sub/eac_cli/lib/eac_cli/parser/alternative/any_options.rb +17 -0
- data/sub/eac_cli/lib/eac_cli/parser/alternative/argv.rb +19 -0
- data/sub/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
- data/sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb +37 -0
- data/sub/eac_cli/lib/eac_cli/parser/alternative/option_argument.rb +29 -0
- data/sub/eac_cli/lib/eac_cli/parser/alternative/options.rb +29 -0
- data/sub/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
- data/sub/eac_cli/lib/eac_cli/parser/alternative/short_options.rb +54 -0
- data/sub/eac_cli/lib/eac_cli/parser/alternative.rb +99 -0
- data/sub/eac_cli/lib/eac_cli/parser/collector.rb +52 -0
- data/sub/eac_cli/lib/eac_cli/parser/error.rb +13 -0
- data/sub/eac_cli/lib/eac_cli/parser.rb +32 -0
- data/sub/eac_cli/lib/eac_cli/patches/object/runner_with.rb +22 -0
- data/sub/eac_cli/lib/eac_cli/patches/object.rb +5 -0
- data/sub/eac_cli/lib/eac_cli/patches.rb +3 -0
- data/sub/eac_cli/lib/eac_cli/rspec/setup.rb +41 -0
- data/sub/eac_cli/lib/eac_cli/rspec.rb +7 -0
- data/sub/eac_cli/lib/eac_cli/runner/after_class_methods.rb +34 -0
- data/sub/eac_cli/lib/eac_cli/runner/class_runner.rb +32 -0
- data/sub/eac_cli/lib/eac_cli/runner/context.rb +57 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/base.rb +22 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/parent.rb +24 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner.rb +17 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner_missing_method.rb +29 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb +41 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders.rb +9 -0
- data/sub/eac_cli/lib/eac_cli/runner/exit.rb +14 -0
- data/sub/eac_cli/lib/eac_cli/runner/for_context.rb +35 -0
- data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +45 -0
- data/sub/eac_cli/lib/eac_cli/runner.rb +47 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/confirmation/input_result.rb +60 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb +65 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb +61 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/help/builder.rb +79 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/help/layout.rb +38 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/help.rb +51 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/input.rb +32 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output.rb +54 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_item/asciidoc_formatter.rb +70 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_item/base_formatter.rb +12 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_item/csv_formatter.rb +21 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_item/yaml_formatter.rb +16 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_item.rb +47 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_list/base_formatter.rb +44 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_list/csv_formatter.rb +24 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_list/tty_formatter.rb +34 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_list/yaml_formatter.rb +21 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/output_list.rb +39 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/subcommands/definition_concern.rb +10 -0
- data/sub/eac_cli/lib/eac_cli/runner_with/subcommands.rb +124 -0
- data/sub/eac_cli/lib/eac_cli/runner_with.rb +7 -0
- data/sub/eac_cli/lib/eac_cli/runner_with_set.rb +54 -0
- data/sub/eac_cli/lib/eac_cli/speaker/constants.rb +11 -0
- data/sub/eac_cli/lib/eac_cli/speaker/input_blocked.rb +14 -0
- data/sub/eac_cli/lib/eac_cli/speaker/input_requested.rb +8 -0
- data/sub/eac_cli/lib/eac_cli/speaker/list.rb +84 -0
- data/sub/eac_cli/lib/eac_cli/speaker/options.rb +42 -0
- data/sub/eac_cli/lib/eac_cli/speaker/request_from_list.rb +40 -0
- data/sub/eac_cli/lib/eac_cli/speaker.rb +114 -0
- data/sub/eac_cli/lib/eac_cli/version.rb +5 -0
- data/sub/eac_cli/lib/eac_cli.rb +14 -0
- data/sub/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +18 -0
- data/sub/eac_cli/spec/lib/eac_cli/old_configs_spec.rb +14 -0
- data/sub/eac_cli/spec/lib/eac_cli/parser/alternative/subcommands_spec.rb +58 -0
- data/sub/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +89 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner/for_context_spec.rb +79 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_spec.rb +129 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/confirmation/input_result_spec.rb +36 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/confirmation_spec.rb +42 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/help/layout_spec.rb +21 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +51 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/output_list_spec.rb +57 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb +81 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +99 -0
- data/sub/eac_cli/spec/lib/eac_cli/speaker_spec.rb +36 -0
- data/sub/{eac_docker → eac_cli}/spec/spec_helper.rb +1 -2
- metadata +108 -48
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners.rb +0 -14
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances.rb +0 -11
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners.rb +0 -13
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources.rb +0 -11
- data/sub/avm-eac_ubuntu_base0/avm-eac_ubuntu_base0.gemspec +0 -21
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/apache/resource.rb +0 -57
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/apache.rb +0 -24
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/docker_image.rb +0 -31
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/instances/base.rb +0 -24
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb +0 -82
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/runners/base/docker.rb +0 -15
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/runners/base.rb +0 -26
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/version.rb +0 -7
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0.rb +0 -13
- data/sub/avm-eac_ubuntu_base0/spec/lib/avm/eac_ubuntu_base0/docker_image_spec.rb +0 -12
- data/sub/avm-eac_ubuntu_base0/spec/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server_spec.rb +0 -11
- data/sub/avm-eac_ubuntu_base0/spec/lib/avm/eac_ubuntu_base0/runners/base/docker_spec.rb +0 -11
- data/sub/avm-eac_ubuntu_base0/spec/lib/avm/eac_ubuntu_base0/runners/base_spec.rb +0 -5
- data/sub/avm-eac_ubuntu_base0/spec/spec_helper.rb +0 -5
- data/sub/avm-eac_ubuntu_base0/template/avm/eac_ubuntu_base0/docker_image/Dockerfile.template +0 -27
- data/sub/avm-eac_ubuntu_base0/template/avm/eac_ubuntu_base0/rspec/ssh_docker_server/Dockerfile.template +0 -24
- data/sub/avm-eac_ubuntu_base0/template/avm/eac_ubuntu_base0/rspec/ssh_docker_server/id_rsa +0 -27
- data/sub/avm-eac_ubuntu_base0/template/avm/eac_ubuntu_base0/rspec/ssh_docker_server/id_rsa.pub +0 -1
- data/sub/eac_docker/Gemfile +0 -8
- data/sub/eac_docker/eac_docker.gemspec +0 -20
- data/sub/eac_docker/lib/eac_docker/container.rb +0 -83
- data/sub/eac_docker/lib/eac_docker/debug.rb +0 -13
- data/sub/eac_docker/lib/eac_docker/executables.rb +0 -15
- data/sub/eac_docker/lib/eac_docker/images/base.rb +0 -11
- data/sub/eac_docker/lib/eac_docker/images/coded.rb +0 -39
- data/sub/eac_docker/lib/eac_docker/images/named.rb +0 -26
- data/sub/eac_docker/lib/eac_docker/images/templatized.rb +0 -43
- data/sub/eac_docker/lib/eac_docker/registry.rb +0 -15
- data/sub/eac_docker/lib/eac_docker/rspec/setup.rb +0 -15
- data/sub/eac_docker/lib/eac_docker/rspec/stub_image.rb +0 -39
- data/sub/eac_docker/lib/eac_docker/version.rb +0 -5
- data/sub/eac_docker/lib/eac_docker.rb +0 -9
- data/sub/eac_docker/spec/lib/eac_docker/executables_spec.rb +0 -7
- data/sub/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +0 -10
- data/sub/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +0 -1
- data/sub/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +0 -15
- data/sub/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +0 -1
- data/sub/eac_docker/spec/rubocop_spec.rb +0 -3
- /data/sub/{avm-eac_ubuntu_base0 → eac_cli}/Gemfile +0 -0
- /data/sub/{avm-eac_ubuntu_base0 → eac_cli}/spec/rubocop_spec.rb +0 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Definition
|
5
|
+
class Alternative
|
6
|
+
ANY_OPTION_DESCRIPTION = 'ANY_OPTION'
|
7
|
+
ANY_OPTION_LONG = '__'
|
8
|
+
ANY_OPTION_SHORT = '_'
|
9
|
+
SUBCOMMAND_NAME_ARG = :subcommand
|
10
|
+
SUBCOMMAND_ARGS_ARG = :subcommand_args
|
11
|
+
|
12
|
+
# @return [Boolean]
|
13
|
+
def any_opt
|
14
|
+
@any_opt = true
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Boolean]
|
18
|
+
def any_option?
|
19
|
+
@any_opt ? true : false
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [EacCli::Definition::BooleanOption]
|
23
|
+
def any_options_option
|
24
|
+
@any_options_option ||= ::EacCli::Definition::BooleanOption.new(
|
25
|
+
ANY_OPTION_SHORT, ANY_OPTION_LONG, ANY_OPTION_DESCRIPTION,
|
26
|
+
optional: true, repeat: true, usage: false
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def arg_opt(*args)
|
31
|
+
options_set << ::EacCli::Definition::ArgumentOption.from_args(args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def bool_opt(*args)
|
35
|
+
options_set << ::EacCli::Definition::BooleanOption.from_args(args)
|
36
|
+
end
|
37
|
+
|
38
|
+
def options
|
39
|
+
options_set.to_a
|
40
|
+
end
|
41
|
+
|
42
|
+
def options_argument?
|
43
|
+
@options_argument ? true : false
|
44
|
+
end
|
45
|
+
|
46
|
+
def options_argument(enable)
|
47
|
+
@options_argument = enable
|
48
|
+
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def pos_arg(name, arg_options = {})
|
53
|
+
new_pos_arg = ::EacCli::Definition::Positional.new(name, arg_options)
|
54
|
+
check_positional_blocked(new_pos_arg)
|
55
|
+
pos_set << new_pos_arg
|
56
|
+
end
|
57
|
+
|
58
|
+
def positional
|
59
|
+
pos_set.to_a
|
60
|
+
end
|
61
|
+
|
62
|
+
def positional_arguments_blocked_reason(new_pos_arg)
|
63
|
+
last = pos_set.last
|
64
|
+
return nil unless last
|
65
|
+
return 'there are subcommands' if subcommands?
|
66
|
+
return 'last argument repeats' if last.repeat?
|
67
|
+
return 'new argument is required and last is optional' if
|
68
|
+
last.optional? && new_pos_arg.if_present(&:required?)
|
69
|
+
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def subcommands
|
74
|
+
pos_arg(SUBCOMMAND_NAME_ARG, subcommand: true)
|
75
|
+
pos_set << ::EacCli::Definition::Positional.new(SUBCOMMAND_ARGS_ARG,
|
76
|
+
optional: true, repeat: true)
|
77
|
+
end
|
78
|
+
|
79
|
+
def subcommands?
|
80
|
+
pos_set.any?(&:subcommand?)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def check_positional_blocked(new_pos_arg)
|
86
|
+
positional_arguments_blocked_reason(new_pos_arg).if_present do |v|
|
87
|
+
raise ::EacCli::Definition::Error, "Positional arguments are blocked: #{v} " \
|
88
|
+
"(New argument: #{new_pos_arg})"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def pos_set
|
93
|
+
@pos_set ||= []
|
94
|
+
end
|
95
|
+
|
96
|
+
def options_set
|
97
|
+
@options_set ||= []
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Definition
|
5
|
+
class ArgumentOption < ::EacCli::Definition::Option
|
6
|
+
def argument?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_value(new_value, previous_value)
|
11
|
+
repeat? ? previous_value + [new_value] : new_value
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_default_value
|
15
|
+
repeat? ? [] : nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Definition
|
5
|
+
class BooleanOption < ::EacCli::Definition::Option
|
6
|
+
def argument?
|
7
|
+
false
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_value(_new_value, previous_value)
|
11
|
+
repeat? ? previous_value + 1 : true
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_value
|
15
|
+
return super unless default_value?
|
16
|
+
|
17
|
+
raise("Unallowed default value for boolean options (Option: #{self})")
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_default_value
|
21
|
+
repeat? ? 0 : false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Definition
|
5
|
+
class Option
|
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}?") } ||
|
30
|
+
raise(::EacCli::Definition::Error, "Unknown type for \"#{value}\"")
|
31
|
+
end
|
32
|
+
|
33
|
+
def short?
|
34
|
+
value.start_with?('-') && !long?
|
35
|
+
end
|
36
|
+
|
37
|
+
def long?
|
38
|
+
value.start_with?('--')
|
39
|
+
end
|
40
|
+
|
41
|
+
def description?
|
42
|
+
!short? || !long?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Definition
|
5
|
+
# @abstract
|
6
|
+
class Option < ::EacCli::Definition::OptionOrPositional
|
7
|
+
require_sub __FILE__
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# @param args [Enumerable<String>]
|
11
|
+
# @return [EacCli::Definition::Option]
|
12
|
+
def from_args(args)
|
13
|
+
p = ::EacCli::Definition::Option::InitializeArgsParser.new(args)
|
14
|
+
new(p.short, p.long, p.description, p.options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
DEFAULT_REQUIRED = false
|
19
|
+
|
20
|
+
enable_abstract_methods
|
21
|
+
lists.add_symbol :option, *OPTION_LIST, :default, :usage
|
22
|
+
|
23
|
+
# @!method initialize(short, long, description, options = {})
|
24
|
+
# @param short [String]
|
25
|
+
# @param long [String]
|
26
|
+
# @param description [String]
|
27
|
+
# @param options [Hash<Symbol, Object>]
|
28
|
+
# @raise [EacCli::Definition::Error]
|
29
|
+
common_constructor :short, :long, :description, :options, default: [{}] do
|
30
|
+
validate
|
31
|
+
self.options = ::EacCli::Definition::Option.lists.option.hash_keys_validate!(
|
32
|
+
options.symbolize_keys
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Object]
|
37
|
+
def default_value
|
38
|
+
default_value? ? options[OPTION_DEFAULT] : default_default_value
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Boolean]
|
42
|
+
def default_value?
|
43
|
+
options.key?(OPTION_DEFAULT)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Symbol]
|
47
|
+
# @raise [EacCli::Definition::Error] If no short or long option is provided.
|
48
|
+
def identifier
|
49
|
+
[long, short].each do |v|
|
50
|
+
v.to_s.if_present { |vv| return vv.variableize.to_sym }
|
51
|
+
end
|
52
|
+
|
53
|
+
raise('No short or long option to build identifier')
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Boolean]
|
57
|
+
def show_on_usage?
|
58
|
+
options[:usage]
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# @return [void]
|
64
|
+
# @raise [EacCli::Definition::Error]
|
65
|
+
def validate
|
66
|
+
raise 'Nor short neither long selector was set' if short.blank? && long.blank?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Definition
|
5
|
+
# @abstract
|
6
|
+
class OptionOrPositional
|
7
|
+
acts_as_abstract :build_value, :default_value, :identifier, :options
|
8
|
+
enable_listable
|
9
|
+
|
10
|
+
OPTION_LIST = %i[optional repeat required].freeze
|
11
|
+
|
12
|
+
# @return [Boolean]
|
13
|
+
def optional?
|
14
|
+
!required?
|
15
|
+
end
|
16
|
+
|
17
|
+
# @raise [EacCli::Definition::Error]
|
18
|
+
def raise(*args)
|
19
|
+
::Kernel.raise ::EacCli::Definition::Error, *args
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Boolean]
|
23
|
+
def repeat?
|
24
|
+
options[:repeat] ? true : false
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Boolean]
|
28
|
+
def required?
|
29
|
+
return true if options.key?(:required) && options.fetch(:required)
|
30
|
+
return false if options.key?(:optional) && options.fetch(:optional)
|
31
|
+
|
32
|
+
self.class.const_get('DEFAULT_REQUIRED')
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
def to_s
|
37
|
+
"#{self.class.name.demodulize}[#{identifier}]"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Definition
|
5
|
+
class Positional < ::EacCli::Definition::OptionOrPositional
|
6
|
+
DEFAULT_REQUIRED = true
|
7
|
+
DEFAULT_VISIBLE = true
|
8
|
+
|
9
|
+
lists.add_symbol :option, *OPTION_LIST, :subcommand, :visible
|
10
|
+
|
11
|
+
# @!method initialize(name, options = {})
|
12
|
+
# @param name [String]
|
13
|
+
# @param options [Hash<Symbol, Object>]
|
14
|
+
common_constructor :name, :options, default: [{}] do
|
15
|
+
options.assert_valid_keys(self.class.lists.option.values)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param new_value [Array, Object]
|
19
|
+
# @param previous_value [Array, Object]
|
20
|
+
# @return [Array]
|
21
|
+
def build_value(new_value, previous_value)
|
22
|
+
if previous_value.is_a?(::Array)
|
23
|
+
previous_value + [new_value]
|
24
|
+
else
|
25
|
+
new_value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Object]
|
30
|
+
def default_value
|
31
|
+
repeat? ? [] : nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Symbol]
|
35
|
+
def identifier
|
36
|
+
name.to_s.variableize.to_sym
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Boolean]
|
40
|
+
def subcommand?
|
41
|
+
options[OPTION_SUBCOMMAND]
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Boolean]
|
45
|
+
def visible?
|
46
|
+
options.key?(OPTION_VISIBLE) ? options.fetch(OPTION_VISIBLE) : DEFAULT_VISIBLE
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Definition
|
5
|
+
require_sub __FILE__
|
6
|
+
|
7
|
+
MAIN_ALTERNATIVE_KEY = :main
|
8
|
+
SUBCOMMAND_NAME_ARG = 'subcommand'
|
9
|
+
SUBCOMMAND_ARGS_ARG = 'subcommand_args'
|
10
|
+
|
11
|
+
# @return [String, nil]
|
12
|
+
attr_accessor :description
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
self.description = '-- NO DESCRIPTION SET --'
|
16
|
+
alternatives_set[MAIN_ALTERNATIVE_KEY] = main_alternative
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [EacCli::Definition::Alternative]
|
20
|
+
def alt(key = nil, &block)
|
21
|
+
key ||= new_alternative_key
|
22
|
+
raise(::EacCli::Definition::Error, "A alternative with key=\"#{key}\" already exists") if
|
23
|
+
key.present? && alternatives_set.key?(key)
|
24
|
+
|
25
|
+
r = ::EacCli::Definition::Alternative.new
|
26
|
+
r.instance_eval(&block)
|
27
|
+
alternatives_set[key] = r
|
28
|
+
r
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Enumerable<EacCli::Definition::Alternative>]
|
32
|
+
def alternatives
|
33
|
+
alternatives_set.values
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [EacCli::Definition::Alternative]
|
37
|
+
# @raise [KeyError] If there is not a alternative with provided key.
|
38
|
+
def alternative(key)
|
39
|
+
alternatives_set.fetch(key)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Same as {#description=}.
|
43
|
+
def desc(description)
|
44
|
+
self.description = description
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [EacCli::Definition::Alternative]
|
48
|
+
def main_alternative
|
49
|
+
@main_alternative ||= begin
|
50
|
+
r = ::EacCli::Definition::Alternative.new
|
51
|
+
r.options_argument(true)
|
52
|
+
r
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Same as {#options_argument=}.
|
57
|
+
# @param options_argument [Boolean]
|
58
|
+
def options_arg(options_argument)
|
59
|
+
self.options_argument = options_argument
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [Boolean]
|
63
|
+
def options_argument # rubocop:disable Naming/PredicateMethod
|
64
|
+
main_alternative.options_argument?
|
65
|
+
end
|
66
|
+
|
67
|
+
def options_argument=(enable)
|
68
|
+
main_alternative.options_argument(enable)
|
69
|
+
end
|
70
|
+
|
71
|
+
delegate :arg_opt, :bool_opt, :options, :pos_arg,
|
72
|
+
:positional, :subcommands, to: :main_alternative
|
73
|
+
|
74
|
+
def subcommands?
|
75
|
+
alternatives.any?(&:subcommands?)
|
76
|
+
end
|
77
|
+
|
78
|
+
def options_first(enable = true) # rubocop:disable Style/OptionalBooleanParameter
|
79
|
+
@options_first = enable
|
80
|
+
end
|
81
|
+
|
82
|
+
def options_first?
|
83
|
+
@options_first ? true : false
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def alternatives_set
|
89
|
+
@alternatives_set ||= ::ActiveSupport::HashWithIndifferentAccess.new
|
90
|
+
end
|
91
|
+
|
92
|
+
def new_alternative_key
|
93
|
+
@last_key ||= 0
|
94
|
+
loop do
|
95
|
+
@last_key += 1
|
96
|
+
break @last_key unless alternatives_set.key?(@last_key)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def pos_set
|
101
|
+
@pos_set ||= []
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
# A [EacRubyUtils::Enum] which each value is associated with one console color.
|
5
|
+
class Enum < ::EacRubyUtils::Enum
|
6
|
+
# Foreground color used in [to_bg_label]
|
7
|
+
TO_BG_LABEL_FG_COLOR = :light_white
|
8
|
+
|
9
|
+
attr_reader :color
|
10
|
+
|
11
|
+
def initialize(key, color)
|
12
|
+
super(key)
|
13
|
+
@color = color
|
14
|
+
end
|
15
|
+
|
16
|
+
delegate :to_s, to: :key
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
def to_label
|
20
|
+
to_fg_label
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [String]
|
24
|
+
def to_fg_label
|
25
|
+
to_fg_bg_label(color)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [String]
|
29
|
+
def to_bg_label
|
30
|
+
to_fg_bg_label(TO_BG_LABEL_FG_COLOR, color)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
def to_fg_bg_label(fg_color, bg_color = nil)
|
37
|
+
colors = { color: fg_color }
|
38
|
+
bg_color.if_present { |v| colors[:background] = v }
|
39
|
+
::ColorizedString[to_s].colorize(colors)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class OldConfigs
|
5
|
+
class EntryReader
|
6
|
+
enable_speaker
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def entry_key_to_envvar_name(entry_key)
|
10
|
+
path = if entry_key.is_a?(::Array)
|
11
|
+
entry_key
|
12
|
+
else
|
13
|
+
::EacConfig::PathsHash.parse_entry_key(entry_key)
|
14
|
+
end
|
15
|
+
path.join('_').gsub(/[^a-z0-9_]/i, '').gsub(/\A_+/, '').gsub(/_+\z/, '')
|
16
|
+
.gsub(/_{2,}/, '_').upcase
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
common_constructor :console_configs, :entry_key, :options do
|
21
|
+
self.options = ::EacCli::OldConfigs::ReadEntryOptions.new(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def read
|
25
|
+
%w[envvars storage console].each do |suffix|
|
26
|
+
value = send("read_from_#{suffix}")
|
27
|
+
return value if value.present?
|
28
|
+
end
|
29
|
+
return nil unless options[:required]
|
30
|
+
|
31
|
+
raise "No value found for entry \"#{entry_key}\""
|
32
|
+
end
|
33
|
+
|
34
|
+
def read_from_storage
|
35
|
+
console_configs.configs.read_entry(entry_key)
|
36
|
+
end
|
37
|
+
|
38
|
+
def read_from_envvars
|
39
|
+
return if options[:noenv]
|
40
|
+
|
41
|
+
env_entry_key = self.class.entry_key_to_envvar_name(entry_key)
|
42
|
+
return unless ENV.key?(env_entry_key)
|
43
|
+
|
44
|
+
ENV.fetch(env_entry_key).if_present(::EacRubyUtils::BlankNotBlank.instance)
|
45
|
+
end
|
46
|
+
|
47
|
+
def read_from_console
|
48
|
+
return if options[:noinput]
|
49
|
+
|
50
|
+
options[:before_input].if_present(&:call)
|
51
|
+
entry_value = looped_entry_value_from_input
|
52
|
+
console_configs.configs.write_entry(entry_key, entry_value) if options[:store]
|
53
|
+
entry_value
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def looped_entry_value_from_input
|
59
|
+
loop do
|
60
|
+
entry_value = entry_value_from_input(entry_key, options)
|
61
|
+
next if entry_value.blank?
|
62
|
+
next if options[:validator] && !options[:validator].call(entry_value)
|
63
|
+
|
64
|
+
return entry_value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def entry_value_from_input(entry_key, options)
|
69
|
+
entry_value = input("Value for entry \"#{entry_key}\"",
|
70
|
+
options.request_input_options)
|
71
|
+
warn('Entered value is blank') if entry_value.blank?
|
72
|
+
entry_value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class OldConfigs
|
5
|
+
class PasswordEntryReader < ::EacCli::OldConfigs::EntryReader
|
6
|
+
ENTRY_KEY = 'core.store_passwords'
|
7
|
+
|
8
|
+
def initialize(console_configs, entry_key, options = {})
|
9
|
+
super(console_configs, entry_key, options.merge(noecho: true,
|
10
|
+
store: console_configs.store_passwords?))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class OldConfigs
|
5
|
+
class ReadEntryOptions
|
6
|
+
enable_simple_cache
|
7
|
+
common_constructor :options do
|
8
|
+
self.options = options.to_h.symbolize_keys
|
9
|
+
.assert_valid_keys(DEFAULT_VALUES.keys).freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
DEFAULT_VALUES = {
|
13
|
+
before_input: nil, bool: false, list: false, noecho: false, noenv: false, noinput: false,
|
14
|
+
required: true, store: true, validator: nil
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
delegate :to_h, to: :options
|
18
|
+
|
19
|
+
def [](key)
|
20
|
+
values.fetch(key.to_sym)
|
21
|
+
end
|
22
|
+
|
23
|
+
def request_input_options
|
24
|
+
values.slice(:bool, :list, :noecho)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def values_uncached
|
30
|
+
consumer = options.to_options_consumer
|
31
|
+
r = {}
|
32
|
+
DEFAULT_VALUES.each do |key, default_value|
|
33
|
+
value = consumer.consume(key)
|
34
|
+
value = default_value if value.nil?
|
35
|
+
r[key] = value
|
36
|
+
end
|
37
|
+
consumer.validate
|
38
|
+
r
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class OldConfigs
|
5
|
+
class StorePasswordsEntryReader < ::EacCli::OldConfigs::EntryReader
|
6
|
+
ENTRY_KEY = 'core.store_passwords'
|
7
|
+
|
8
|
+
def initialize(console_configs)
|
9
|
+
super(console_configs, ENTRY_KEY,
|
10
|
+
before_input: -> { banner },
|
11
|
+
validator: ->(entry_value) { %w[yes no].include?(entry_value) }
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def banner
|
16
|
+
infom 'Do you wanna to store passwords?'
|
17
|
+
infom 'Warning: the passwords will be store in clear text in ' \
|
18
|
+
"\"#{console_configs.configs.storage_path}\""
|
19
|
+
infom 'Enter "yes" or "no"'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|