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.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +22 -27
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +1 -1
  5. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/apache_host.rb +0 -2
  6. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/database.rb +0 -3
  7. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/files.rb +0 -4
  8. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/gitolite.rb +0 -3
  9. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/install.rb +0 -3
  10. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/nodejs.rb +0 -3
  11. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/web.rb +0 -3
  12. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base.rb +1 -7
  13. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/deploy.rb +0 -3
  14. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/docker_image.rb +0 -6
  15. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/entity_base.rb +0 -4
  16. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/project.rb +0 -5
  17. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/root.rb +0 -4
  18. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/wiki_page.rb +0 -4
  19. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api.rb +0 -4
  20. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/docker.rb +0 -2
  21. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project/wiki_page/read.rb +0 -2
  22. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project/wiki_page/write.rb +0 -2
  23. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project/wiki_page.rb +0 -4
  24. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project.rb +0 -4
  25. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project_rename.rb +0 -3
  26. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/base.rb +0 -4
  27. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/core_update.rb +0 -6
  28. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/core_update.rb +0 -4
  29. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/docker.rb +0 -3
  30. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
  31. data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/instances/docker_image/Dockerfile.template +1 -0
  32. data/sub/eac_cli/eac_cli.gemspec +23 -0
  33. data/sub/eac_cli/lib/eac_cli/config/entry/options.rb +55 -0
  34. data/sub/eac_cli/lib/eac_cli/config/entry/undefined.rb +26 -0
  35. data/sub/eac_cli/lib/eac_cli/config/entry.rb +55 -0
  36. data/sub/eac_cli/lib/eac_cli/config.rb +15 -0
  37. data/sub/eac_cli/lib/eac_cli/core_ext.rb +4 -0
  38. data/sub/eac_cli/lib/eac_cli/default_runner.rb +12 -0
  39. data/sub/eac_cli/lib/eac_cli/definition/alternative.rb +101 -0
  40. data/sub/eac_cli/lib/eac_cli/definition/argument_option.rb +19 -0
  41. data/sub/eac_cli/lib/eac_cli/definition/boolean_option.rb +25 -0
  42. data/sub/eac_cli/lib/eac_cli/definition/error.rb +8 -0
  43. data/sub/eac_cli/lib/eac_cli/definition/option/initialize_args_parser.rb +48 -0
  44. data/sub/eac_cli/lib/eac_cli/definition/option.rb +70 -0
  45. data/sub/eac_cli/lib/eac_cli/definition/option_or_positional.rb +41 -0
  46. data/sub/eac_cli/lib/eac_cli/definition/positional.rb +50 -0
  47. data/sub/eac_cli/lib/eac_cli/definition.rb +104 -0
  48. data/sub/eac_cli/lib/eac_cli/enum.rb +42 -0
  49. data/sub/eac_cli/lib/eac_cli/old_configs/entry_reader.rb +76 -0
  50. data/sub/eac_cli/lib/eac_cli/old_configs/password_entry_reader.rb +14 -0
  51. data/sub/eac_cli/lib/eac_cli/old_configs/read_entry_options.rb +42 -0
  52. data/sub/eac_cli/lib/eac_cli/old_configs/store_passwords_entry_reader.rb +23 -0
  53. data/sub/eac_cli/lib/eac_cli/old_configs.rb +31 -0
  54. data/sub/eac_cli/lib/eac_cli/parser/alternative/any_options.rb +17 -0
  55. data/sub/eac_cli/lib/eac_cli/parser/alternative/argv.rb +19 -0
  56. data/sub/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  57. data/sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb +37 -0
  58. data/sub/eac_cli/lib/eac_cli/parser/alternative/option_argument.rb +29 -0
  59. data/sub/eac_cli/lib/eac_cli/parser/alternative/options.rb +29 -0
  60. data/sub/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  61. data/sub/eac_cli/lib/eac_cli/parser/alternative/short_options.rb +54 -0
  62. data/sub/eac_cli/lib/eac_cli/parser/alternative.rb +99 -0
  63. data/sub/eac_cli/lib/eac_cli/parser/collector.rb +52 -0
  64. data/sub/eac_cli/lib/eac_cli/parser/error.rb +13 -0
  65. data/sub/eac_cli/lib/eac_cli/parser.rb +32 -0
  66. data/sub/eac_cli/lib/eac_cli/patches/object/runner_with.rb +22 -0
  67. data/sub/eac_cli/lib/eac_cli/patches/object.rb +5 -0
  68. data/sub/eac_cli/lib/eac_cli/patches.rb +3 -0
  69. data/sub/eac_cli/lib/eac_cli/rspec/setup.rb +41 -0
  70. data/sub/eac_cli/lib/eac_cli/rspec.rb +7 -0
  71. data/sub/eac_cli/lib/eac_cli/runner/after_class_methods.rb +34 -0
  72. data/sub/eac_cli/lib/eac_cli/runner/class_runner.rb +32 -0
  73. data/sub/eac_cli/lib/eac_cli/runner/context.rb +57 -0
  74. data/sub/eac_cli/lib/eac_cli/runner/context_responders/base.rb +22 -0
  75. data/sub/eac_cli/lib/eac_cli/runner/context_responders/parent.rb +24 -0
  76. data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner.rb +17 -0
  77. data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner_missing_method.rb +29 -0
  78. data/sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb +41 -0
  79. data/sub/eac_cli/lib/eac_cli/runner/context_responders.rb +9 -0
  80. data/sub/eac_cli/lib/eac_cli/runner/exit.rb +14 -0
  81. data/sub/eac_cli/lib/eac_cli/runner/for_context.rb +35 -0
  82. data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +45 -0
  83. data/sub/eac_cli/lib/eac_cli/runner.rb +47 -0
  84. data/sub/eac_cli/lib/eac_cli/runner_with/confirmation/input_result.rb +60 -0
  85. data/sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb +65 -0
  86. data/sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb +61 -0
  87. data/sub/eac_cli/lib/eac_cli/runner_with/help/builder.rb +79 -0
  88. data/sub/eac_cli/lib/eac_cli/runner_with/help/layout.rb +38 -0
  89. data/sub/eac_cli/lib/eac_cli/runner_with/help.rb +51 -0
  90. data/sub/eac_cli/lib/eac_cli/runner_with/input.rb +32 -0
  91. data/sub/eac_cli/lib/eac_cli/runner_with/output.rb +54 -0
  92. data/sub/eac_cli/lib/eac_cli/runner_with/output_item/asciidoc_formatter.rb +70 -0
  93. data/sub/eac_cli/lib/eac_cli/runner_with/output_item/base_formatter.rb +12 -0
  94. data/sub/eac_cli/lib/eac_cli/runner_with/output_item/csv_formatter.rb +21 -0
  95. data/sub/eac_cli/lib/eac_cli/runner_with/output_item/yaml_formatter.rb +16 -0
  96. data/sub/eac_cli/lib/eac_cli/runner_with/output_item.rb +47 -0
  97. data/sub/eac_cli/lib/eac_cli/runner_with/output_list/base_formatter.rb +44 -0
  98. data/sub/eac_cli/lib/eac_cli/runner_with/output_list/csv_formatter.rb +24 -0
  99. data/sub/eac_cli/lib/eac_cli/runner_with/output_list/tty_formatter.rb +34 -0
  100. data/sub/eac_cli/lib/eac_cli/runner_with/output_list/yaml_formatter.rb +21 -0
  101. data/sub/eac_cli/lib/eac_cli/runner_with/output_list.rb +39 -0
  102. data/sub/eac_cli/lib/eac_cli/runner_with/subcommands/definition_concern.rb +10 -0
  103. data/sub/eac_cli/lib/eac_cli/runner_with/subcommands.rb +124 -0
  104. data/sub/eac_cli/lib/eac_cli/runner_with.rb +7 -0
  105. data/sub/eac_cli/lib/eac_cli/runner_with_set.rb +54 -0
  106. data/sub/eac_cli/lib/eac_cli/speaker/constants.rb +11 -0
  107. data/sub/eac_cli/lib/eac_cli/speaker/input_blocked.rb +14 -0
  108. data/sub/eac_cli/lib/eac_cli/speaker/input_requested.rb +8 -0
  109. data/sub/eac_cli/lib/eac_cli/speaker/list.rb +84 -0
  110. data/sub/eac_cli/lib/eac_cli/speaker/options.rb +42 -0
  111. data/sub/eac_cli/lib/eac_cli/speaker/request_from_list.rb +40 -0
  112. data/sub/eac_cli/lib/eac_cli/speaker.rb +114 -0
  113. data/sub/eac_cli/lib/eac_cli/version.rb +5 -0
  114. data/sub/eac_cli/lib/eac_cli.rb +14 -0
  115. data/sub/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +18 -0
  116. data/sub/eac_cli/spec/lib/eac_cli/old_configs_spec.rb +14 -0
  117. data/sub/eac_cli/spec/lib/eac_cli/parser/alternative/subcommands_spec.rb +58 -0
  118. data/sub/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +89 -0
  119. data/sub/eac_cli/spec/lib/eac_cli/runner/for_context_spec.rb +79 -0
  120. data/sub/eac_cli/spec/lib/eac_cli/runner_spec.rb +129 -0
  121. data/sub/eac_cli/spec/lib/eac_cli/runner_with/confirmation/input_result_spec.rb +36 -0
  122. data/sub/eac_cli/spec/lib/eac_cli/runner_with/confirmation_spec.rb +42 -0
  123. data/sub/eac_cli/spec/lib/eac_cli/runner_with/help/layout_spec.rb +21 -0
  124. data/sub/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +51 -0
  125. data/sub/eac_cli/spec/lib/eac_cli/runner_with/output_list_spec.rb +57 -0
  126. data/sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb +81 -0
  127. data/sub/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +99 -0
  128. data/sub/eac_cli/spec/lib/eac_cli/speaker_spec.rb +36 -0
  129. data/sub/{eac_docker → eac_cli}/spec/spec_helper.rb +1 -2
  130. metadata +108 -48
  131. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners.rb +0 -14
  132. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances.rb +0 -11
  133. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners.rb +0 -13
  134. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources.rb +0 -11
  135. data/sub/avm-eac_ubuntu_base0/avm-eac_ubuntu_base0.gemspec +0 -21
  136. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/apache/resource.rb +0 -57
  137. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/apache.rb +0 -24
  138. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/docker_image.rb +0 -31
  139. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/instances/base.rb +0 -24
  140. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb +0 -82
  141. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/runners/base/docker.rb +0 -15
  142. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/runners/base.rb +0 -26
  143. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/version.rb +0 -7
  144. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0.rb +0 -13
  145. data/sub/avm-eac_ubuntu_base0/spec/lib/avm/eac_ubuntu_base0/docker_image_spec.rb +0 -12
  146. data/sub/avm-eac_ubuntu_base0/spec/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server_spec.rb +0 -11
  147. data/sub/avm-eac_ubuntu_base0/spec/lib/avm/eac_ubuntu_base0/runners/base/docker_spec.rb +0 -11
  148. data/sub/avm-eac_ubuntu_base0/spec/lib/avm/eac_ubuntu_base0/runners/base_spec.rb +0 -5
  149. data/sub/avm-eac_ubuntu_base0/spec/spec_helper.rb +0 -5
  150. data/sub/avm-eac_ubuntu_base0/template/avm/eac_ubuntu_base0/docker_image/Dockerfile.template +0 -27
  151. data/sub/avm-eac_ubuntu_base0/template/avm/eac_ubuntu_base0/rspec/ssh_docker_server/Dockerfile.template +0 -24
  152. data/sub/avm-eac_ubuntu_base0/template/avm/eac_ubuntu_base0/rspec/ssh_docker_server/id_rsa +0 -27
  153. data/sub/avm-eac_ubuntu_base0/template/avm/eac_ubuntu_base0/rspec/ssh_docker_server/id_rsa.pub +0 -1
  154. data/sub/eac_docker/Gemfile +0 -8
  155. data/sub/eac_docker/eac_docker.gemspec +0 -20
  156. data/sub/eac_docker/lib/eac_docker/container.rb +0 -83
  157. data/sub/eac_docker/lib/eac_docker/debug.rb +0 -13
  158. data/sub/eac_docker/lib/eac_docker/executables.rb +0 -15
  159. data/sub/eac_docker/lib/eac_docker/images/base.rb +0 -11
  160. data/sub/eac_docker/lib/eac_docker/images/coded.rb +0 -39
  161. data/sub/eac_docker/lib/eac_docker/images/named.rb +0 -26
  162. data/sub/eac_docker/lib/eac_docker/images/templatized.rb +0 -43
  163. data/sub/eac_docker/lib/eac_docker/registry.rb +0 -15
  164. data/sub/eac_docker/lib/eac_docker/rspec/setup.rb +0 -15
  165. data/sub/eac_docker/lib/eac_docker/rspec/stub_image.rb +0 -39
  166. data/sub/eac_docker/lib/eac_docker/version.rb +0 -5
  167. data/sub/eac_docker/lib/eac_docker.rb +0 -9
  168. data/sub/eac_docker/spec/lib/eac_docker/executables_spec.rb +0 -7
  169. data/sub/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +0 -10
  170. data/sub/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +0 -1
  171. data/sub/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +0 -15
  172. data/sub/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +0 -1
  173. data/sub/eac_docker/spec/rubocop_spec.rb +0 -3
  174. /data/sub/{avm-eac_ubuntu_base0 → eac_cli}/Gemfile +0 -0
  175. /data/sub/{avm-eac_ubuntu_base0 → eac_cli}/spec/rubocop_spec.rb +0 -0
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/hash_with_indifferent_access'
4
+ require 'ostruct'
5
+
6
+ module EacCli
7
+ class Speaker
8
+ class List
9
+ VALUE_STRUCT = ::Struct.new(:key, :label, :value)
10
+
11
+ class << self
12
+ # @param list [Array, Hash]
13
+ # @param options [Hash]
14
+ def build(list, options = {})
15
+ return List.new(hash_to_values(list), options) if list.is_a?(::Hash)
16
+ return List.new(array_to_values(list), options) if list.is_a?(::Array)
17
+
18
+ raise "Invalid list: #{list} (#{list.class})"
19
+ end
20
+
21
+ private
22
+
23
+ def hash_to_values(list)
24
+ list.map { |key, value| VALUE_STRUCT.new(key, key, value) }
25
+ end
26
+
27
+ def array_to_values(list)
28
+ list.map { |value| VALUE_STRUCT.new(value, value, value) }
29
+ end
30
+ end
31
+
32
+ DEFAULT_IGNORE_CASE = true
33
+
34
+ enable_listable
35
+ lists.add_symbol :option, :ignore_case
36
+
37
+ # @!attribute [r] values
38
+ # @return [Array<VALUE_STRUCT>]
39
+ # # @!attribute [r] options
40
+ # @return [Hash]
41
+ # @!method initialize(values)
42
+ # @param values [Array<VALUE_STRUCT>]
43
+ # @param options [Hash]
44
+ common_constructor :values, :options, default: [{}] do
45
+ self.options = self.class.lists.option.hash_keys_validate!(options)
46
+ self.values = values.map do |v|
47
+ VALUE_STRUCT.new(to_key(v.key), to_label(v.label), v.value)
48
+ end
49
+ end
50
+
51
+ # @return [Boolean]
52
+ def ignore_case?
53
+ options.if_key(OPTION_IGNORE_CASE, DEFAULT_IGNORE_CASE, &:to_bool)
54
+ end
55
+
56
+ def valid_labels
57
+ values.map(&:label)
58
+ end
59
+
60
+ def valid_value?(value)
61
+ values.any? { |v| v.key == to_key(value) }
62
+ end
63
+
64
+ # @param value [Object]
65
+ # @return [String]
66
+ def to_key(value)
67
+ r = to_label(value)
68
+ ignore_case? ? r.downcase : r
69
+ end
70
+
71
+ def to_label(value)
72
+ value.to_s.strip
73
+ end
74
+
75
+ def build_value(value)
76
+ key = to_key(value)
77
+ values.each do |v|
78
+ return v.value if v.key == key
79
+ end
80
+ raise "Value not found: \"#{value}\" (#{values})"
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ class Speaker
5
+ module Options
6
+ common_concern do
7
+ enable_listable
8
+ lists.add_symbol :option, :out_out, :err_out, :in_in, :parent, :err_line_prefix,
9
+ :ignore_case
10
+ end
11
+
12
+ def err_out
13
+ option(OPTION_ERR_OUT, $stderr)
14
+ end
15
+
16
+ def out_out
17
+ option(OPTION_OUT_OUT, $stdout)
18
+ end
19
+
20
+ def in_in
21
+ option(OPTION_IN_IN, $stdin)
22
+ end
23
+
24
+ # @return [Boolean]
25
+ def ignore_case
26
+ option(OPTION_IGNORE_CASE, nil)
27
+ end
28
+
29
+ def err_line_prefix
30
+ option(OPTION_ERR_LINE_PREFIX, '')
31
+ end
32
+
33
+ def parent
34
+ options[OPTION_PARENT]
35
+ end
36
+
37
+ def option(key, default)
38
+ options[key] || parent.if_present(default) { |v| v.send(__METHOD__) }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ class Speaker
5
+ class RequestFromList
6
+ acts_as_instance_method
7
+ enable_simple_cache
8
+ common_constructor :speaker, :question, :list_values, :noecho,
9
+ :ignore_case
10
+
11
+ # @return [String]
12
+ def result
13
+ loop do
14
+ return list.build_value(input) if list.valid_value?(input)
15
+
16
+ speaker.warn "Invalid input: \"#{input}\" (Valid: #{list.valid_labels.join(', ')})"
17
+ end
18
+ end
19
+
20
+ protected
21
+
22
+ # @return [String]
23
+ def input_uncached
24
+ speaker.send(
25
+ :request_string,
26
+ "#{question} [#{list.valid_labels.join('/')}]",
27
+ noecho
28
+ )
29
+ end
30
+
31
+ # @return [EacCli::Speaker::List]
32
+ def list_uncached
33
+ list_options = {}
34
+ list_options[::EacCli::Speaker::List::OPTION_IGNORE_CASE] = ignore_case unless
35
+ ignore_case.nil?
36
+ ::EacCli::Speaker::List.build(list_values, list_options)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ class Speaker
5
+ require_sub __FILE__, include_modules: true
6
+ include ::EacRubyUtils::Speaker::Receiver
7
+
8
+ common_constructor :options, default: [{}] do
9
+ self.options = self.class.lists.option.hash_keys_validate!(options)
10
+ end
11
+
12
+ def puts(string = '')
13
+ string.to_s.each_line do |line|
14
+ err_out.puts(err_line_prefix.to_s + line)
15
+ end
16
+ end
17
+
18
+ def out(string = '')
19
+ out_out.write(string.to_s)
20
+ end
21
+
22
+ def error(string)
23
+ puts "ERROR: #{string}".white.on_red
24
+ end
25
+
26
+ def title(string)
27
+ string = string.to_s
28
+ puts(('-' * (8 + string.length)).green)
29
+ puts("--- #{string} ---".green)
30
+ puts(('-' * (8 + string.length)).green)
31
+ puts
32
+ end
33
+
34
+ def info(string)
35
+ puts string.to_s.white
36
+ end
37
+
38
+ def infom(string)
39
+ puts string.to_s.light_yellow
40
+ end
41
+
42
+ def warn(string)
43
+ puts string.to_s.yellow
44
+ end
45
+
46
+ # Options:
47
+ # +bool+ ([Boolean], default: +false+): requires a answer "yes" or "no".
48
+ # +list+ ([Hash] or [Array], default: +nil+): requires a answer from a list.
49
+ # +noecho+ ([Boolean], default: +false+): does not output answer.
50
+ def input(question, options = {})
51
+ bool, list, noecho, ignore_case =
52
+ options.to_options_consumer.consume_all(:bool, :list, :noecho, :ignore_case)
53
+ if list
54
+ request_from_list(question, list, noecho, ignore_case)
55
+ elsif bool
56
+ request_from_bool(question, noecho)
57
+ else
58
+ request_string(question, noecho)
59
+ end
60
+ end
61
+
62
+ def infov(*args)
63
+ r = []
64
+ args.each_with_index do |v, i|
65
+ if i.even?
66
+ r << "#{v}: ".cyan
67
+ else
68
+ r.last << v.to_s
69
+ end
70
+ end
71
+ puts r.join(', ')
72
+ end
73
+
74
+ def success(string)
75
+ puts string.to_s.green
76
+ end
77
+
78
+ private
79
+
80
+ def list_value(list, input)
81
+ values = list_values(list)
82
+ return input, true unless values
83
+
84
+ [input, false] unless values.include?(input)
85
+ end
86
+
87
+ def list_values(list)
88
+ if list.is_a?(::Hash)
89
+ list.keys.map(&:to_s)
90
+ elsif list.is_a?(::Array)
91
+ list.map(&:to_s)
92
+ end
93
+ end
94
+
95
+ def request_from_bool(question, noecho)
96
+ request_from_list(question, { yes: true, y: true, no: false, n: false }, noecho, true)
97
+ end
98
+
99
+ def request_string(question, noecho)
100
+ err_out.write "#{question}: ".yellow
101
+ noecho ? request_string_noecho : request_string_echo
102
+ end
103
+
104
+ def request_string_noecho
105
+ r = in_in.noecho(&:gets).chomp.strip
106
+ err_out.write("\n")
107
+ r
108
+ end
109
+
110
+ def request_string_echo
111
+ in_in.gets.chomp.strip
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ VERSION = '0.44.1'
5
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils'
4
+ EacRubyUtils::RootModuleSetup.perform __FILE__ do
5
+ ignore 'core_ext'
6
+ ignore 'patches'
7
+ end
8
+
9
+ module EacCli
10
+ end
11
+
12
+ require 'eac_config'
13
+ require 'colorize'
14
+ require 'eac_cli/core_ext'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/definition/alternative'
4
+
5
+ RSpec.describe EacCli::Definition::Alternative do
6
+ let(:instance) { described_class.new }
7
+
8
+ it { expect { instance.arg_opt '-a', '--opt2', 'A argument option' }.not_to raise_error }
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) }
14
+ it { expect { instance.options_argument(true) }.not_to raise_error }
15
+ it { expect { instance.pos_arg :pos1 }.not_to raise_error }
16
+ it { expect { instance.pos_arg :pos2, optional: true, repeat: true }.not_to raise_error }
17
+ it { expect { instance.subcommands }.not_to raise_error }
18
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/old_configs'
4
+
5
+ RSpec.describe EacCli::OldConfigs do
6
+ describe '#entry_key_to_envvar_name' do
7
+ {
8
+ 'a.entry.value' => 'A_ENTRY_VALUE',
9
+ 'appli-cation_0.var_one' => 'APPLICATION_0_VAR_ONE'
10
+ }.each do |input, expected_result|
11
+ it { expect(described_class.entry_key_to_envvar_name(input)).to eq(expected_result) }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/definition/alternative'
4
+ require 'eac_cli/parser/alternative'
5
+
6
+ RSpec.describe EacCli::Parser::Alternative, '#subcommands' do
7
+ let(:instance) { described_class.new(alternative, argv) }
8
+ let(:actual_parsed) { instance.parsed.to_h.symbolize_keys }
9
+ let(:alternative) do
10
+ r = EacCli::Definition::Alternative.new
11
+ r.bool_opt '-b', '--opt1', 'A boolean option'
12
+ r.arg_opt '-a', '--opt2', 'A argument option'
13
+ r.subcommands
14
+ r
15
+ end
16
+
17
+ context 'with all values' do
18
+ let(:argv) { %w[--opt1 --opt2 OPT2 CMD CMD_ARG_1 --CMD_ARG_2] }
19
+ let(:parsed_expected) do
20
+ {
21
+ opt1: true, opt2: 'OPT2',
22
+ EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => 'CMD',
23
+ EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => %w[CMD_ARG_1 --CMD_ARG_2]
24
+ }
25
+ end
26
+
27
+ it { expect(instance.error).to be_blank }
28
+ it { expect(actual_parsed).to eq(parsed_expected) }
29
+ end
30
+
31
+ context 'with only required values' do
32
+ let(:argv) { %w[CMD] }
33
+ let(:parsed_expected) do
34
+ {
35
+ opt1: false, opt2: nil,
36
+ EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => 'CMD',
37
+ EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => []
38
+ }
39
+ end
40
+
41
+ it { expect(instance.error).to be_blank }
42
+ it { expect(actual_parsed).to eq(parsed_expected) }
43
+ end
44
+
45
+ context 'without required values' do
46
+ let(:argv) { %w[--opt1] }
47
+ let(:parsed_expected) do
48
+ {
49
+ opt1: true, opt2: nil,
50
+ EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => nil,
51
+ EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => []
52
+ }
53
+ end
54
+
55
+ it { expect(instance.error).to be_present }
56
+ it { expect(actual_parsed).to eq(parsed_expected) }
57
+ end
58
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/definition/alternative'
4
+ require 'eac_cli/parser/alternative'
5
+
6
+ RSpec.describe EacCli::Parser::Alternative do
7
+ let(:instance) { described_class.new(alternative, argv) }
8
+ let(:actual_parsed) { instance.parsed.to_h.symbolize_keys }
9
+
10
+ context 'without subcommands' do
11
+ let(:alternative) do
12
+ r = EacCli::Definition::Alternative.new
13
+ r.bool_opt '-b', '--opt1', 'A boolean option'
14
+ r.arg_opt '-a', '--opt2', 'A argument option'
15
+ r.bool_opt '-c', '--opt3', 'A required boolean option', required: true
16
+ r.pos_arg :pos1
17
+ r.pos_arg :pos2, optional: true, repeat: true
18
+ r
19
+ end
20
+
21
+ context 'with all values' do
22
+ let(:argv) { %w[--opt1 --opt2 OPT2 --opt3 POS1 POS2_1 POS2_2] }
23
+ let(:parsed_expected) do
24
+ {
25
+ opt1: true, opt2: 'OPT2', opt3: true, pos1: 'POS1', pos2: %w[POS2_1 POS2_2]
26
+ }
27
+ end
28
+
29
+ it { expect(instance.error).to be_blank }
30
+ it { expect(actual_parsed).to eq(parsed_expected) }
31
+ end
32
+
33
+ context 'with only required values' do
34
+ let(:argv) { %w[--opt3 POS1] }
35
+ let(:parsed_expected) { { opt1: false, opt2: nil, opt3: true, pos1: 'POS1', pos2: [] } }
36
+
37
+ it { expect(instance.error).to be_blank }
38
+ it { expect(actual_parsed).to eq(parsed_expected) }
39
+ end
40
+
41
+ context 'with double dash' do
42
+ let(:argv) { %w[--opt3 POS1 -- --opt1 --] }
43
+ let(:parsed_expected) do
44
+ { opt1: false, opt2: nil, opt3: true, pos1: 'POS1', pos2: %w[--opt1 --] }
45
+ end
46
+
47
+ it { expect(instance.error).to be_blank }
48
+ it { expect(actual_parsed).to eq(parsed_expected) }
49
+ end
50
+
51
+ context 'without required positional' do
52
+ let(:argv) { %w[--opt1 --opt3] }
53
+ let(:parsed_expected) { { opt1: true, opt2: nil, opt3: true, pos1: nil, pos2: [] } }
54
+
55
+ it { expect(instance.error).to be_present }
56
+ it { expect(actual_parsed).to eq(parsed_expected) }
57
+ end
58
+
59
+ context 'without required option' do
60
+ let(:argv) { %w[--opt1 POS1] }
61
+ let(:parsed_expected) { { opt1: true, opt2: nil, opt3: false, pos1: 'POS1', pos2: [] } }
62
+
63
+ it { expect(instance.error).to be_present }
64
+ it { expect(actual_parsed).to eq(parsed_expected) }
65
+ end
66
+
67
+ context 'without any required option or positional' do
68
+ let(:argv) { %w[] }
69
+ let(:parsed_expected) { { opt1: false, opt2: nil, opt3: false, pos1: nil, pos2: [] } }
70
+
71
+ it { expect(instance.error).to be_present }
72
+ it { expect(actual_parsed).to eq(parsed_expected) }
73
+ end
74
+
75
+ context 'with excedent positional' do
76
+ let(:alternative) do
77
+ r = EacCli::Definition::Alternative.new
78
+ r.pos_arg :pos1
79
+ r
80
+ end
81
+
82
+ let(:argv) { %w[POS1 POS2] }
83
+ let(:parsed_expected) { { pos1: 'POS1' } }
84
+
85
+ it { expect(instance.error).to be_present }
86
+ it { expect(actual_parsed).to eq(parsed_expected) }
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+
5
+ RSpec.describe EacCli::Runner, '#for_context' do
6
+ let(:parent_runner_class) do
7
+ example = self
8
+ Class.new do
9
+ include example.described_class
10
+
11
+ def self.name
12
+ 'ParentRunnerClass'
13
+ end
14
+
15
+ for_context :method_for_context
16
+
17
+ def run; end
18
+
19
+ def method_for_context; end
20
+
21
+ def method_not_for_context; end
22
+ end
23
+ end
24
+
25
+ let(:child_runner_class1) do # rubocop:disable RSpec/IndexedLet
26
+ example = self
27
+ Class.new do
28
+ include example.described_class
29
+
30
+ def self.name
31
+ 'ChildRunnerClass1'
32
+ end
33
+
34
+ def run
35
+ method_for_context
36
+ runner_context.call(:method_for_context)
37
+ runner_context.call(:method_not_for_context)
38
+ end
39
+ end
40
+ end
41
+
42
+ let(:child_runner_class2) do # rubocop:disable RSpec/IndexedLet
43
+ example = self
44
+ Class.new do
45
+ include example.described_class
46
+
47
+ def self.name
48
+ 'ChildRunnerClass2'
49
+ end
50
+
51
+ def run
52
+ method_not_for_context
53
+ end
54
+ end
55
+ end
56
+
57
+ let(:parent_runner) { parent_runner_class.create }
58
+ let(:context_args) { [{ argv: [], parent: parent_runner }] }
59
+ let(:child_runner) { child_runner_class.create(*context_args) }
60
+
61
+ it { expect(parent_runner.for_context?(:method_for_context)).to be(true) }
62
+ it { expect(parent_runner.for_context?(:method_not_for_context)).to be(false) }
63
+
64
+ context 'when method is for context' do
65
+ let(:child_runner_class) { child_runner_class1 }
66
+
67
+ it do
68
+ expect { child_runner.run }.not_to raise_error
69
+ end
70
+ end
71
+
72
+ context 'when method is not for context' do
73
+ let(:child_runner_class) { child_runner_class2 }
74
+
75
+ it do
76
+ expect { child_runner.run }.to raise_error(NameError)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+
5
+ RSpec.describe EacCli::Runner do
6
+ let(:runner_class) do
7
+ the_module = described_class
8
+ Class.new do
9
+ include the_module
10
+
11
+ runner_definition do
12
+ arg_opt '-o', '--opt1', 'A arg option.'
13
+ bool_opt '-p', '--opt2', 'A boolean option'
14
+ arg_opt '-q', '--opt4', 'A repeatable argument option.', repeat: true
15
+ bool_opt '-r', '--opt5', 'A repeatable boolean option', repeat: true
16
+ arg_opt '-s', '--opt6', 'A argument option with default value', default: 'DEFAULT'
17
+ pos_arg :pos1
18
+ pos_arg :pos2, repeat: true, optional: true
19
+ alt do
20
+ bool_opt '-a', '--opt3', 'A boolean option in a alternative.', required: true
21
+ end
22
+ end
23
+
24
+ def run; end
25
+ end
26
+ end
27
+
28
+ let(:instance) { runner_class.create(argv) }
29
+ let(:parsed_actual) { instance.parsed.to_h.symbolize_keys }
30
+
31
+ context 'when all args are supplied' do
32
+ let(:argv) { %w[--opt1 aaa --opt2 bbb ccc ddd --opt6 6] }
33
+ let(:parsed_expected) do
34
+ { opt1: 'aaa', opt2: true, opt3: false, opt4: [], opt5: 0, opt6: '6', pos1: 'bbb',
35
+ pos2: %w[ccc ddd] }
36
+ end
37
+
38
+ it { expect(parsed_actual).to eq(parsed_expected) }
39
+ it { expect(instance.parsed.opt1).to eq('aaa') }
40
+ it { expect(instance.parsed.opt2?).to be(true) }
41
+ it { expect(instance.parsed.pos1).to eq('bbb') }
42
+ it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
43
+ end
44
+
45
+ context 'with long option and argument in same position' do
46
+ let(:argv) { %w[--opt1=aaa pos1] }
47
+
48
+ it { expect(instance.parsed.opt1).to eq('aaa') }
49
+ end
50
+
51
+ context 'with valid grouped short options' do
52
+ let(:argv) { %w[-po aaa pos1] }
53
+
54
+ it { expect(instance.parsed.opt1).to eq('aaa') }
55
+ it { expect(instance.parsed.opt2?).to be(true) }
56
+ end
57
+
58
+ context 'with invalid grouped short options' do
59
+ let(:argv) { %w[-op aaa pos1] }
60
+
61
+ it do
62
+ expect { instance.parsed }.to raise_error(EacCli::Parser::Error)
63
+ end
64
+ end
65
+
66
+ context 'when only required args are supplied' do
67
+ let(:argv) { %w[bbb] }
68
+ let(:parsed_expected) do
69
+ { opt1: nil, opt2: false, opt3: false, opt4: [], opt5: 0, opt6: 'DEFAULT', pos1: 'bbb',
70
+ pos2: [] }
71
+ end
72
+
73
+ it { expect(parsed_actual).to eq(parsed_expected) }
74
+ it { expect(instance.parsed.opt1).to be_nil }
75
+ it { expect(instance.parsed.opt2?).to be(false) }
76
+ it { expect(instance.parsed.pos1).to eq('bbb') }
77
+ it { expect(instance.parsed.pos2).to eq([]) }
78
+ end
79
+
80
+ context 'when required args are not supplied' do
81
+ let(:argv) { %w[] }
82
+
83
+ it do
84
+ expect { instance.parsed }.to raise_error(EacCli::Parser::Error)
85
+ end
86
+ end
87
+
88
+ context 'when alternative args are supplied' do
89
+ let(:argv) { %w[--opt3] }
90
+ let(:parsed_expected) do
91
+ { opt1: nil, opt2: false, opt3: true, opt4: [], opt5: 0, opt6: 'DEFAULT', pos1: nil,
92
+ pos2: [] }
93
+ end
94
+
95
+ it { expect(parsed_actual).to eq(parsed_expected) }
96
+ it { expect(instance.parsed.opt3?).to be(true) }
97
+ end
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, opt6: 'DEFAULT', pos1: 'AAA',
103
+ pos2: [] }
104
+ end
105
+
106
+ it { expect(parsed_actual).to eq(parsed_expected) }
107
+ end
108
+
109
+ context 'when extra args are not supplied' do
110
+ let(:runner_class) do
111
+ the_module = described_class
112
+ Class.new do
113
+ include the_module
114
+
115
+ runner_definition do
116
+ pos_arg :pos1
117
+ end
118
+
119
+ def run; end
120
+ end
121
+ end
122
+
123
+ let(:argv) { %w[aaa bbb] }
124
+
125
+ it do
126
+ expect { instance.parsed }.to raise_error(EacCli::Parser::Error)
127
+ end
128
+ end
129
+ end