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,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module RunnerWith
5
+ module Output
6
+ STDOUT_OPTION = '-'
7
+ DEFAULT_FILE_OPTION = '+'
8
+ DEFAULT_DEFAULT_OUTPUT_OPTION = STDOUT_OPTION
9
+ DEFAULT_DEFAULT_FILE_TO_OUTPUT = 'output'
10
+
11
+ common_concern do
12
+ enable_abstract_methods
13
+ enable_settings_provider
14
+ include ::EacCli::Runner
15
+
16
+ abstract_methods :output_content
17
+
18
+ runner_definition do
19
+ arg_opt '-o', '--output', 'Output to file.'
20
+ end
21
+ end
22
+
23
+ def run_output
24
+ file = file_to_output
25
+ if file
26
+ file.to_pathname.write(output_content)
27
+ else
28
+ $stdout.write(output_content)
29
+ end
30
+ end
31
+
32
+ def output_option
33
+ parsed.output || default_output_option_value
34
+ end
35
+
36
+ def file_to_output
37
+ case output_option
38
+ when STDOUT_OPTION then nil
39
+ when DEFAULT_FILE_OPTION then default_file_to_output_value
40
+ else output_option
41
+ end
42
+ end
43
+
44
+ def default_output_option_value
45
+ setting_value(:default_output_option,
46
+ default: DEFAULT_DEFAULT_OUTPUT_OPTION)
47
+ end
48
+
49
+ def default_file_to_output_value
50
+ setting_value(:default_file_to_output, default: DEFAULT_DEFAULT_FILE_TO_OUTPUT)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module EacCli
6
+ module RunnerWith
7
+ module OutputItem
8
+ class AsciidocFormatter < ::EacCli::RunnerWith::OutputItem::BaseFormatter
9
+ STARTING_LEVEL = 2
10
+
11
+ # @return [String]
12
+ def to_output
13
+ output_hash(item_hash, STARTING_LEVEL)
14
+ end
15
+
16
+ protected
17
+
18
+ # @param hash [Hash]
19
+ # @param level [Integer]
20
+ # @return [String]
21
+ def output_enumerable(enumerable, level)
22
+ enumerable.map { |e| output_object(e, level + 1) }.join
23
+ end
24
+
25
+ # @param hash [Hash]
26
+ # @param level [Integer]
27
+ # @return [String]
28
+ def output_hash(hash, level)
29
+ hash.map { |k, v| section(k, v, level) }.join("\n")
30
+ end
31
+
32
+ def output_object(object, level)
33
+ return output_hash(object, level) if object.is_a?(::Hash)
34
+ return output_enumerable(object, level) if object.is_a?(::Enumerable)
35
+
36
+ output_string(object, level)
37
+ end
38
+
39
+ # @param string [String]
40
+ # @param level [Integer]
41
+ # @return [String]
42
+ def output_string(string, _level)
43
+ "* #{string.to_s.strip}\n"
44
+ end
45
+
46
+ # @param title [String]
47
+ # @param content [String]
48
+ # @param level [Integer]
49
+ # @return [String]
50
+ def section(title, content, level)
51
+ "#{section_title(title, level)}\n\n#{section_content(content, level)}"
52
+ end
53
+
54
+ # @param title [String]
55
+ # @param level [Integer]
56
+ # @return [String]
57
+ def section_title(title, level)
58
+ "#{'=' * level} #{title}"
59
+ end
60
+
61
+ # @param content [String]
62
+ # @param level [Integer]
63
+ # @return [String]
64
+ def section_content(content, level)
65
+ output_object(content, level)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module RunnerWith
5
+ module OutputItem
6
+ class BaseFormatter
7
+ acts_as_abstract :to_output
8
+ common_constructor :item_hash
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+
5
+ module EacCli
6
+ module RunnerWith
7
+ module OutputItem
8
+ class CsvFormatter < ::EacCli::RunnerWith::OutputItem::BaseFormatter
9
+ COLUMNS = %w[key value].freeze
10
+
11
+ # @return [String]
12
+ def to_output
13
+ ::CSV.generate do |csv|
14
+ csv << COLUMNS
15
+ item_hash.each { |k, v| csv << [k, v] }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module EacCli
6
+ module RunnerWith
7
+ module OutputItem
8
+ class YamlFormatter < ::EacCli::RunnerWith::OutputItem::BaseFormatter
9
+ # @return [String]
10
+ def to_output
11
+ ::YAML.dump(item_hash.deep_stringify_keys)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module RunnerWith
5
+ module OutputItem
6
+ require_sub __FILE__
7
+
8
+ FORMATS = %w[asciidoc csv yaml].freeze
9
+
10
+ common_concern do
11
+ acts_as_abstract :item_hash
12
+ include ::EacCli::RunnerWith::Output
13
+
14
+ runner_definition do
15
+ arg_opt '-f', '--format', 'Format to output item.', default: 'yaml'
16
+ end
17
+ end
18
+
19
+ # @return [String]
20
+ def output_content
21
+ formatter.to_output
22
+ end
23
+
24
+ # @return [EacCli::RunnerWith::OutputList::BaseFormatter]
25
+ def formatter
26
+ formatter_class.new(item_hash)
27
+ end
28
+
29
+ # @return [Class]
30
+ def formatter_class
31
+ formats.fetch(parsed.format)
32
+ end
33
+
34
+ # @return [Hash<String, Class>]
35
+ def formats
36
+ FORMATS.to_h do |e|
37
+ [e, ::EacCli::RunnerWith::OutputItem.const_get("#{e.camelize}Formatter")]
38
+ end
39
+ end
40
+
41
+ # @return [Hash<String, Enumerable<String>]
42
+ def help_extra_text
43
+ help_list_section('Formats', formats.keys.sort)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module RunnerWith
5
+ module OutputList
6
+ class BaseFormatter
7
+ acts_as_abstract :to_output
8
+ common_constructor :columns, :rows
9
+
10
+ # @return [String]
11
+ def build_column(column)
12
+ column.to_s
13
+ end
14
+
15
+ # @return [Array<String>]
16
+ def build_columns
17
+ columns.map(&:to_s)
18
+ end
19
+
20
+ # @param row [Object]
21
+ # @return [Object]
22
+ def build_row(_row)
23
+ raise_abstract_method __method__
24
+ end
25
+
26
+ # @return [Array<Hash<String, String>>]
27
+ def build_rows
28
+ rows.map { |row| build_row(row) }
29
+ end
30
+
31
+ # @param row [Object]
32
+ # @param column [String]
33
+ # @return [Object]
34
+ def build_value(row, column)
35
+ return row.send(column) if row.respond_to?(column)
36
+ return row.with_indifferent_access.fetch(column) if row.is_a?(::Hash)
37
+
38
+ raise ::ArgumentError, "Row \"#{row}\" do not respond to column \"#{column}\" neither " \
39
+ "is a Hash (Row: #{row}, Column: #{column})"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+
5
+ module EacCli
6
+ module RunnerWith
7
+ module OutputList
8
+ class CsvFormatter < ::EacCli::RunnerWith::OutputList::BaseFormatter
9
+ # @return [Array]
10
+ def build_row(row)
11
+ build_columns.map { |c| build_value(row, c) }
12
+ end
13
+
14
+ # @return [String]
15
+ def to_output
16
+ ::CSV.generate do |csv|
17
+ csv << build_columns
18
+ build_rows.each { |row| csv << row }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty/table'
4
+
5
+ module EacCli
6
+ module RunnerWith
7
+ module OutputList
8
+ class TtyFormatter < ::EacCli::RunnerWith::OutputList::BaseFormatter
9
+ # @param row [Object]
10
+ # @return [Array]
11
+ def build_row(row)
12
+ build_columns.map { |c| build_value(row, c) }
13
+ end
14
+
15
+ # @return [String]
16
+ def to_output
17
+ "#{tty_table_output}\n"
18
+ end
19
+
20
+ # @return [TTY::Table]
21
+ def tty_table
22
+ ::TTY::Table.new(build_columns, build_rows)
23
+ end
24
+
25
+ # @return [String]
26
+ def tty_table_output
27
+ tty_table.render(:unicode, multiline: true) do |renderer|
28
+ renderer.border.separator = ->(row) { ((row + 1) % columns.count).zero? }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module EacCli
6
+ module RunnerWith
7
+ module OutputList
8
+ class YamlFormatter < ::EacCli::RunnerWith::OutputList::BaseFormatter
9
+ # @return [Hash<String, String>]
10
+ def build_row(row)
11
+ build_columns.inject({}) { |a, e| a.merge(e => build_value(row, e).to_s) }
12
+ end
13
+
14
+ # @return [String]
15
+ def to_output
16
+ ::YAML.dump(build_rows)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module RunnerWith
5
+ module OutputList
6
+ require_sub __FILE__
7
+
8
+ FORMATS = {
9
+ 'csv' => ::EacCli::RunnerWith::OutputList::CsvFormatter,
10
+ 'tty' => ::EacCli::RunnerWith::OutputList::TtyFormatter,
11
+ 'yaml' => ::EacCli::RunnerWith::OutputList::YamlFormatter
12
+ }.freeze
13
+
14
+ common_concern do
15
+ acts_as_abstract :list_columns, :list_rows
16
+ include ::EacCli::RunnerWith::Output
17
+
18
+ runner_definition do
19
+ arg_opt '-f', '--format', 'Format to output list.', default: 'yaml'
20
+ end
21
+ end
22
+
23
+ # @return [String]
24
+ def output_content
25
+ formatter.to_output
26
+ end
27
+
28
+ # @return [EacCli::RunnerWith::OutputList::BaseFormatter]
29
+ def formatter
30
+ formatter_class.new(list_columns, list_rows)
31
+ end
32
+
33
+ # @return [Class]
34
+ def formatter_class
35
+ FORMATS.fetch(parsed.format)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module RunnerWith
5
+ module Subcommands
6
+ module DefinitionConcern
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module RunnerWith
5
+ module Subcommands
6
+ require_sub __FILE__
7
+
8
+ class << self
9
+ delegate :runner?, to: :'::EacCli::Runner'
10
+
11
+ # @return [Hash<String, EacCli::Runner>]
12
+ def subcommands_from_module(a_module)
13
+ a_module.constants
14
+ .map { |name| [name.to_s.underscore.gsub('_', '-'), a_module.const_get(name)] }
15
+ .select { |c| runner?(c[1]) }
16
+ .to_h.with_indifferent_access
17
+ end
18
+ end
19
+
20
+ common_concern do
21
+ include ::EacCli::Runner
22
+ runner_definition.singleton_class
23
+ .include(::EacCli::RunnerWith::Subcommands::DefinitionConcern)
24
+ end
25
+
26
+ EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME = :extra_available_subcommands
27
+
28
+ def available_subcommands
29
+ @available_subcommands ||= available_subcommands_auto.merge(available_subcommands_extra)
30
+ end
31
+
32
+ # @return [Hash<String, EacCli::Runner>]
33
+ def available_subcommands_auto
34
+ ::EacCli::RunnerWith::Subcommands.subcommands_from_module(self.class)
35
+ end
36
+
37
+ def available_subcommands_extra
38
+ if respond_to?(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME, true)
39
+ send(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME)
40
+ else
41
+ {}
42
+ end
43
+ end
44
+
45
+ def available_subcommands_to_s
46
+ available_subcommands.keys.sort.join(', ')
47
+ end
48
+
49
+ # @return [Hash<String, Enumerable<String>]
50
+ def help_extra_text
51
+ help_list_section('Subcommands', available_subcommands.keys.sort)
52
+ end
53
+
54
+ def method_missing(method_name, *arguments, &block)
55
+ return run_with_subcommand(*arguments, &block) if
56
+ run_with_subcommand_alias_run?(method_name)
57
+
58
+ super
59
+ end
60
+
61
+ def respond_to_missing?(method_name, include_private = false)
62
+ run_with_subcommand_alias_run?(method_name) || super
63
+ end
64
+
65
+ def run_with_subcommand
66
+ if run_subcommand?
67
+ if subcommand_runner.respond_to?(:run_run)
68
+ subcommand_runner.run_run
69
+ else
70
+ subcommand_runner.run
71
+ end
72
+ else
73
+ run_without_subcommand
74
+ end
75
+ end
76
+
77
+ def run_with_subcommand_alias_run?(method_name)
78
+ subcommands? && method_name.to_sym == :run
79
+ end
80
+
81
+ def run_without_subcommand
82
+ "Method #{__method__} should be overrided in #{self.class.name}"
83
+ end
84
+
85
+ def run_subcommand?
86
+ subcommand_name.present?
87
+ end
88
+
89
+ def subcommands?
90
+ self.class.runner_definition.subcommands?
91
+ end
92
+
93
+ def subcommand_args
94
+ parsed.fetch(::EacCli::Definition::SUBCOMMAND_ARGS_ARG)
95
+ end
96
+
97
+ def subcommand_class
98
+ available_subcommands[subcommand_name].if_present { |v| return v }
99
+
100
+ raise(::EacCli::Parser::Error.new(
101
+ self.class.runner_definition, runner_context.argv,
102
+ "Subcommand \"#{subcommand_name}\" not found " \
103
+ "(Available: #{available_subcommands_to_s})"
104
+ ))
105
+ end
106
+
107
+ def subcommand_name
108
+ parsed.fetch(::EacCli::Definition::SUBCOMMAND_NAME_ARG)
109
+ end
110
+
111
+ def subcommand_program
112
+ [program_name, subcommand_name]
113
+ end
114
+
115
+ def subcommand_runner
116
+ @subcommand_runner ||= subcommand_class.create(
117
+ argv: subcommand_args,
118
+ program_name: subcommand_program,
119
+ parent: self
120
+ )
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module RunnerWith
5
+ require_sub __FILE__
6
+ end
7
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ class RunnerWithSet
5
+ class << self
6
+ def default
7
+ @default ||= new
8
+ end
9
+ end
10
+
11
+ def add_namespace(namespace)
12
+ namespace = sanitize_namespace(namespace)
13
+ namespace_set << namespace unless namespace_set.include?(namespace)
14
+ self
15
+ end
16
+
17
+ def add_from_gems_registry
18
+ ::EacRubyUtils::GemsRegistry.new('RunnerWith').registered.each do |registered_gem|
19
+ add_namespace(registered_gem.registered_module)
20
+ end
21
+ end
22
+
23
+ def item_to_module(item)
24
+ item.is_a?(::Module) ? item : key_to_module(item)
25
+ end
26
+
27
+ def namespaces
28
+ namespace_set.dup
29
+ end
30
+
31
+ private
32
+
33
+ def namespace_set
34
+ @namespace_set ||= []
35
+ end
36
+
37
+ def key_to_module(key)
38
+ namespace_set.lazy
39
+ .map { |namespace| key_to_module_in_namespace(namespace, key) }
40
+ .find(&:present?) ||
41
+ raise("Not module found with key \"#{key}\" (Namespaces: #{namespace_set})")
42
+ end
43
+
44
+ def key_to_module_in_namespace(namespace, key)
45
+ namespace.const_get(key.to_s.camelize)
46
+ rescue ::NameError
47
+ nil
48
+ end
49
+
50
+ def sanitize_namespace(source)
51
+ source.is_a?(::Module) ? source : source.to_s.constantize
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ class Speaker
5
+ module Constants
6
+ STDERR = ::EacRubyUtils::ByReference.new { $stderr }
7
+ STDIN = ::EacRubyUtils::ByReference.new { $stdin }
8
+ STDOUT = ::EacRubyUtils::ByReference.new { $stdout }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ class Speaker
5
+ class InputBlocked
6
+ %w[gets noecho].each do |method|
7
+ define_method(method) do
8
+ raise ::EacCli::Speaker::InputRequested,
9
+ "Method (\"#{method}\") was requested, but input is blocked"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ class Speaker
5
+ class InputRequested < ::RuntimeError
6
+ end
7
+ end
8
+ end