colorcode_convert_rgb 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 (158) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +23 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +40 -0
  6. data/Rakefile +10 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/colorcode_convert_rgb.gemspec +30 -0
  10. data/exe/colorcode_convert_rgb +4 -0
  11. data/lib/colorcode_convert_rgb.rb +7 -0
  12. data/lib/colorcode_convert_rgb/cli.rb +13 -0
  13. data/lib/colorcode_convert_rgb/version.rb +3 -0
  14. data/vendor/bundle/ruby/2.5.0/bin/colorcode_convert_rgb +27 -0
  15. data/vendor/bundle/ruby/2.5.0/bin/rake +27 -0
  16. data/vendor/bundle/ruby/2.5.0/bin/thor +27 -0
  17. data/vendor/bundle/ruby/2.5.0/cache/minitest-5.14.2.gem +0 -0
  18. data/vendor/bundle/ruby/2.5.0/cache/rake-12.3.3.gem +0 -0
  19. data/vendor/bundle/ruby/2.5.0/cache/thor-1.0.1.gem +0 -0
  20. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/.autotest +34 -0
  21. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/History.rdoc +1397 -0
  22. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Manifest.txt +27 -0
  23. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/README.rdoc +764 -0
  24. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Rakefile +74 -0
  25. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/design_rationale.rb +52 -0
  26. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/hoe/minitest.rb +32 -0
  27. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest.rb +1056 -0
  28. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/assertions.rb +807 -0
  29. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/autorun.rb +13 -0
  30. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/benchmark.rb +455 -0
  31. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/expectations.rb +303 -0
  32. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/hell.rb +11 -0
  33. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/mock.rb +240 -0
  34. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/parallel.rb +70 -0
  35. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride.rb +4 -0
  36. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride_plugin.rb +142 -0
  37. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/spec.rb +342 -0
  38. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/test.rb +220 -0
  39. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/unit.rb +45 -0
  40. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/metametameta.rb +136 -0
  41. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_assertions.rb +1575 -0
  42. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_benchmark.rb +137 -0
  43. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_mock.rb +872 -0
  44. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_reporter.rb +299 -0
  45. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_spec.rb +1061 -0
  46. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_test.rb +1084 -0
  47. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/CONTRIBUTING.rdoc +43 -0
  48. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Gemfile +3 -0
  49. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/History.rdoc +2344 -0
  50. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/MIT-LICENSE +21 -0
  51. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/README.rdoc +156 -0
  52. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Rakefile +41 -0
  53. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/azure-pipelines.yml +11 -0
  54. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/bundle +105 -0
  55. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/console +7 -0
  56. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rake +29 -0
  57. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rdoc +29 -0
  58. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rubocop +29 -0
  59. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/setup +6 -0
  60. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/command_line_usage.rdoc +158 -0
  61. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile1 +38 -0
  62. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile2 +35 -0
  63. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/a.c +6 -0
  64. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/b.c +6 -0
  65. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/main.c +11 -0
  66. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/glossary.rdoc +42 -0
  67. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/jamis.rb +592 -0
  68. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/proto_rake.rdoc +127 -0
  69. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rake.1 +156 -0
  70. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rakefile.rdoc +622 -0
  71. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rational.rdoc +151 -0
  72. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/exe/rake +27 -0
  73. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake.rb +71 -0
  74. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb +824 -0
  75. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/backtrace.rb +24 -0
  76. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/clean.rb +78 -0
  77. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cloneable.rb +17 -0
  78. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cpu_counter.rb +107 -0
  79. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/default_loader.rb +15 -0
  80. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/dsl_definition.rb +195 -0
  81. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/early_time.rb +22 -0
  82. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/core.rb +26 -0
  83. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/string.rb +176 -0
  84. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_creation_task.rb +25 -0
  85. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_list.rb +435 -0
  86. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_task.rb +54 -0
  87. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils.rb +137 -0
  88. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils_ext.rb +145 -0
  89. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_chain.rb +57 -0
  90. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_exception_mixin.rb +17 -0
  91. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/late_time.rb +18 -0
  92. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/linked_list.rb +112 -0
  93. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/loaders/makefile.rb +54 -0
  94. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/multi_task.rb +14 -0
  95. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/name_space.rb +38 -0
  96. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/packagetask.rb +207 -0
  97. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/phony.rb +16 -0
  98. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/private_reader.rb +21 -0
  99. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/promise.rb +100 -0
  100. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/pseudo_status.rb +30 -0
  101. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_module.rb +67 -0
  102. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_test_loader.rb +27 -0
  103. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rule_recursion_overflow_error.rb +20 -0
  104. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/scope.rb +43 -0
  105. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task.rb +413 -0
  106. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_argument_error.rb +8 -0
  107. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_arguments.rb +109 -0
  108. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_manager.rb +324 -0
  109. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/tasklib.rb +12 -0
  110. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/testtask.rb +224 -0
  111. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_history_display.rb +49 -0
  112. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_pool.rb +163 -0
  113. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/trace_output.rb +23 -0
  114. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/version.rb +10 -0
  115. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/win32.rb +51 -0
  116. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/rake.gemspec +42 -0
  117. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/.document +5 -0
  118. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CHANGELOG.md +220 -0
  119. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CONTRIBUTING.md +15 -0
  120. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/LICENSE.md +20 -0
  121. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/README.md +51 -0
  122. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/bin/thor +6 -0
  123. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor.rb +517 -0
  124. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions.rb +336 -0
  125. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_file.rb +104 -0
  126. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_link.rb +61 -0
  127. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/directory.rb +108 -0
  128. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/empty_directory.rb +143 -0
  129. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/file_manipulation.rb +373 -0
  130. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/inject_into_file.rb +120 -0
  131. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/base.rb +699 -0
  132. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/command.rb +142 -0
  133. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/core_ext/hash_with_indifferent_access.rb +97 -0
  134. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/error.rb +110 -0
  135. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/group.rb +281 -0
  136. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/invocation.rb +178 -0
  137. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor.rb +17 -0
  138. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/basic.rb +37 -0
  139. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/readline.rb +88 -0
  140. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/nested_context.rb +29 -0
  141. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser.rb +4 -0
  142. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/argument.rb +70 -0
  143. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/arguments.rb +175 -0
  144. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/option.rb +159 -0
  145. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/options.rb +236 -0
  146. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/rake_compat.rb +72 -0
  147. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/runner.rb +325 -0
  148. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell.rb +81 -0
  149. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/basic.rb +491 -0
  150. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/color.rb +153 -0
  151. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/html.rb +126 -0
  152. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/util.rb +284 -0
  153. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/version.rb +3 -0
  154. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/thor.gemspec +28 -0
  155. data/vendor/bundle/ruby/2.5.0/specifications/minitest-5.14.2.gemspec +38 -0
  156. data/vendor/bundle/ruby/2.5.0/specifications/rake-12.3.3.gemspec +43 -0
  157. data/vendor/bundle/ruby/2.5.0/specifications/thor-1.0.1.gemspec +34 -0
  158. metadata +214 -0
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Rake
3
+ VERSION = "12.3.3"
4
+
5
+ module Version # :nodoc: all
6
+ MAJOR, MINOR, BUILD, *OTHER = Rake::VERSION.split "."
7
+
8
+ NUMBERS = [MAJOR, MINOR, BUILD, *OTHER]
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ require "rbconfig"
3
+
4
+ module Rake
5
+ # Win 32 interface methods for Rake. Windows specific functionality
6
+ # will be placed here to collect that knowledge in one spot.
7
+ module Win32 # :nodoc: all
8
+
9
+ # Error indicating a problem in locating the home directory on a
10
+ # Win32 system.
11
+ class Win32HomeError < RuntimeError
12
+ end
13
+
14
+ class << self
15
+ # True if running on a windows system.
16
+ def windows?
17
+ RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw|[Ww]indows)!
18
+ end
19
+
20
+ # The standard directory containing system wide rake files on
21
+ # Win 32 systems. Try the following environment variables (in
22
+ # order):
23
+ #
24
+ # * HOME
25
+ # * HOMEDRIVE + HOMEPATH
26
+ # * APPDATA
27
+ # * USERPROFILE
28
+ #
29
+ # If the above are not defined, the return nil.
30
+ def win32_system_dir #:nodoc:
31
+ win32_shared_path = ENV["HOME"]
32
+ if win32_shared_path.nil? && ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
33
+ win32_shared_path = ENV["HOMEDRIVE"] + ENV["HOMEPATH"]
34
+ end
35
+
36
+ win32_shared_path ||= ENV["APPDATA"]
37
+ win32_shared_path ||= ENV["USERPROFILE"]
38
+ raise Win32HomeError,
39
+ "Unable to determine home path environment variable." if
40
+ win32_shared_path.nil? or win32_shared_path.empty?
41
+ normalize(File.join(win32_shared_path, "Rake"))
42
+ end
43
+
44
+ # Normalize a win32 path so that the slashes are all forward slashes.
45
+ def normalize(path)
46
+ path.gsub(/\\/, "/")
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
+ require 'rake/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rake".freeze
7
+ s.version = Rake::VERSION
8
+ s.authors = ["Hiroshi SHIBATA".freeze, "Eric Hodel".freeze, "Jim Weirich".freeze]
9
+ s.email = ["hsbt@ruby-lang.org".freeze, "drbrain@segment7.net".freeze, "".freeze]
10
+
11
+ s.summary = "Rake is a Make-like program implemented in Ruby".freeze
12
+ s.description = <<-DESCRIPTION
13
+ Rake is a Make-like program implemented in Ruby. Tasks and dependencies are
14
+ specified in standard Ruby syntax.
15
+ Rake has the following features:
16
+ * Rakefiles (rake's version of Makefiles) are completely defined in standard Ruby syntax.
17
+ No XML files to edit. No quirky Makefile syntax to worry about (is that a tab or a space?)
18
+ * Users can specify tasks with prerequisites.
19
+ * Rake supports rule patterns to synthesize implicit tasks.
20
+ * Flexible FileLists that act like arrays but know about manipulating file names and paths.
21
+ * Supports parallel execution of tasks.
22
+ DESCRIPTION
23
+ s.homepage = "https://github.com/ruby/rake".freeze
24
+ s.licenses = ["MIT".freeze]
25
+
26
+ s.files = %x[git ls-files -z].split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } -
27
+ %w[.rubocop.yml .gitignore .travis.yml appveyor.yml]
28
+ s.bindir = "exe"
29
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ s.require_paths = ["lib".freeze]
31
+
32
+ s.required_ruby_version = Gem::Requirement.new(">= 2.0.0".freeze)
33
+ s.rubygems_version = "2.6.1".freeze
34
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.2".freeze)
35
+ s.rdoc_options = ["--main".freeze, "README.rdoc".freeze]
36
+
37
+ s.add_development_dependency(%q<bundler>.freeze)
38
+ s.add_development_dependency(%q<minitest>.freeze)
39
+ s.add_development_dependency(%q<rdoc>.freeze)
40
+ s.add_development_dependency(%q<coveralls>.freeze)
41
+ s.add_development_dependency(%q<rubocop>.freeze)
42
+ end
@@ -0,0 +1,5 @@
1
+ lib/*.rb
2
+ lib/**/*.rb
3
+ -
4
+ CHANGELOG.rdoc
5
+ LICENSE.md
@@ -0,0 +1,220 @@
1
+ # 1.0.1
2
+ * Fix thor when `thor/base` and `thor/group` are required without `thor.rb`.
3
+ * Handle relative source path in `create_link`.
4
+
5
+ # 1.0.0
6
+ * Drop support to Ruby 1.8 and 1.9.
7
+ * Deprecate relying on default `exit_on_failure?`.
8
+ In preparation to make Thor commands exit when there is a failure we are deprecating
9
+ defining a command without defining what behavior is expected when there is a failure.
10
+
11
+ To fix the deprecation you need to define a class method called `exit_on_failure?` returning
12
+
13
+ `false` if you want the current behavior or `true` if you want the new behavior.
14
+ * Deprecate defining an option with the default value using a different type as defined in the option.
15
+ * Allow options to be repeatable. See #674.
16
+
17
+ # 0.20.3
18
+ * Support old versions of `did_you_mean`.
19
+
20
+ # 0.20.2
21
+ * Fix `did_you_mean` support.
22
+
23
+ # 0.20.1
24
+ * Support new versions of ERB.
25
+ * Fix `check_unknown_options!` to not check the content that was not parsed, i.e. after a `--` or after the first unknown with `stop_on_unknown_option!`
26
+ * Add `did_you_mean` support.
27
+
28
+ ## 0.20.0
29
+ * Add `check_default_type!` to check if the default value of an option matches the defined type.
30
+ It removes the warning on usage and gives the command authors the possibility to check for programming errors.
31
+
32
+ * Add `disable_required_check!` to disable check for required options in some commands.
33
+ It is a substitute of `disable_class_options` that was not working as intended.
34
+
35
+ * Add `inject_into_module`.
36
+
37
+ ## 0.19.4, release 2016-11-28
38
+ * Rename `Thor::Base#thor_reserved_word?` to `#is_thor_reserved_word?`
39
+
40
+ ## 0.19.3, release 2016-11-27
41
+ * Output a warning instead of raising an exception when a default option value doesn't match its specified type
42
+
43
+ ## 0.19.2, release 2016-11-26
44
+ * Fix bug with handling of colors passed to `ask` (and methods like `yes?` and `no?` which it underpins)
45
+ * Allow numeric arguments to be negative
46
+ * Ensure that default option values are of the specified type (e.g. you can't specify `"foo"` as the default for a numeric option), but make symbols and strings interchangeable
47
+ * Add `Thor::Shell::Basic#indent` method for intending output
48
+ * Fix `remove_command` for an inherited command (see #451)
49
+ * Allow hash arguments to only have each key provided once (see #455)
50
+ * Allow commands to disable class options, for instance for "help" commands (see #363)
51
+ * Do not generate a negative option (`--no-no-foo`) for already negative boolean options (`--no-foo`)
52
+ * Improve compatibility of `Thor::CoreExt::HashWithIndifferentAccess` with Ruby standard library `Hash`
53
+ * Allow specifying a custom binding for template evaluation (e.g. `#key?` and `#fetch`)
54
+ * Fix support for subcommand-specific "help"s
55
+ * Use a string buffer when handling ERB for Ruby 2.3 compatibility
56
+ * Update dependencies
57
+
58
+ ## 0.19.1, release 2014-03-24
59
+ * Fix `say` non-String break regression
60
+
61
+ ## 0.19.0, release 2014-03-22
62
+ * Add support for a default to #ask
63
+ * Avoid @namespace not initialized warning
64
+ * Avoid private attribute? warning
65
+ * Fix initializing with unknown options
66
+ * Loosen required_rubygems_version for compatibility with Ubuntu 10.04
67
+ * Shell#ask: support a noecho option for stdin
68
+ * Shell#ask: change API to be :echo => false
69
+ * Display a message without a stack trace for ambiguous commands
70
+ * Make say and say_status thread safe
71
+ * Dependency for console io version check
72
+ * Alias --help to help on subcommands
73
+ * Use mime-types 1.x for Ruby 1.8.7 compatibility for Ruby 1.8 only
74
+ * Accept .tt files as templates
75
+ * Check if numeric value is in enum
76
+ * Use Readline for user input
77
+ * Fix dispatching of subcommands (concerning :help and *args)
78
+ * Fix warnings when running specs with `$VERBOSE = true`
79
+ * Make subcommand help more consistent
80
+ * Make the current command chain accessible in command
81
+
82
+ ## 0.18.1, release 2013-03-30
83
+ * Revert regressions found in 0.18.0
84
+
85
+ ## 0.18.0, release 2013-03-26
86
+ * Remove rake2thor
87
+ * Only display colors if output medium supports colors
88
+ * Pass parent_options to subcommands
89
+ * Fix non-dash-prefixed aliases
90
+ * Make error messages more helpful
91
+ * Rename "task" to "command"
92
+ * Add the method to allow for custom package name
93
+
94
+ ## 0.17.0, release 2013-01-24
95
+ * Add better support for tasks that accept arbitrary additional arguments (e.g. things like `bundle exec`)
96
+ * Add #stop_on_unknown_option!
97
+ * Only strip from stdin.gets if it wasn't ended with EOF
98
+ * Allow "send" as a task name
99
+ * Allow passing options as arguments after "--"
100
+ * Autoload Thor::Group
101
+
102
+ ## 0.16.0, release 2012-08-14
103
+ * Add enum to string arguments
104
+
105
+ ## 0.15.4, release 2012-06-29
106
+ * Fix regression when destination root contains reserved regexp characters
107
+
108
+ ## 0.15.3, release 2012-06-18
109
+ * Support strict_args_position! for backwards compatibility
110
+ * Escape Dir glob characters in paths
111
+
112
+ ## 0.15.2, released 2012-05-07
113
+ * Added print_in_columns
114
+ * Exposed terminal_width as a public API
115
+
116
+ ## 0.15.1, release 2012-05-06
117
+ * Fix Ruby 1.8 truncation bug with unicode chars
118
+ * Fix shell delegate methods to pass their block
119
+ * Don't output trailing spaces when printing the last column in a table
120
+
121
+ ## 0.15, released 2012-04-29
122
+ * Alias method_options to options
123
+ * Refactor say to allow multiple colors
124
+ * Exposed error as a public API
125
+ * Exposed file_collision as a public API
126
+ * Exposed print_wrapped as a public API
127
+ * Exposed set_color as a public API
128
+ * Fix number-formatting bugs in print_table
129
+ * Fix "indent" typo in print_table
130
+ * Fix Errno::EPIPE when piping tasks to `head`
131
+ * More friendly error messages
132
+
133
+ ## 0.14, released 2010-07-25
134
+ * Added CreateLink class and #link_file method
135
+ * Made Thor::Actions#run use system as default method for system calls
136
+ * Allow use of private methods from superclass as tasks
137
+ * Added mute(&block) method which allows to run block without any output
138
+ * Removed config[:pretend]
139
+ * Enabled underscores for command line switches
140
+ * Added Thor::Base.basename which is used by both Thor.banner and Thor::Group.banner
141
+ * Deprecated invoke() without arguments
142
+ * Added :only and :except to check_unknown_options
143
+
144
+ ## 0.13, released 2010-02-03
145
+ * Added :lazy_default which is only triggered if a switch is given
146
+ * Added Thor::Shell::HTML
147
+ * Added subcommands
148
+ * Decoupled Thor::Group and Thor, so it's easier to vendor
149
+ * Added check_unknown_options! in case you want error messages to be raised in valid switches
150
+ * run(command) should return the results of command
151
+
152
+ ## 0.12, released 2010-01-02
153
+ * Methods generated by attr_* are automatically not marked as tasks
154
+ * inject_into_file does not add the same content twice, unless :force is set
155
+ * Removed rr in favor to rspec mock framework
156
+ * Improved output for thor -T
157
+ * [#7] Do not force white color on status
158
+ * [#8] Yield a block with the filename on directory
159
+
160
+ ## 0.11, released 2009-07-01
161
+ * Added a rake compatibility layer. It allows you to use spec and rdoc tasks on
162
+ Thor classes.
163
+ * BACKWARDS INCOMPATIBLE: aliases are not generated automatically anymore
164
+ since it may cause wrong behavior in the invocation system.
165
+ * thor help now show information about any class/task. All those calls are
166
+ possible:
167
+
168
+ thor help describe
169
+ thor help describe:amazing
170
+ Or even with default namespaces:
171
+
172
+ thor help :spec
173
+ * Thor::Runner now invokes the default task if none is supplied:
174
+
175
+ thor describe # invokes the default task, usually help
176
+ * Thor::Runner now works with mappings:
177
+
178
+ thor describe -h
179
+ * Added some documentation and code refactoring.
180
+
181
+ ## 0.9.8, released 2008-10-20
182
+ * Fixed some tiny issues that were introduced lately.
183
+
184
+ ## 0.9.7, released 2008-10-13
185
+ * Setting global method options on the initialize method works as expected:
186
+ All other tasks will accept these global options in addition to their own.
187
+ * Added 'group' notion to Thor task sets (class Thor); by default all tasks
188
+ are in the 'standard' group. Running 'thor -T' will only show the standard
189
+ tasks - adding --all will show all tasks. You can also filter on a specific
190
+ group using the --group option: thor -T --group advanced
191
+
192
+ ## 0.9.6, released 2008-09-13
193
+ * Generic improvements
194
+
195
+ ## 0.9.5, released 2008-08-27
196
+ * Improve Windows compatibility
197
+ * Update (incorrect) README and task.thor sample file
198
+ * Options hash is now frozen (once returned)
199
+ * Allow magic predicates on options object. For instance: `options.force?`
200
+ * Add support for :numeric type
201
+ * BACKWARDS INCOMPATIBLE: Refactor Thor::Options. You cannot access shorthand forms in options hash anymore (for instance, options[:f])
202
+ * Allow specifying optional args with default values: method_options(:user => "mislav")
203
+ * Don't write options for nil or false values. This allows, for example, turning color off when running specs.
204
+ * Exit with the status of the spec command to help CI stuff out some.
205
+
206
+ ## 0.9.4, released 2008-08-13
207
+ * Try to add Windows compatibility.
208
+ * BACKWARDS INCOMPATIBLE: options hash is now accessed as a property in your class and is not passed as last argument anymore
209
+ * Allow options at the beginning of the argument list as well as the end.
210
+ * Make options available with symbol keys in addition to string keys.
211
+ * Allow true to be passed to Thor#method_options to denote a boolean option.
212
+ * If loading a thor file fails, don't give up, just print a warning and keep going.
213
+ * Make sure that we re-raise errors if they happened further down the pipe than we care about.
214
+ * Only delete the old file on updating when the installation of the new one is a success
215
+ * Make it Ruby 1.8.5 compatible.
216
+ * Don't raise an error if a boolean switch is defined multiple times.
217
+ * Thor::Options now doesn't parse through things that look like options but aren't.
218
+ * Add URI detection to install task, and make sure we don't append ".thor" to URIs
219
+ * Add rake2thor to the gem binfiles.
220
+ * Make sure local Thorfiles override system-wide ones.
@@ -0,0 +1,15 @@
1
+ Pull Requests
2
+ -------------
3
+ Here are some reasons why a pull request may not be merged:
4
+
5
+ 1. It hasn’t been reviewed.
6
+ 2. It doesn’t include specs for new functionality.
7
+ 3. It doesn’t include documentation for new functionality.
8
+ 4. It changes behavior without changing the relevant documentation, comments, or specs.
9
+ 5. It changes behavior of an existing public API, breaking backward compatibility.
10
+ 6. It breaks the tests on a supported platform.
11
+ 7. It doesn’t merge cleanly (requiring Git rebasing and conflict resolution).
12
+
13
+ If you would like to help in this process, you can start by evaluating open pull requests against the criteria above. For example, if a pull request does not include specs for new functionality, you can add a comment like: “If you would like this feature to be added to Thor, please add specs to ensure that it does not break in the future.” This will help move a pull request closer to being merged.
14
+
15
+ Include this emoji in the top of your ticket to signal to us that you read this file: 🌈
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ Thor
2
+ ====
3
+
4
+ [![Gem Version](http://img.shields.io/gem/v/thor.svg)][gem]
5
+ [![Build Status](http://img.shields.io/travis/erikhuda/thor.svg)][travis]
6
+ [![Code Climate](http://img.shields.io/codeclimate/github/erikhuda/thor.svg)][codeclimate]
7
+ [![Coverage Status](http://img.shields.io/coveralls/erikhuda/thor.svg)][coveralls]
8
+
9
+ [gem]: https://rubygems.org/gems/thor
10
+ [travis]: http://travis-ci.org/erikhuda/thor
11
+ [codeclimate]: https://codeclimate.com/github/erikhuda/thor
12
+ [coveralls]: https://coveralls.io/r/erikhuda/thor
13
+
14
+ Description
15
+ -----------
16
+ Thor is a simple and efficient tool for building self-documenting command line
17
+ utilities. It removes the pain of parsing command line options, writing
18
+ "USAGE:" banners, and can also be used as an alternative to the [Rake][rake]
19
+ build tool. The syntax is Rake-like, so it should be familiar to most Rake
20
+ users.
21
+
22
+ Please note: Thor, by design, is a system tool created to allow seamless file and url
23
+ access, which should not receive application user input. It relies on [open-uri][open-uri],
24
+ which combined with application user input would provide a command injection attack
25
+ vector.
26
+
27
+ [rake]: https://github.com/ruby/rake
28
+ [open-uri]: https://ruby-doc.org/stdlib-2.5.1/libdoc/open-uri/rdoc/index.html
29
+
30
+ Installation
31
+ ------------
32
+ gem install thor
33
+
34
+ Usage and documentation
35
+ -----------------------
36
+ Please see the [wiki][] for basic usage and other documentation on using Thor. You can also checkout the [official homepage][homepage].
37
+
38
+ [wiki]: https://github.com/erikhuda/thor/wiki
39
+ [homepage]: http://whatisthor.com/
40
+
41
+ Contributing
42
+ ------------
43
+ If you would like to help, please read the [CONTRIBUTING][] file for suggestions.
44
+
45
+ [contributing]: CONTRIBUTING.md
46
+
47
+ License
48
+ -------
49
+ Released under the MIT License. See the [LICENSE][] file for further details.
50
+
51
+ [license]: LICENSE.md
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require "thor/runner"
5
+ $thor_runner = true
6
+ Thor::Runner.start
@@ -0,0 +1,517 @@
1
+ require "set"
2
+ require_relative "thor/base"
3
+
4
+ class Thor
5
+ class << self
6
+ # Allows for custom "Command" package naming.
7
+ #
8
+ # === Parameters
9
+ # name<String>
10
+ # options<Hash>
11
+ #
12
+ def package_name(name, _ = {})
13
+ @package_name = name.nil? || name == "" ? nil : name
14
+ end
15
+
16
+ # Sets the default command when thor is executed without an explicit command to be called.
17
+ #
18
+ # ==== Parameters
19
+ # meth<Symbol>:: name of the default command
20
+ #
21
+ def default_command(meth = nil)
22
+ if meth
23
+ @default_command = meth == :none ? "help" : meth.to_s
24
+ else
25
+ @default_command ||= from_superclass(:default_command, "help")
26
+ end
27
+ end
28
+ alias_method :default_task, :default_command
29
+
30
+ # Registers another Thor subclass as a command.
31
+ #
32
+ # ==== Parameters
33
+ # klass<Class>:: Thor subclass to register
34
+ # command<String>:: Subcommand name to use
35
+ # usage<String>:: Short usage for the subcommand
36
+ # description<String>:: Description for the subcommand
37
+ def register(klass, subcommand_name, usage, description, options = {})
38
+ if klass <= Thor::Group
39
+ desc usage, description, options
40
+ define_method(subcommand_name) { |*args| invoke(klass, args) }
41
+ else
42
+ desc usage, description, options
43
+ subcommand subcommand_name, klass
44
+ end
45
+ end
46
+
47
+ # Defines the usage and the description of the next command.
48
+ #
49
+ # ==== Parameters
50
+ # usage<String>
51
+ # description<String>
52
+ # options<String>
53
+ #
54
+ def desc(usage, description, options = {})
55
+ if options[:for]
56
+ command = find_and_refresh_command(options[:for])
57
+ command.usage = usage if usage
58
+ command.description = description if description
59
+ else
60
+ @usage = usage
61
+ @desc = description
62
+ @hide = options[:hide] || false
63
+ end
64
+ end
65
+
66
+ # Defines the long description of the next command.
67
+ #
68
+ # ==== Parameters
69
+ # long description<String>
70
+ #
71
+ def long_desc(long_description, options = {})
72
+ if options[:for]
73
+ command = find_and_refresh_command(options[:for])
74
+ command.long_description = long_description if long_description
75
+ else
76
+ @long_desc = long_description
77
+ end
78
+ end
79
+
80
+ # Maps an input to a command. If you define:
81
+ #
82
+ # map "-T" => "list"
83
+ #
84
+ # Running:
85
+ #
86
+ # thor -T
87
+ #
88
+ # Will invoke the list command.
89
+ #
90
+ # ==== Parameters
91
+ # Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given command.
92
+ #
93
+ def map(mappings = nil, **kw)
94
+ @map ||= from_superclass(:map, {})
95
+
96
+ if mappings && !kw.empty?
97
+ mappings = kw.merge!(mappings)
98
+ else
99
+ mappings ||= kw
100
+ end
101
+ if mappings
102
+ mappings.each do |key, value|
103
+ if key.respond_to?(:each)
104
+ key.each { |subkey| @map[subkey] = value }
105
+ else
106
+ @map[key] = value
107
+ end
108
+ end
109
+ end
110
+
111
+ @map
112
+ end
113
+
114
+ # Declares the options for the next command to be declared.
115
+ #
116
+ # ==== Parameters
117
+ # Hash[Symbol => Object]:: The hash key is the name of the option and the value
118
+ # is the type of the option. Can be :string, :array, :hash, :boolean, :numeric
119
+ # or :required (string). If you give a value, the type of the value is used.
120
+ #
121
+ def method_options(options = nil)
122
+ @method_options ||= {}
123
+ build_options(options, @method_options) if options
124
+ @method_options
125
+ end
126
+
127
+ alias_method :options, :method_options
128
+
129
+ # Adds an option to the set of method options. If :for is given as option,
130
+ # it allows you to change the options from a previous defined command.
131
+ #
132
+ # def previous_command
133
+ # # magic
134
+ # end
135
+ #
136
+ # method_option :foo => :bar, :for => :previous_command
137
+ #
138
+ # def next_command
139
+ # # magic
140
+ # end
141
+ #
142
+ # ==== Parameters
143
+ # name<Symbol>:: The name of the argument.
144
+ # options<Hash>:: Described below.
145
+ #
146
+ # ==== Options
147
+ # :desc - Description for the argument.
148
+ # :required - If the argument is required or not.
149
+ # :default - Default value for this argument. It cannot be required and have default values.
150
+ # :aliases - Aliases for this option.
151
+ # :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
152
+ # :banner - String to show on usage notes.
153
+ # :hide - If you want to hide this option from the help.
154
+ #
155
+ def method_option(name, options = {})
156
+ scope = if options[:for]
157
+ find_and_refresh_command(options[:for]).options
158
+ else
159
+ method_options
160
+ end
161
+
162
+ build_option(name, options, scope)
163
+ end
164
+ alias_method :option, :method_option
165
+
166
+ # Prints help information for the given command.
167
+ #
168
+ # ==== Parameters
169
+ # shell<Thor::Shell>
170
+ # command_name<String>
171
+ #
172
+ def command_help(shell, command_name)
173
+ meth = normalize_command_name(command_name)
174
+ command = all_commands[meth]
175
+ handle_no_command_error(meth) unless command
176
+
177
+ shell.say "Usage:"
178
+ shell.say " #{banner(command).split("\n").join("\n ")}"
179
+ shell.say
180
+ class_options_help(shell, nil => command.options.values)
181
+ if command.long_description
182
+ shell.say "Description:"
183
+ shell.print_wrapped(command.long_description, :indent => 2)
184
+ else
185
+ shell.say command.description
186
+ end
187
+ end
188
+ alias_method :task_help, :command_help
189
+
190
+ # Prints help information for this class.
191
+ #
192
+ # ==== Parameters
193
+ # shell<Thor::Shell>
194
+ #
195
+ def help(shell, subcommand = false)
196
+ list = printable_commands(true, subcommand)
197
+ Thor::Util.thor_classes_in(self).each do |klass|
198
+ list += klass.printable_commands(false)
199
+ end
200
+ list.sort! { |a, b| a[0] <=> b[0] }
201
+
202
+ if defined?(@package_name) && @package_name
203
+ shell.say "#{@package_name} commands:"
204
+ else
205
+ shell.say "Commands:"
206
+ end
207
+
208
+ shell.print_table(list, :indent => 2, :truncate => true)
209
+ shell.say
210
+ class_options_help(shell)
211
+ end
212
+
213
+ # Returns commands ready to be printed.
214
+ def printable_commands(all = true, subcommand = false)
215
+ (all ? all_commands : commands).map do |_, command|
216
+ next if command.hidden?
217
+ item = []
218
+ item << banner(command, false, subcommand)
219
+ item << (command.description ? "# #{command.description.gsub(/\s+/m, ' ')}" : "")
220
+ item
221
+ end.compact
222
+ end
223
+ alias_method :printable_tasks, :printable_commands
224
+
225
+ def subcommands
226
+ @subcommands ||= from_superclass(:subcommands, [])
227
+ end
228
+ alias_method :subtasks, :subcommands
229
+
230
+ def subcommand_classes
231
+ @subcommand_classes ||= {}
232
+ end
233
+
234
+ def subcommand(subcommand, subcommand_class)
235
+ subcommands << subcommand.to_s
236
+ subcommand_class.subcommand_help subcommand
237
+ subcommand_classes[subcommand.to_s] = subcommand_class
238
+
239
+ define_method(subcommand) do |*args|
240
+ args, opts = Thor::Arguments.split(args)
241
+ invoke_args = [args, opts, {:invoked_via_subcommand => true, :class_options => options}]
242
+ invoke_args.unshift "help" if opts.delete("--help") || opts.delete("-h")
243
+ invoke subcommand_class, *invoke_args
244
+ end
245
+ subcommand_class.commands.each do |_meth, command|
246
+ command.ancestor_name = subcommand
247
+ end
248
+ end
249
+ alias_method :subtask, :subcommand
250
+
251
+ # Extend check unknown options to accept a hash of conditions.
252
+ #
253
+ # === Parameters
254
+ # options<Hash>: A hash containing :only and/or :except keys
255
+ def check_unknown_options!(options = {})
256
+ @check_unknown_options ||= {}
257
+ options.each do |key, value|
258
+ if value
259
+ @check_unknown_options[key] = Array(value)
260
+ else
261
+ @check_unknown_options.delete(key)
262
+ end
263
+ end
264
+ @check_unknown_options
265
+ end
266
+
267
+ # Overwrite check_unknown_options? to take subcommands and options into account.
268
+ def check_unknown_options?(config) #:nodoc:
269
+ options = check_unknown_options
270
+ return false unless options
271
+
272
+ command = config[:current_command]
273
+ return true unless command
274
+
275
+ name = command.name
276
+
277
+ if subcommands.include?(name)
278
+ false
279
+ elsif options[:except]
280
+ !options[:except].include?(name.to_sym)
281
+ elsif options[:only]
282
+ options[:only].include?(name.to_sym)
283
+ else
284
+ true
285
+ end
286
+ end
287
+
288
+ # Stop parsing of options as soon as an unknown option or a regular
289
+ # argument is encountered. All remaining arguments are passed to the command.
290
+ # This is useful if you have a command that can receive arbitrary additional
291
+ # options, and where those additional options should not be handled by
292
+ # Thor.
293
+ #
294
+ # ==== Example
295
+ #
296
+ # To better understand how this is useful, let's consider a command that calls
297
+ # an external command. A user may want to pass arbitrary options and
298
+ # arguments to that command. The command itself also accepts some options,
299
+ # which should be handled by Thor.
300
+ #
301
+ # class_option "verbose", :type => :boolean
302
+ # stop_on_unknown_option! :exec
303
+ # check_unknown_options! :except => :exec
304
+ #
305
+ # desc "exec", "Run a shell command"
306
+ # def exec(*args)
307
+ # puts "diagnostic output" if options[:verbose]
308
+ # Kernel.exec(*args)
309
+ # end
310
+ #
311
+ # Here +exec+ can be called with +--verbose+ to get diagnostic output,
312
+ # e.g.:
313
+ #
314
+ # $ thor exec --verbose echo foo
315
+ # diagnostic output
316
+ # foo
317
+ #
318
+ # But if +--verbose+ is given after +echo+, it is passed to +echo+ instead:
319
+ #
320
+ # $ thor exec echo --verbose foo
321
+ # --verbose foo
322
+ #
323
+ # ==== Parameters
324
+ # Symbol ...:: A list of commands that should be affected.
325
+ def stop_on_unknown_option!(*command_names)
326
+ stop_on_unknown_option.merge(command_names)
327
+ end
328
+
329
+ def stop_on_unknown_option?(command) #:nodoc:
330
+ command && stop_on_unknown_option.include?(command.name.to_sym)
331
+ end
332
+
333
+ # Disable the check for required options for the given commands.
334
+ # This is useful if you have a command that does not need the required options
335
+ # to work, like help.
336
+ #
337
+ # ==== Parameters
338
+ # Symbol ...:: A list of commands that should be affected.
339
+ def disable_required_check!(*command_names)
340
+ disable_required_check.merge(command_names)
341
+ end
342
+
343
+ def disable_required_check?(command) #:nodoc:
344
+ command && disable_required_check.include?(command.name.to_sym)
345
+ end
346
+
347
+ protected
348
+
349
+ def stop_on_unknown_option #:nodoc:
350
+ @stop_on_unknown_option ||= Set.new
351
+ end
352
+
353
+ # help command has the required check disabled by default.
354
+ def disable_required_check #:nodoc:
355
+ @disable_required_check ||= Set.new([:help])
356
+ end
357
+
358
+ # The method responsible for dispatching given the args.
359
+ def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable MethodLength
360
+ meth ||= retrieve_command_name(given_args)
361
+ command = all_commands[normalize_command_name(meth)]
362
+
363
+ if !command && config[:invoked_via_subcommand]
364
+ # We're a subcommand and our first argument didn't match any of our
365
+ # commands. So we put it back and call our default command.
366
+ given_args.unshift(meth)
367
+ command = all_commands[normalize_command_name(default_command)]
368
+ end
369
+
370
+ if command
371
+ args, opts = Thor::Options.split(given_args)
372
+ if stop_on_unknown_option?(command) && !args.empty?
373
+ # given_args starts with a non-option, so we treat everything as
374
+ # ordinary arguments
375
+ args.concat opts
376
+ opts.clear
377
+ end
378
+ else
379
+ args = given_args
380
+ opts = nil
381
+ command = dynamic_command_class.new(meth)
382
+ end
383
+
384
+ opts = given_opts || opts || []
385
+ config[:current_command] = command
386
+ config[:command_options] = command.options
387
+
388
+ instance = new(args, opts, config)
389
+ yield instance if block_given?
390
+ args = instance.args
391
+ trailing = args[Range.new(arguments.size, -1)]
392
+ instance.invoke_command(command, trailing || [])
393
+ end
394
+
395
+ # The banner for this class. You can customize it if you are invoking the
396
+ # thor class by another ways which is not the Thor::Runner. It receives
397
+ # the command that is going to be invoked and a boolean which indicates if
398
+ # the namespace should be displayed as arguments.
399
+ #
400
+ def banner(command, namespace = nil, subcommand = false)
401
+ $thor_runner ||= false
402
+ command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage|
403
+ "#{basename} #{formatted_usage}"
404
+ end.join("\n")
405
+ end
406
+
407
+ def baseclass #:nodoc:
408
+ Thor
409
+ end
410
+
411
+ def dynamic_command_class #:nodoc:
412
+ Thor::DynamicCommand
413
+ end
414
+
415
+ def create_command(meth) #:nodoc:
416
+ @usage ||= nil
417
+ @desc ||= nil
418
+ @long_desc ||= nil
419
+ @hide ||= nil
420
+
421
+ if @usage && @desc
422
+ base_class = @hide ? Thor::HiddenCommand : Thor::Command
423
+ commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
424
+ @usage, @desc, @long_desc, @method_options, @hide = nil
425
+ true
426
+ elsif all_commands[meth] || meth == "method_missing"
427
+ true
428
+ else
429
+ puts "[WARNING] Attempted to create command #{meth.inspect} without usage or description. " \
430
+ "Call desc if you want this method to be available as command or declare it inside a " \
431
+ "no_commands{} block. Invoked from #{caller[1].inspect}."
432
+ false
433
+ end
434
+ end
435
+ alias_method :create_task, :create_command
436
+
437
+ def initialize_added #:nodoc:
438
+ class_options.merge!(method_options)
439
+ @method_options = nil
440
+ end
441
+
442
+ # Retrieve the command name from given args.
443
+ def retrieve_command_name(args) #:nodoc:
444
+ meth = args.first.to_s unless args.empty?
445
+ args.shift if meth && (map[meth] || meth !~ /^\-/)
446
+ end
447
+ alias_method :retrieve_task_name, :retrieve_command_name
448
+
449
+ # receives a (possibly nil) command name and returns a name that is in
450
+ # the commands hash. In addition to normalizing aliases, this logic
451
+ # will determine if a shortened command is an unambiguous substring of
452
+ # a command or alias.
453
+ #
454
+ # +normalize_command_name+ also converts names like +animal-prison+
455
+ # into +animal_prison+.
456
+ def normalize_command_name(meth) #:nodoc:
457
+ return default_command.to_s.tr("-", "_") unless meth
458
+
459
+ possibilities = find_command_possibilities(meth)
460
+ raise AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]" if possibilities.size > 1
461
+
462
+ if possibilities.empty?
463
+ meth ||= default_command
464
+ elsif map[meth]
465
+ meth = map[meth]
466
+ else
467
+ meth = possibilities.first
468
+ end
469
+
470
+ meth.to_s.tr("-", "_") # treat foo-bar as foo_bar
471
+ end
472
+ alias_method :normalize_task_name, :normalize_command_name
473
+
474
+ # this is the logic that takes the command name passed in by the user
475
+ # and determines whether it is an unambiguous substrings of a command or
476
+ # alias name.
477
+ def find_command_possibilities(meth)
478
+ len = meth.to_s.length
479
+ possibilities = all_commands.merge(map).keys.select { |n| meth == n[0, len] }.sort
480
+ unique_possibilities = possibilities.map { |k| map[k] || k }.uniq
481
+
482
+ if possibilities.include?(meth)
483
+ [meth]
484
+ elsif unique_possibilities.size == 1
485
+ unique_possibilities
486
+ else
487
+ possibilities
488
+ end
489
+ end
490
+ alias_method :find_task_possibilities, :find_command_possibilities
491
+
492
+ def subcommand_help(cmd)
493
+ desc "help [COMMAND]", "Describe subcommands or one specific subcommand"
494
+ class_eval "
495
+ def help(command = nil, subcommand = true); super; end
496
+ "
497
+ end
498
+ alias_method :subtask_help, :subcommand_help
499
+ end
500
+
501
+ include Thor::Base
502
+
503
+ map HELP_MAPPINGS => :help
504
+
505
+ desc "help [COMMAND]", "Describe available commands or one specific command"
506
+ def help(command = nil, subcommand = false)
507
+ if command
508
+ if self.class.subcommands.include? command
509
+ self.class.subcommand_classes[command].help(shell, true)
510
+ else
511
+ self.class.command_help(shell, command)
512
+ end
513
+ else
514
+ self.class.help(shell, subcommand)
515
+ end
516
+ end
517
+ end