saikouda 0.1.0

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 (228) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/CODE_OF_CONDUCT.md +74 -0
  4. data/Gemfile +5 -0
  5. data/Gemfile.lock +22 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +43 -0
  8. data/Rakefile +2 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/exe/saikouda +5 -0
  12. data/lib/saikouda/cli.rb +106 -0
  13. data/lib/saikouda/version.rb +3 -0
  14. data/lib/saikouda.rb +7 -0
  15. data/saikouda.gemspec +34 -0
  16. data/vendor/bundle/bin/rake +27 -0
  17. data/vendor/bundle/bin/saikouda +27 -0
  18. data/vendor/bundle/bin/thor +27 -0
  19. data/vendor/bundle/cache/rake-10.5.0.gem +0 -0
  20. data/vendor/bundle/cache/thor-0.20.3.gem +0 -0
  21. data/vendor/bundle/gems/rake-10.5.0/.autotest +7 -0
  22. data/vendor/bundle/gems/rake-10.5.0/.rubocop.yml +27 -0
  23. data/vendor/bundle/gems/rake-10.5.0/.togglerc +7 -0
  24. data/vendor/bundle/gems/rake-10.5.0/CONTRIBUTING.rdoc +38 -0
  25. data/vendor/bundle/gems/rake-10.5.0/History.rdoc +659 -0
  26. data/vendor/bundle/gems/rake-10.5.0/MIT-LICENSE +21 -0
  27. data/vendor/bundle/gems/rake-10.5.0/Manifest.txt +166 -0
  28. data/vendor/bundle/gems/rake-10.5.0/README.rdoc +139 -0
  29. data/vendor/bundle/gems/rake-10.5.0/Rakefile +81 -0
  30. data/vendor/bundle/gems/rake-10.5.0/bin/rake +33 -0
  31. data/vendor/bundle/gems/rake-10.5.0/doc/command_line_usage.rdoc +158 -0
  32. data/vendor/bundle/gems/rake-10.5.0/doc/example/Rakefile1 +38 -0
  33. data/vendor/bundle/gems/rake-10.5.0/doc/example/Rakefile2 +35 -0
  34. data/vendor/bundle/gems/rake-10.5.0/doc/example/a.c +6 -0
  35. data/vendor/bundle/gems/rake-10.5.0/doc/example/b.c +6 -0
  36. data/vendor/bundle/gems/rake-10.5.0/doc/example/main.c +11 -0
  37. data/vendor/bundle/gems/rake-10.5.0/doc/glossary.rdoc +42 -0
  38. data/vendor/bundle/gems/rake-10.5.0/doc/jamis.rb +591 -0
  39. data/vendor/bundle/gems/rake-10.5.0/doc/proto_rake.rdoc +127 -0
  40. data/vendor/bundle/gems/rake-10.5.0/doc/rake.1 +141 -0
  41. data/vendor/bundle/gems/rake-10.5.0/doc/rakefile.rdoc +624 -0
  42. data/vendor/bundle/gems/rake-10.5.0/doc/rational.rdoc +151 -0
  43. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.4.14.rdoc +23 -0
  44. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.4.15.rdoc +35 -0
  45. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.5.0.rdoc +53 -0
  46. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.5.3.rdoc +78 -0
  47. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.5.4.rdoc +46 -0
  48. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.6.0.rdoc +141 -0
  49. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.7.0.rdoc +119 -0
  50. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.7.1.rdoc +59 -0
  51. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.7.2.rdoc +121 -0
  52. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.7.3.rdoc +47 -0
  53. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.8.0.rdoc +114 -0
  54. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.8.2.rdoc +165 -0
  55. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.8.3.rdoc +112 -0
  56. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.8.4.rdoc +147 -0
  57. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.8.5.rdoc +53 -0
  58. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.8.6.rdoc +37 -0
  59. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.8.7.rdoc +55 -0
  60. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.9.0.rdoc +112 -0
  61. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.9.1.rdoc +52 -0
  62. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.9.2.2.rdoc +55 -0
  63. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.9.2.rdoc +49 -0
  64. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.9.3.rdoc +102 -0
  65. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.9.4.rdoc +60 -0
  66. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.9.5.rdoc +55 -0
  67. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-0.9.6.rdoc +64 -0
  68. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-10.0.0.rdoc +178 -0
  69. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-10.0.1.rdoc +58 -0
  70. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-10.0.2.rdoc +53 -0
  71. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-10.0.3.rdoc +191 -0
  72. data/vendor/bundle/gems/rake-10.5.0/doc/release_notes/rake-10.1.0.rdoc +61 -0
  73. data/vendor/bundle/gems/rake-10.5.0/lib/rake/alt_system.rb +110 -0
  74. data/vendor/bundle/gems/rake-10.5.0/lib/rake/application.rb +790 -0
  75. data/vendor/bundle/gems/rake-10.5.0/lib/rake/backtrace.rb +23 -0
  76. data/vendor/bundle/gems/rake-10.5.0/lib/rake/clean.rb +76 -0
  77. data/vendor/bundle/gems/rake-10.5.0/lib/rake/cloneable.rb +16 -0
  78. data/vendor/bundle/gems/rake-10.5.0/lib/rake/contrib/.document +1 -0
  79. data/vendor/bundle/gems/rake-10.5.0/lib/rake/contrib/compositepublisher.rb +21 -0
  80. data/vendor/bundle/gems/rake-10.5.0/lib/rake/contrib/ftptools.rb +137 -0
  81. data/vendor/bundle/gems/rake-10.5.0/lib/rake/contrib/publisher.rb +81 -0
  82. data/vendor/bundle/gems/rake-10.5.0/lib/rake/contrib/rubyforgepublisher.rb +18 -0
  83. data/vendor/bundle/gems/rake-10.5.0/lib/rake/contrib/sshpublisher.rb +61 -0
  84. data/vendor/bundle/gems/rake-10.5.0/lib/rake/contrib/sys.rb +4 -0
  85. data/vendor/bundle/gems/rake-10.5.0/lib/rake/cpu_counter.rb +125 -0
  86. data/vendor/bundle/gems/rake-10.5.0/lib/rake/default_loader.rb +14 -0
  87. data/vendor/bundle/gems/rake-10.5.0/lib/rake/dsl_definition.rb +201 -0
  88. data/vendor/bundle/gems/rake-10.5.0/lib/rake/early_time.rb +21 -0
  89. data/vendor/bundle/gems/rake-10.5.0/lib/rake/ext/core.rb +25 -0
  90. data/vendor/bundle/gems/rake-10.5.0/lib/rake/ext/module.rb +2 -0
  91. data/vendor/bundle/gems/rake-10.5.0/lib/rake/ext/pathname.rb +25 -0
  92. data/vendor/bundle/gems/rake-10.5.0/lib/rake/ext/string.rb +175 -0
  93. data/vendor/bundle/gems/rake-10.5.0/lib/rake/ext/time.rb +18 -0
  94. data/vendor/bundle/gems/rake-10.5.0/lib/rake/file_creation_task.rb +24 -0
  95. data/vendor/bundle/gems/rake-10.5.0/lib/rake/file_list.rb +428 -0
  96. data/vendor/bundle/gems/rake-10.5.0/lib/rake/file_task.rb +46 -0
  97. data/vendor/bundle/gems/rake-10.5.0/lib/rake/file_utils.rb +128 -0
  98. data/vendor/bundle/gems/rake-10.5.0/lib/rake/file_utils_ext.rb +144 -0
  99. data/vendor/bundle/gems/rake-10.5.0/lib/rake/gempackagetask.rb +4 -0
  100. data/vendor/bundle/gems/rake-10.5.0/lib/rake/invocation_chain.rb +56 -0
  101. data/vendor/bundle/gems/rake-10.5.0/lib/rake/invocation_exception_mixin.rb +16 -0
  102. data/vendor/bundle/gems/rake-10.5.0/lib/rake/late_time.rb +17 -0
  103. data/vendor/bundle/gems/rake-10.5.0/lib/rake/linked_list.rb +103 -0
  104. data/vendor/bundle/gems/rake-10.5.0/lib/rake/loaders/makefile.rb +53 -0
  105. data/vendor/bundle/gems/rake-10.5.0/lib/rake/multi_task.rb +13 -0
  106. data/vendor/bundle/gems/rake-10.5.0/lib/rake/name_space.rb +38 -0
  107. data/vendor/bundle/gems/rake-10.5.0/lib/rake/packagetask.rb +199 -0
  108. data/vendor/bundle/gems/rake-10.5.0/lib/rake/pathmap.rb +3 -0
  109. data/vendor/bundle/gems/rake-10.5.0/lib/rake/phony.rb +15 -0
  110. data/vendor/bundle/gems/rake-10.5.0/lib/rake/private_reader.rb +20 -0
  111. data/vendor/bundle/gems/rake-10.5.0/lib/rake/promise.rb +99 -0
  112. data/vendor/bundle/gems/rake-10.5.0/lib/rake/pseudo_status.rb +29 -0
  113. data/vendor/bundle/gems/rake-10.5.0/lib/rake/rake_module.rb +38 -0
  114. data/vendor/bundle/gems/rake-10.5.0/lib/rake/rake_test_loader.rb +22 -0
  115. data/vendor/bundle/gems/rake-10.5.0/lib/rake/rdoctask.rb +4 -0
  116. data/vendor/bundle/gems/rake-10.5.0/lib/rake/ruby182_test_unit_fix.rb +29 -0
  117. data/vendor/bundle/gems/rake-10.5.0/lib/rake/rule_recursion_overflow_error.rb +20 -0
  118. data/vendor/bundle/gems/rake-10.5.0/lib/rake/runtest.rb +27 -0
  119. data/vendor/bundle/gems/rake-10.5.0/lib/rake/scope.rb +42 -0
  120. data/vendor/bundle/gems/rake-10.5.0/lib/rake/task.rb +383 -0
  121. data/vendor/bundle/gems/rake-10.5.0/lib/rake/task_argument_error.rb +7 -0
  122. data/vendor/bundle/gems/rake-10.5.0/lib/rake/task_arguments.rb +98 -0
  123. data/vendor/bundle/gems/rake-10.5.0/lib/rake/task_manager.rb +307 -0
  124. data/vendor/bundle/gems/rake-10.5.0/lib/rake/tasklib.rb +24 -0
  125. data/vendor/bundle/gems/rake-10.5.0/lib/rake/testtask.rb +213 -0
  126. data/vendor/bundle/gems/rake-10.5.0/lib/rake/thread_history_display.rb +48 -0
  127. data/vendor/bundle/gems/rake-10.5.0/lib/rake/thread_pool.rb +164 -0
  128. data/vendor/bundle/gems/rake-10.5.0/lib/rake/trace_output.rb +22 -0
  129. data/vendor/bundle/gems/rake-10.5.0/lib/rake/version.rb +7 -0
  130. data/vendor/bundle/gems/rake-10.5.0/lib/rake/win32.rb +56 -0
  131. data/vendor/bundle/gems/rake-10.5.0/lib/rake.rb +79 -0
  132. data/vendor/bundle/gems/rake-10.5.0/rakelib/publish.rake +20 -0
  133. data/vendor/bundle/gems/rake-10.5.0/rakelib/test_times.rake +25 -0
  134. data/vendor/bundle/gems/rake-10.5.0/test/file_creation.rb +34 -0
  135. data/vendor/bundle/gems/rake-10.5.0/test/helper.rb +129 -0
  136. data/vendor/bundle/gems/rake-10.5.0/test/support/rakefile_definitions.rb +478 -0
  137. data/vendor/bundle/gems/rake-10.5.0/test/support/ruby_runner.rb +34 -0
  138. data/vendor/bundle/gems/rake-10.5.0/test/test_private_reader.rb +42 -0
  139. data/vendor/bundle/gems/rake-10.5.0/test/test_rake.rb +40 -0
  140. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_application.rb +643 -0
  141. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_application_options.rb +468 -0
  142. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_backtrace.rb +119 -0
  143. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_clean.rb +61 -0
  144. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_cpu_counter.rb +68 -0
  145. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_definitions.rb +84 -0
  146. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_directory_task.rb +76 -0
  147. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_dsl.rb +40 -0
  148. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_early_time.rb +31 -0
  149. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_extension.rb +59 -0
  150. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_file_creation_task.rb +56 -0
  151. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_file_list.rb +670 -0
  152. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_file_list_path_map.rb +8 -0
  153. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_file_task.rb +197 -0
  154. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_file_utils.rb +314 -0
  155. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_ftp_file.rb +74 -0
  156. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_functional.rb +482 -0
  157. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_invocation_chain.rb +64 -0
  158. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_late_time.rb +18 -0
  159. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_linked_list.rb +84 -0
  160. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_makefile_loader.rb +46 -0
  161. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_multi_task.rb +64 -0
  162. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_name_space.rb +57 -0
  163. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_package_task.rb +79 -0
  164. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_path_map.rb +168 -0
  165. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_path_map_explode.rb +34 -0
  166. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_path_map_partial.rb +18 -0
  167. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_pathname_extensions.rb +15 -0
  168. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_pseudo_status.rb +21 -0
  169. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_rake_test_loader.rb +20 -0
  170. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_reduce_compat.rb +26 -0
  171. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_require.rb +40 -0
  172. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_rules.rb +388 -0
  173. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_scope.rb +44 -0
  174. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_task.rb +393 -0
  175. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_task_argument_parsing.rb +119 -0
  176. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_task_arguments.rb +127 -0
  177. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_task_lib.rb +9 -0
  178. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_task_manager.rb +178 -0
  179. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_task_manager_argument_resolution.rb +19 -0
  180. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_task_with_arguments.rb +172 -0
  181. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_test_task.rb +146 -0
  182. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_thread_pool.rb +145 -0
  183. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_top_level_functions.rb +71 -0
  184. data/vendor/bundle/gems/rake-10.5.0/test/test_rake_win32.rb +72 -0
  185. data/vendor/bundle/gems/rake-10.5.0/test/test_thread_history_display.rb +101 -0
  186. data/vendor/bundle/gems/rake-10.5.0/test/test_trace_output.rb +52 -0
  187. data/vendor/bundle/gems/thor-0.20.3/.document +5 -0
  188. data/vendor/bundle/gems/thor-0.20.3/CHANGELOG.md +204 -0
  189. data/vendor/bundle/gems/thor-0.20.3/CONTRIBUTING.md +15 -0
  190. data/vendor/bundle/gems/thor-0.20.3/LICENSE.md +20 -0
  191. data/vendor/bundle/gems/thor-0.20.3/README.md +51 -0
  192. data/vendor/bundle/gems/thor-0.20.3/bin/thor +6 -0
  193. data/vendor/bundle/gems/thor-0.20.3/lib/thor/actions/create_file.rb +104 -0
  194. data/vendor/bundle/gems/thor-0.20.3/lib/thor/actions/create_link.rb +60 -0
  195. data/vendor/bundle/gems/thor-0.20.3/lib/thor/actions/directory.rb +118 -0
  196. data/vendor/bundle/gems/thor-0.20.3/lib/thor/actions/empty_directory.rb +143 -0
  197. data/vendor/bundle/gems/thor-0.20.3/lib/thor/actions/file_manipulation.rb +373 -0
  198. data/vendor/bundle/gems/thor-0.20.3/lib/thor/actions/inject_into_file.rb +109 -0
  199. data/vendor/bundle/gems/thor-0.20.3/lib/thor/actions.rb +331 -0
  200. data/vendor/bundle/gems/thor-0.20.3/lib/thor/base.rb +678 -0
  201. data/vendor/bundle/gems/thor-0.20.3/lib/thor/command.rb +135 -0
  202. data/vendor/bundle/gems/thor-0.20.3/lib/thor/core_ext/hash_with_indifferent_access.rb +97 -0
  203. data/vendor/bundle/gems/thor-0.20.3/lib/thor/core_ext/io_binary_read.rb +12 -0
  204. data/vendor/bundle/gems/thor-0.20.3/lib/thor/core_ext/ordered_hash.rb +129 -0
  205. data/vendor/bundle/gems/thor-0.20.3/lib/thor/error.rb +114 -0
  206. data/vendor/bundle/gems/thor-0.20.3/lib/thor/group.rb +281 -0
  207. data/vendor/bundle/gems/thor-0.20.3/lib/thor/invocation.rb +177 -0
  208. data/vendor/bundle/gems/thor-0.20.3/lib/thor/line_editor/basic.rb +37 -0
  209. data/vendor/bundle/gems/thor-0.20.3/lib/thor/line_editor/readline.rb +88 -0
  210. data/vendor/bundle/gems/thor-0.20.3/lib/thor/line_editor.rb +17 -0
  211. data/vendor/bundle/gems/thor-0.20.3/lib/thor/parser/argument.rb +70 -0
  212. data/vendor/bundle/gems/thor-0.20.3/lib/thor/parser/arguments.rb +175 -0
  213. data/vendor/bundle/gems/thor-0.20.3/lib/thor/parser/option.rb +146 -0
  214. data/vendor/bundle/gems/thor-0.20.3/lib/thor/parser/options.rb +226 -0
  215. data/vendor/bundle/gems/thor-0.20.3/lib/thor/parser.rb +4 -0
  216. data/vendor/bundle/gems/thor-0.20.3/lib/thor/rake_compat.rb +71 -0
  217. data/vendor/bundle/gems/thor-0.20.3/lib/thor/runner.rb +324 -0
  218. data/vendor/bundle/gems/thor-0.20.3/lib/thor/shell/basic.rb +482 -0
  219. data/vendor/bundle/gems/thor-0.20.3/lib/thor/shell/color.rb +149 -0
  220. data/vendor/bundle/gems/thor-0.20.3/lib/thor/shell/html.rb +126 -0
  221. data/vendor/bundle/gems/thor-0.20.3/lib/thor/shell.rb +81 -0
  222. data/vendor/bundle/gems/thor-0.20.3/lib/thor/util.rb +268 -0
  223. data/vendor/bundle/gems/thor-0.20.3/lib/thor/version.rb +3 -0
  224. data/vendor/bundle/gems/thor-0.20.3/lib/thor.rb +509 -0
  225. data/vendor/bundle/gems/thor-0.20.3/thor.gemspec +21 -0
  226. data/vendor/bundle/specifications/rake-10.5.0.gemspec +43 -0
  227. data/vendor/bundle/specifications/thor-0.20.3.gemspec +35 -0
  228. metadata +314 -0
@@ -0,0 +1,482 @@
1
+ class Thor
2
+ module Shell
3
+ class Basic
4
+ DEFAULT_TERMINAL_WIDTH = 80
5
+
6
+ attr_accessor :base
7
+ attr_reader :padding
8
+
9
+ # Initialize base, mute and padding to nil.
10
+ #
11
+ def initialize #:nodoc:
12
+ @base = nil
13
+ @mute = false
14
+ @padding = 0
15
+ @always_force = false
16
+ end
17
+
18
+ # Mute everything that's inside given block
19
+ #
20
+ def mute
21
+ @mute = true
22
+ yield
23
+ ensure
24
+ @mute = false
25
+ end
26
+
27
+ # Check if base is muted
28
+ #
29
+ def mute?
30
+ @mute
31
+ end
32
+
33
+ # Sets the output padding, not allowing less than zero values.
34
+ #
35
+ def padding=(value)
36
+ @padding = [0, value].max
37
+ end
38
+
39
+ # Sets the output padding while executing a block and resets it.
40
+ #
41
+ def indent(count = 1)
42
+ orig_padding = padding
43
+ self.padding = padding + count
44
+ yield
45
+ self.padding = orig_padding
46
+ end
47
+
48
+ # Asks something to the user and receives a response.
49
+ #
50
+ # If a default value is specified it will be presented to the user
51
+ # and allows them to select that value with an empty response. This
52
+ # option is ignored when limited answers are supplied.
53
+ #
54
+ # If asked to limit the correct responses, you can pass in an
55
+ # array of acceptable answers. If one of those is not supplied,
56
+ # they will be shown a message stating that one of those answers
57
+ # must be given and re-asked the question.
58
+ #
59
+ # If asking for sensitive information, the :echo option can be set
60
+ # to false to mask user input from $stdin.
61
+ #
62
+ # If the required input is a path, then set the path option to
63
+ # true. This will enable tab completion for file paths relative
64
+ # to the current working directory on systems that support
65
+ # Readline.
66
+ #
67
+ # ==== Example
68
+ # ask("What is your name?")
69
+ #
70
+ # ask("What is the planet furthest from the sun?", :default => "Pluto")
71
+ #
72
+ # ask("What is your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])
73
+ #
74
+ # ask("What is your password?", :echo => false)
75
+ #
76
+ # ask("Where should the file be saved?", :path => true)
77
+ #
78
+ def ask(statement, *args)
79
+ options = args.last.is_a?(Hash) ? args.pop : {}
80
+ color = args.first
81
+
82
+ if options[:limited_to]
83
+ ask_filtered(statement, color, options)
84
+ else
85
+ ask_simply(statement, color, options)
86
+ end
87
+ end
88
+
89
+ # Say (print) something to the user. If the sentence ends with a whitespace
90
+ # or tab character, a new line is not appended (print + flush). Otherwise
91
+ # are passed straight to puts (behavior got from Highline).
92
+ #
93
+ # ==== Example
94
+ # say("I know you knew that.")
95
+ #
96
+ def say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/))
97
+ buffer = prepare_message(message, *color)
98
+ buffer << "\n" if force_new_line && !message.to_s.end_with?("\n")
99
+
100
+ stdout.print(buffer)
101
+ stdout.flush
102
+ end
103
+
104
+ # Say a status with the given color and appends the message. Since this
105
+ # method is used frequently by actions, it allows nil or false to be given
106
+ # in log_status, avoiding the message from being shown. If a Symbol is
107
+ # given in log_status, it's used as the color.
108
+ #
109
+ def say_status(status, message, log_status = true)
110
+ return if quiet? || log_status == false
111
+ spaces = " " * (padding + 1)
112
+ color = log_status.is_a?(Symbol) ? log_status : :green
113
+
114
+ status = status.to_s.rjust(12)
115
+ status = set_color status, color, true if color
116
+
117
+ buffer = "#{status}#{spaces}#{message}"
118
+ buffer = "#{buffer}\n" unless buffer.end_with?("\n")
119
+
120
+ stdout.print(buffer)
121
+ stdout.flush
122
+ end
123
+
124
+ # Make a question the to user and returns true if the user replies "y" or
125
+ # "yes".
126
+ #
127
+ def yes?(statement, color = nil)
128
+ !!(ask(statement, color, :add_to_history => false) =~ is?(:yes))
129
+ end
130
+
131
+ # Make a question the to user and returns true if the user replies "n" or
132
+ # "no".
133
+ #
134
+ def no?(statement, color = nil)
135
+ !!(ask(statement, color, :add_to_history => false) =~ is?(:no))
136
+ end
137
+
138
+ # Prints values in columns
139
+ #
140
+ # ==== Parameters
141
+ # Array[String, String, ...]
142
+ #
143
+ def print_in_columns(array)
144
+ return if array.empty?
145
+ colwidth = (array.map { |el| el.to_s.size }.max || 0) + 2
146
+ array.each_with_index do |value, index|
147
+ # Don't output trailing spaces when printing the last column
148
+ if ((((index + 1) % (terminal_width / colwidth))).zero? && !index.zero?) || index + 1 == array.length
149
+ stdout.puts value
150
+ else
151
+ stdout.printf("%-#{colwidth}s", value)
152
+ end
153
+ end
154
+ end
155
+
156
+ # Prints a table.
157
+ #
158
+ # ==== Parameters
159
+ # Array[Array[String, String, ...]]
160
+ #
161
+ # ==== Options
162
+ # indent<Integer>:: Indent the first column by indent value.
163
+ # colwidth<Integer>:: Force the first column to colwidth spaces wide.
164
+ #
165
+ def print_table(array, options = {}) # rubocop:disable MethodLength
166
+ return if array.empty?
167
+
168
+ formats = []
169
+ indent = options[:indent].to_i
170
+ colwidth = options[:colwidth]
171
+ options[:truncate] = terminal_width if options[:truncate] == true
172
+
173
+ formats << "%-#{colwidth + 2}s".dup if colwidth
174
+ start = colwidth ? 1 : 0
175
+
176
+ colcount = array.max { |a, b| a.size <=> b.size }.size
177
+
178
+ maximas = []
179
+
180
+ start.upto(colcount - 1) do |index|
181
+ maxima = array.map { |row| row[index] ? row[index].to_s.size : 0 }.max
182
+ maximas << maxima
183
+ formats << if index == colcount - 1
184
+ # Don't output 2 trailing spaces when printing the last column
185
+ "%-s".dup
186
+ else
187
+ "%-#{maxima + 2}s".dup
188
+ end
189
+ end
190
+
191
+ formats[0] = formats[0].insert(0, " " * indent)
192
+ formats << "%s"
193
+
194
+ array.each do |row|
195
+ sentence = "".dup
196
+
197
+ row.each_with_index do |column, index|
198
+ maxima = maximas[index]
199
+
200
+ f = if column.is_a?(Numeric)
201
+ if index == row.size - 1
202
+ # Don't output 2 trailing spaces when printing the last column
203
+ "%#{maxima}s"
204
+ else
205
+ "%#{maxima}s "
206
+ end
207
+ else
208
+ formats[index]
209
+ end
210
+ sentence << f % column.to_s
211
+ end
212
+
213
+ sentence = truncate(sentence, options[:truncate]) if options[:truncate]
214
+ stdout.puts sentence
215
+ end
216
+ end
217
+
218
+ # Prints a long string, word-wrapping the text to the current width of the
219
+ # terminal display. Ideal for printing heredocs.
220
+ #
221
+ # ==== Parameters
222
+ # String
223
+ #
224
+ # ==== Options
225
+ # indent<Integer>:: Indent each line of the printed paragraph by indent value.
226
+ #
227
+ def print_wrapped(message, options = {})
228
+ indent = options[:indent] || 0
229
+ width = terminal_width - indent
230
+ paras = message.split("\n\n")
231
+
232
+ paras.map! do |unwrapped|
233
+ counter = 0
234
+ unwrapped.split(" ").inject do |memo, word|
235
+ word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n")
236
+ counter = 0 if word.include? "\n"
237
+ if (counter + word.length + 1) < width
238
+ memo = "#{memo} #{word}"
239
+ counter += (word.length + 1)
240
+ else
241
+ memo = "#{memo}\n#{word}"
242
+ counter = word.length
243
+ end
244
+ memo
245
+ end
246
+ end.compact!
247
+
248
+ paras.each do |para|
249
+ para.split("\n").each do |line|
250
+ stdout.puts line.insert(0, " " * indent)
251
+ end
252
+ stdout.puts unless para == paras.last
253
+ end
254
+ end
255
+
256
+ # Deals with file collision and returns true if the file should be
257
+ # overwritten and false otherwise. If a block is given, it uses the block
258
+ # response as the content for the diff.
259
+ #
260
+ # ==== Parameters
261
+ # destination<String>:: the destination file to solve conflicts
262
+ # block<Proc>:: an optional block that returns the value to be used in diff and merge
263
+ #
264
+ def file_collision(destination)
265
+ return true if @always_force
266
+ options = block_given? ? "[Ynaqdhm]" : "[Ynaqh]"
267
+
268
+ loop do
269
+ answer = ask(
270
+ %[Overwrite #{destination}? (enter "h" for help) #{options}],
271
+ :add_to_history => false
272
+ )
273
+
274
+ case answer
275
+ when nil
276
+ say ""
277
+ return true
278
+ when is?(:yes), is?(:force), ""
279
+ return true
280
+ when is?(:no), is?(:skip)
281
+ return false
282
+ when is?(:always)
283
+ return @always_force = true
284
+ when is?(:quit)
285
+ say "Aborting..."
286
+ raise SystemExit
287
+ when is?(:diff)
288
+ show_diff(destination, yield) if block_given?
289
+ say "Retrying..."
290
+ when is?(:merge)
291
+ if block_given? && !merge_tool.empty?
292
+ merge(destination, yield)
293
+ return nil
294
+ end
295
+
296
+ say "Please specify merge tool to `THOR_MERGE` env."
297
+ else
298
+ say file_collision_help
299
+ end
300
+ end
301
+ end
302
+
303
+ # This code was copied from Rake, available under MIT-LICENSE
304
+ # Copyright (c) 2003, 2004 Jim Weirich
305
+ def terminal_width
306
+ result = if ENV["THOR_COLUMNS"]
307
+ ENV["THOR_COLUMNS"].to_i
308
+ else
309
+ unix? ? dynamic_width : DEFAULT_TERMINAL_WIDTH
310
+ end
311
+ result < 10 ? DEFAULT_TERMINAL_WIDTH : result
312
+ rescue
313
+ DEFAULT_TERMINAL_WIDTH
314
+ end
315
+
316
+ # Called if something goes wrong during the execution. This is used by Thor
317
+ # internally and should not be used inside your scripts. If something went
318
+ # wrong, you can always raise an exception. If you raise a Thor::Error, it
319
+ # will be rescued and wrapped in the method below.
320
+ #
321
+ def error(statement)
322
+ stderr.puts statement
323
+ end
324
+
325
+ # Apply color to the given string with optional bold. Disabled in the
326
+ # Thor::Shell::Basic class.
327
+ #
328
+ def set_color(string, *) #:nodoc:
329
+ string
330
+ end
331
+
332
+ protected
333
+
334
+ def prepare_message(message, *color)
335
+ spaces = " " * padding
336
+ spaces + set_color(message.to_s, *color)
337
+ end
338
+
339
+ def can_display_colors?
340
+ false
341
+ end
342
+
343
+ def lookup_color(color)
344
+ return color unless color.is_a?(Symbol)
345
+ self.class.const_get(color.to_s.upcase)
346
+ end
347
+
348
+ def stdout
349
+ $stdout
350
+ end
351
+
352
+ def stderr
353
+ $stderr
354
+ end
355
+
356
+ def is?(value) #:nodoc:
357
+ value = value.to_s
358
+
359
+ if value.size == 1
360
+ /\A#{value}\z/i
361
+ else
362
+ /\A(#{value}|#{value[0, 1]})\z/i
363
+ end
364
+ end
365
+
366
+ def file_collision_help #:nodoc:
367
+ <<-HELP
368
+ Y - yes, overwrite
369
+ n - no, do not overwrite
370
+ a - all, overwrite this and all others
371
+ q - quit, abort
372
+ d - diff, show the differences between the old and the new
373
+ h - help, show this help
374
+ m - merge, run merge tool
375
+ HELP
376
+ end
377
+
378
+ def show_diff(destination, content) #:nodoc:
379
+ diff_cmd = ENV["THOR_DIFF"] || ENV["RAILS_DIFF"] || "diff -u"
380
+
381
+ require "tempfile"
382
+ Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp|
383
+ temp.write content
384
+ temp.rewind
385
+ system %(#{diff_cmd} "#{destination}" "#{temp.path}")
386
+ end
387
+ end
388
+
389
+ def quiet? #:nodoc:
390
+ mute? || (base && base.options[:quiet])
391
+ end
392
+
393
+ # Calculate the dynamic width of the terminal
394
+ def dynamic_width
395
+ @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
396
+ end
397
+
398
+ def dynamic_width_stty
399
+ `stty size 2>/dev/null`.split[1].to_i
400
+ end
401
+
402
+ def dynamic_width_tput
403
+ `tput cols 2>/dev/null`.to_i
404
+ end
405
+
406
+ def unix?
407
+ RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
408
+ end
409
+
410
+ def truncate(string, width)
411
+ as_unicode do
412
+ chars = string.chars.to_a
413
+ if chars.length <= width
414
+ chars.join
415
+ else
416
+ chars[0, width - 3].join + "..."
417
+ end
418
+ end
419
+ end
420
+
421
+ if "".respond_to?(:encode)
422
+ def as_unicode
423
+ yield
424
+ end
425
+ else
426
+ def as_unicode
427
+ old = $KCODE
428
+ $KCODE = "U"
429
+ yield
430
+ ensure
431
+ $KCODE = old
432
+ end
433
+ end
434
+
435
+ def ask_simply(statement, color, options)
436
+ default = options[:default]
437
+ message = [statement, ("(#{default})" if default), nil].uniq.join(" ")
438
+ message = prepare_message(message, *color)
439
+ result = Thor::LineEditor.readline(message, options)
440
+
441
+ return unless result
442
+
443
+ result = result.strip
444
+
445
+ if default && result == ""
446
+ default
447
+ else
448
+ result
449
+ end
450
+ end
451
+
452
+ def ask_filtered(statement, color, options)
453
+ answer_set = options[:limited_to]
454
+ correct_answer = nil
455
+ until correct_answer
456
+ answers = answer_set.join(", ")
457
+ answer = ask_simply("#{statement} [#{answers}]", color, options)
458
+ correct_answer = answer_set.include?(answer) ? answer : nil
459
+ say("Your response must be one of: [#{answers}]. Please try again.") unless correct_answer
460
+ end
461
+ correct_answer
462
+ end
463
+
464
+ def merge(destination, content) #:nodoc:
465
+ require "tempfile"
466
+ Tempfile.open([File.basename(destination), File.extname(destination)], File.dirname(destination)) do |temp|
467
+ temp.write content
468
+ temp.rewind
469
+ system %(#{merge_tool} "#{temp.path}" "#{destination}")
470
+ end
471
+ end
472
+
473
+ def merge_tool #:nodoc:
474
+ @merge_tool ||= ENV["THOR_MERGE"] || git_merge_tool
475
+ end
476
+
477
+ def git_merge_tool #:nodoc:
478
+ `git config merge.tool`.rstrip rescue ""
479
+ end
480
+ end
481
+ end
482
+ end
@@ -0,0 +1,149 @@
1
+ require "thor/shell/basic"
2
+
3
+ class Thor
4
+ module Shell
5
+ # Inherit from Thor::Shell::Basic and add set_color behavior. Check
6
+ # Thor::Shell::Basic to see all available methods.
7
+ #
8
+ class Color < Basic
9
+ # Embed in a String to clear all previous ANSI sequences.
10
+ CLEAR = "\e[0m"
11
+ # The start of an ANSI bold sequence.
12
+ BOLD = "\e[1m"
13
+
14
+ # Set the terminal's foreground ANSI color to black.
15
+ BLACK = "\e[30m"
16
+ # Set the terminal's foreground ANSI color to red.
17
+ RED = "\e[31m"
18
+ # Set the terminal's foreground ANSI color to green.
19
+ GREEN = "\e[32m"
20
+ # Set the terminal's foreground ANSI color to yellow.
21
+ YELLOW = "\e[33m"
22
+ # Set the terminal's foreground ANSI color to blue.
23
+ BLUE = "\e[34m"
24
+ # Set the terminal's foreground ANSI color to magenta.
25
+ MAGENTA = "\e[35m"
26
+ # Set the terminal's foreground ANSI color to cyan.
27
+ CYAN = "\e[36m"
28
+ # Set the terminal's foreground ANSI color to white.
29
+ WHITE = "\e[37m"
30
+
31
+ # Set the terminal's background ANSI color to black.
32
+ ON_BLACK = "\e[40m"
33
+ # Set the terminal's background ANSI color to red.
34
+ ON_RED = "\e[41m"
35
+ # Set the terminal's background ANSI color to green.
36
+ ON_GREEN = "\e[42m"
37
+ # Set the terminal's background ANSI color to yellow.
38
+ ON_YELLOW = "\e[43m"
39
+ # Set the terminal's background ANSI color to blue.
40
+ ON_BLUE = "\e[44m"
41
+ # Set the terminal's background ANSI color to magenta.
42
+ ON_MAGENTA = "\e[45m"
43
+ # Set the terminal's background ANSI color to cyan.
44
+ ON_CYAN = "\e[46m"
45
+ # Set the terminal's background ANSI color to white.
46
+ ON_WHITE = "\e[47m"
47
+
48
+ # Set color by using a string or one of the defined constants. If a third
49
+ # option is set to true, it also adds bold to the string. This is based
50
+ # on Highline implementation and it automatically appends CLEAR to the end
51
+ # of the returned String.
52
+ #
53
+ # Pass foreground, background and bold options to this method as
54
+ # symbols.
55
+ #
56
+ # Example:
57
+ #
58
+ # set_color "Hi!", :red, :on_white, :bold
59
+ #
60
+ # The available colors are:
61
+ #
62
+ # :bold
63
+ # :black
64
+ # :red
65
+ # :green
66
+ # :yellow
67
+ # :blue
68
+ # :magenta
69
+ # :cyan
70
+ # :white
71
+ # :on_black
72
+ # :on_red
73
+ # :on_green
74
+ # :on_yellow
75
+ # :on_blue
76
+ # :on_magenta
77
+ # :on_cyan
78
+ # :on_white
79
+ def set_color(string, *colors)
80
+ if colors.compact.empty? || !can_display_colors?
81
+ string
82
+ elsif colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) }
83
+ ansi_colors = colors.map { |color| lookup_color(color) }
84
+ "#{ansi_colors.join}#{string}#{CLEAR}"
85
+ else
86
+ # The old API was `set_color(color, bold=boolean)`. We
87
+ # continue to support the old API because you should never
88
+ # break old APIs unnecessarily :P
89
+ foreground, bold = colors
90
+ foreground = self.class.const_get(foreground.to_s.upcase) if foreground.is_a?(Symbol)
91
+
92
+ bold = bold ? BOLD : ""
93
+ "#{bold}#{foreground}#{string}#{CLEAR}"
94
+ end
95
+ end
96
+
97
+ protected
98
+
99
+ def can_display_colors?
100
+ stdout.tty?
101
+ end
102
+
103
+ # Overwrite show_diff to show diff with colors if Diff::LCS is
104
+ # available.
105
+ #
106
+ def show_diff(destination, content) #:nodoc:
107
+ if diff_lcs_loaded? && ENV["THOR_DIFF"].nil? && ENV["RAILS_DIFF"].nil?
108
+ actual = File.binread(destination).to_s.split("\n")
109
+ content = content.to_s.split("\n")
110
+
111
+ Diff::LCS.sdiff(actual, content).each do |diff|
112
+ output_diff_line(diff)
113
+ end
114
+ else
115
+ super
116
+ end
117
+ end
118
+
119
+ def output_diff_line(diff) #:nodoc:
120
+ case diff.action
121
+ when "-"
122
+ say "- #{diff.old_element.chomp}", :red, true
123
+ when "+"
124
+ say "+ #{diff.new_element.chomp}", :green, true
125
+ when "!"
126
+ say "- #{diff.old_element.chomp}", :red, true
127
+ say "+ #{diff.new_element.chomp}", :green, true
128
+ else
129
+ say " #{diff.old_element.chomp}", nil, true
130
+ end
131
+ end
132
+
133
+ # Check if Diff::LCS is loaded. If it is, use it to create pretty output
134
+ # for diff.
135
+ #
136
+ def diff_lcs_loaded? #:nodoc:
137
+ return true if defined?(Diff::LCS)
138
+ return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
139
+
140
+ @diff_lcs_loaded = begin
141
+ require "diff/lcs"
142
+ true
143
+ rescue LoadError
144
+ false
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end