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,142 @@
1
+ class Thor
2
+ class Command < Struct.new(:name, :description, :long_description, :usage, :options, :ancestor_name)
3
+ FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
4
+
5
+ def initialize(name, description, long_description, usage, options = nil)
6
+ super(name.to_s, description, long_description, usage, options || {})
7
+ end
8
+
9
+ def initialize_copy(other) #:nodoc:
10
+ super(other)
11
+ self.options = other.options.dup if other.options
12
+ end
13
+
14
+ def hidden?
15
+ false
16
+ end
17
+
18
+ # By default, a command invokes a method in the thor class. You can change this
19
+ # implementation to create custom commands.
20
+ def run(instance, args = [])
21
+ arity = nil
22
+
23
+ if private_method?(instance)
24
+ instance.class.handle_no_command_error(name)
25
+ elsif public_method?(instance)
26
+ arity = instance.method(name).arity
27
+ instance.__send__(name, *args)
28
+ elsif local_method?(instance, :method_missing)
29
+ instance.__send__(:method_missing, name.to_sym, *args)
30
+ else
31
+ instance.class.handle_no_command_error(name)
32
+ end
33
+ rescue ArgumentError => e
34
+ handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e, args, arity) : (raise e)
35
+ rescue NoMethodError => e
36
+ handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (raise e)
37
+ end
38
+
39
+ # Returns the formatted usage by injecting given required arguments
40
+ # and required options into the given usage.
41
+ def formatted_usage(klass, namespace = true, subcommand = false)
42
+ if ancestor_name
43
+ formatted = "#{ancestor_name} ".dup # add space
44
+ elsif namespace
45
+ namespace = klass.namespace
46
+ formatted = "#{namespace.gsub(/^(default)/, '')}:".dup
47
+ end
48
+ formatted ||= "#{klass.namespace.split(':').last} ".dup if subcommand
49
+
50
+ formatted ||= "".dup
51
+
52
+ Array(usage).map do |specific_usage|
53
+ formatted_specific_usage = formatted
54
+
55
+ formatted_specific_usage += required_arguments_for(klass, specific_usage)
56
+
57
+ # Add required options
58
+ formatted_specific_usage += " #{required_options}"
59
+
60
+ # Strip and go!
61
+ formatted_specific_usage.strip
62
+ end.join("\n")
63
+ end
64
+
65
+ protected
66
+
67
+ # Add usage with required arguments
68
+ def required_arguments_for(klass, usage)
69
+ if klass && !klass.arguments.empty?
70
+ usage.to_s.gsub(/^#{name}/) do |match|
71
+ match << " " << klass.arguments.map(&:usage).compact.join(" ")
72
+ end
73
+ else
74
+ usage.to_s
75
+ end
76
+ end
77
+
78
+ def not_debugging?(instance)
79
+ !(instance.class.respond_to?(:debugging) && instance.class.debugging)
80
+ end
81
+
82
+ def required_options
83
+ @required_options ||= options.map { |_, o| o.usage if o.required? }.compact.sort.join(" ")
84
+ end
85
+
86
+ # Given a target, checks if this class name is a public method.
87
+ def public_method?(instance) #:nodoc:
88
+ !(instance.public_methods & [name.to_s, name.to_sym]).empty?
89
+ end
90
+
91
+ def private_method?(instance)
92
+ !(instance.private_methods & [name.to_s, name.to_sym]).empty?
93
+ end
94
+
95
+ def local_method?(instance, name)
96
+ methods = instance.public_methods(false) + instance.private_methods(false) + instance.protected_methods(false)
97
+ !(methods & [name.to_s, name.to_sym]).empty?
98
+ end
99
+
100
+ def sans_backtrace(backtrace, caller) #:nodoc:
101
+ saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) || (frame =~ %r{^kernel/} && RUBY_ENGINE =~ /rbx/) }
102
+ saned - caller
103
+ end
104
+
105
+ def handle_argument_error?(instance, error, caller)
106
+ not_debugging?(instance) && (error.message =~ /wrong number of arguments/ || error.message =~ /given \d*, expected \d*/) && begin
107
+ saned = sans_backtrace(error.backtrace, caller)
108
+ saned.empty? || saned.size == 1
109
+ end
110
+ end
111
+
112
+ def handle_no_method_error?(instance, error, caller)
113
+ not_debugging?(instance) &&
114
+ error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
115
+ end
116
+ end
117
+ Task = Command
118
+
119
+ # A command that is hidden in help messages but still invocable.
120
+ class HiddenCommand < Command
121
+ def hidden?
122
+ true
123
+ end
124
+ end
125
+ HiddenTask = HiddenCommand
126
+
127
+ # A dynamic command that handles method missing scenarios.
128
+ class DynamicCommand < Command
129
+ def initialize(name, options = nil)
130
+ super(name.to_s, "A dynamically-generated command", name.to_s, name.to_s, options)
131
+ end
132
+
133
+ def run(instance, args = [])
134
+ if (instance.methods & [name.to_s, name.to_sym]).empty?
135
+ super
136
+ else
137
+ instance.class.handle_no_command_error(name)
138
+ end
139
+ end
140
+ end
141
+ DynamicTask = DynamicCommand
142
+ end
@@ -0,0 +1,97 @@
1
+ class Thor
2
+ module CoreExt #:nodoc:
3
+ # A hash with indifferent access and magic predicates.
4
+ #
5
+ # hash = Thor::CoreExt::HashWithIndifferentAccess.new 'foo' => 'bar', 'baz' => 'bee', 'force' => true
6
+ #
7
+ # hash[:foo] #=> 'bar'
8
+ # hash['foo'] #=> 'bar'
9
+ # hash.foo? #=> true
10
+ #
11
+ class HashWithIndifferentAccess < ::Hash #:nodoc:
12
+ def initialize(hash = {})
13
+ super()
14
+ hash.each do |key, value|
15
+ self[convert_key(key)] = value
16
+ end
17
+ end
18
+
19
+ def [](key)
20
+ super(convert_key(key))
21
+ end
22
+
23
+ def []=(key, value)
24
+ super(convert_key(key), value)
25
+ end
26
+
27
+ def delete(key)
28
+ super(convert_key(key))
29
+ end
30
+
31
+ def fetch(key, *args)
32
+ super(convert_key(key), *args)
33
+ end
34
+
35
+ def key?(key)
36
+ super(convert_key(key))
37
+ end
38
+
39
+ def values_at(*indices)
40
+ indices.map { |key| self[convert_key(key)] }
41
+ end
42
+
43
+ def merge(other)
44
+ dup.merge!(other)
45
+ end
46
+
47
+ def merge!(other)
48
+ other.each do |key, value|
49
+ self[convert_key(key)] = value
50
+ end
51
+ self
52
+ end
53
+
54
+ def reverse_merge(other)
55
+ self.class.new(other).merge(self)
56
+ end
57
+
58
+ def reverse_merge!(other_hash)
59
+ replace(reverse_merge(other_hash))
60
+ end
61
+
62
+ def replace(other_hash)
63
+ super(other_hash)
64
+ end
65
+
66
+ # Convert to a Hash with String keys.
67
+ def to_hash
68
+ Hash.new(default).merge!(self)
69
+ end
70
+
71
+ protected
72
+
73
+ def convert_key(key)
74
+ key.is_a?(Symbol) ? key.to_s : key
75
+ end
76
+
77
+ # Magic predicates. For instance:
78
+ #
79
+ # options.force? # => !!options['force']
80
+ # options.shebang # => "/usr/lib/local/ruby"
81
+ # options.test_framework?(:rspec) # => options[:test_framework] == :rspec
82
+ #
83
+ def method_missing(method, *args)
84
+ method = method.to_s
85
+ if method =~ /^(\w+)\?$/
86
+ if args.empty?
87
+ !!self[$1]
88
+ else
89
+ self[$1] == args.first
90
+ end
91
+ else
92
+ self[method]
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,110 @@
1
+ class Thor
2
+ Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable)
3
+ # In order to support versions of Ruby that don't have keyword
4
+ # arguments, we need our own spell checker class that doesn't take key
5
+ # words. Even though this code wouldn't be hit because of the check
6
+ # above, it's still necessary because the interpreter would otherwise be
7
+ # unable to parse the file.
8
+ class NoKwargSpellChecker < DidYouMean::SpellChecker # :nodoc:
9
+ def initialize(dictionary)
10
+ @dictionary = dictionary
11
+ end
12
+ end
13
+
14
+ DidYouMean::Correctable
15
+ end
16
+
17
+ # Thor::Error is raised when it's caused by wrong usage of thor classes. Those
18
+ # errors have their backtrace suppressed and are nicely shown to the user.
19
+ #
20
+ # Errors that are caused by the developer, like declaring a method which
21
+ # overwrites a thor keyword, SHOULD NOT raise a Thor::Error. This way, we
22
+ # ensure that developer errors are shown with full backtrace.
23
+ class Error < StandardError
24
+ end
25
+
26
+ # Raised when a command was not found.
27
+ class UndefinedCommandError < Error
28
+ class SpellChecker
29
+ attr_reader :error
30
+
31
+ def initialize(error)
32
+ @error = error
33
+ end
34
+
35
+ def corrections
36
+ @corrections ||= spell_checker.correct(error.command).map(&:inspect)
37
+ end
38
+
39
+ def spell_checker
40
+ NoKwargSpellChecker.new(error.all_commands)
41
+ end
42
+ end
43
+
44
+ attr_reader :command, :all_commands
45
+
46
+ def initialize(command, all_commands, namespace)
47
+ @command = command
48
+ @all_commands = all_commands
49
+
50
+ message = "Could not find command #{command.inspect}"
51
+ message = namespace ? "#{message} in #{namespace.inspect} namespace." : "#{message}."
52
+
53
+ super(message)
54
+ end
55
+
56
+ prepend Correctable if Correctable
57
+ end
58
+ UndefinedTaskError = UndefinedCommandError
59
+
60
+ class AmbiguousCommandError < Error
61
+ end
62
+ AmbiguousTaskError = AmbiguousCommandError
63
+
64
+ # Raised when a command was found, but not invoked properly.
65
+ class InvocationError < Error
66
+ end
67
+
68
+ class UnknownArgumentError < Error
69
+ class SpellChecker
70
+ attr_reader :error
71
+
72
+ def initialize(error)
73
+ @error = error
74
+ end
75
+
76
+ def corrections
77
+ @corrections ||=
78
+ error.unknown.flat_map { |unknown| spell_checker.correct(unknown) }.uniq.map(&:inspect)
79
+ end
80
+
81
+ def spell_checker
82
+ @spell_checker ||= NoKwargSpellChecker.new(error.switches)
83
+ end
84
+ end
85
+
86
+ attr_reader :switches, :unknown
87
+
88
+ def initialize(switches, unknown)
89
+ @switches = switches
90
+ @unknown = unknown
91
+
92
+ super("Unknown switches #{unknown.map(&:inspect).join(', ')}")
93
+ end
94
+
95
+ prepend Correctable if Correctable
96
+ end
97
+
98
+ class RequiredArgumentMissingError < InvocationError
99
+ end
100
+
101
+ class MalformattedArgumentError < InvocationError
102
+ end
103
+
104
+ if Correctable
105
+ DidYouMean::SPELL_CHECKERS.merge!(
106
+ 'Thor::UndefinedCommandError' => UndefinedCommandError::SpellChecker,
107
+ 'Thor::UnknownArgumentError' => UnknownArgumentError::SpellChecker
108
+ )
109
+ end
110
+ end
@@ -0,0 +1,281 @@
1
+ require_relative "base"
2
+
3
+ # Thor has a special class called Thor::Group. The main difference to Thor class
4
+ # is that it invokes all commands at once. It also include some methods that allows
5
+ # invocations to be done at the class method, which are not available to Thor
6
+ # commands.
7
+ class Thor::Group
8
+ class << self
9
+ # The description for this Thor::Group. If none is provided, but a source root
10
+ # exists, tries to find the USAGE one folder above it, otherwise searches
11
+ # in the superclass.
12
+ #
13
+ # ==== Parameters
14
+ # description<String>:: The description for this Thor::Group.
15
+ #
16
+ def desc(description = nil)
17
+ if description
18
+ @desc = description
19
+ else
20
+ @desc ||= from_superclass(:desc, nil)
21
+ end
22
+ end
23
+
24
+ # Prints help information.
25
+ #
26
+ # ==== Options
27
+ # short:: When true, shows only usage.
28
+ #
29
+ def help(shell)
30
+ shell.say "Usage:"
31
+ shell.say " #{banner}\n"
32
+ shell.say
33
+ class_options_help(shell)
34
+ shell.say desc if desc
35
+ end
36
+
37
+ # Stores invocations for this class merging with superclass values.
38
+ #
39
+ def invocations #:nodoc:
40
+ @invocations ||= from_superclass(:invocations, {})
41
+ end
42
+
43
+ # Stores invocation blocks used on invoke_from_option.
44
+ #
45
+ def invocation_blocks #:nodoc:
46
+ @invocation_blocks ||= from_superclass(:invocation_blocks, {})
47
+ end
48
+
49
+ # Invoke the given namespace or class given. It adds an instance
50
+ # method that will invoke the klass and command. You can give a block to
51
+ # configure how it will be invoked.
52
+ #
53
+ # The namespace/class given will have its options showed on the help
54
+ # usage. Check invoke_from_option for more information.
55
+ #
56
+ def invoke(*names, &block)
57
+ options = names.last.is_a?(Hash) ? names.pop : {}
58
+ verbose = options.fetch(:verbose, true)
59
+
60
+ names.each do |name|
61
+ invocations[name] = false
62
+ invocation_blocks[name] = block if block_given?
63
+
64
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
65
+ def _invoke_#{name.to_s.gsub(/\W/, '_')}
66
+ klass, command = self.class.prepare_for_invocation(nil, #{name.inspect})
67
+
68
+ if klass
69
+ say_status :invoke, #{name.inspect}, #{verbose.inspect}
70
+ block = self.class.invocation_blocks[#{name.inspect}]
71
+ _invoke_for_class_method klass, command, &block
72
+ else
73
+ say_status :error, %(#{name.inspect} [not found]), :red
74
+ end
75
+ end
76
+ METHOD
77
+ end
78
+ end
79
+
80
+ # Invoke a thor class based on the value supplied by the user to the
81
+ # given option named "name". A class option must be created before this
82
+ # method is invoked for each name given.
83
+ #
84
+ # ==== Examples
85
+ #
86
+ # class GemGenerator < Thor::Group
87
+ # class_option :test_framework, :type => :string
88
+ # invoke_from_option :test_framework
89
+ # end
90
+ #
91
+ # ==== Boolean options
92
+ #
93
+ # In some cases, you want to invoke a thor class if some option is true or
94
+ # false. This is automatically handled by invoke_from_option. Then the
95
+ # option name is used to invoke the generator.
96
+ #
97
+ # ==== Preparing for invocation
98
+ #
99
+ # In some cases you want to customize how a specified hook is going to be
100
+ # invoked. You can do that by overwriting the class method
101
+ # prepare_for_invocation. The class method must necessarily return a klass
102
+ # and an optional command.
103
+ #
104
+ # ==== Custom invocations
105
+ #
106
+ # You can also supply a block to customize how the option is going to be
107
+ # invoked. The block receives two parameters, an instance of the current
108
+ # class and the klass to be invoked.
109
+ #
110
+ def invoke_from_option(*names, &block)
111
+ options = names.last.is_a?(Hash) ? names.pop : {}
112
+ verbose = options.fetch(:verbose, :white)
113
+
114
+ names.each do |name|
115
+ unless class_options.key?(name)
116
+ raise ArgumentError, "You have to define the option #{name.inspect} " \
117
+ "before setting invoke_from_option."
118
+ end
119
+
120
+ invocations[name] = true
121
+ invocation_blocks[name] = block if block_given?
122
+
123
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
124
+ def _invoke_from_option_#{name.to_s.gsub(/\W/, '_')}
125
+ return unless options[#{name.inspect}]
126
+
127
+ value = options[#{name.inspect}]
128
+ value = #{name.inspect} if TrueClass === value
129
+ klass, command = self.class.prepare_for_invocation(#{name.inspect}, value)
130
+
131
+ if klass
132
+ say_status :invoke, value, #{verbose.inspect}
133
+ block = self.class.invocation_blocks[#{name.inspect}]
134
+ _invoke_for_class_method klass, command, &block
135
+ else
136
+ say_status :error, %(\#{value} [not found]), :red
137
+ end
138
+ end
139
+ METHOD
140
+ end
141
+ end
142
+
143
+ # Remove a previously added invocation.
144
+ #
145
+ # ==== Examples
146
+ #
147
+ # remove_invocation :test_framework
148
+ #
149
+ def remove_invocation(*names)
150
+ names.each do |name|
151
+ remove_command(name)
152
+ remove_class_option(name)
153
+ invocations.delete(name)
154
+ invocation_blocks.delete(name)
155
+ end
156
+ end
157
+
158
+ # Overwrite class options help to allow invoked generators options to be
159
+ # shown recursively when invoking a generator.
160
+ #
161
+ def class_options_help(shell, groups = {}) #:nodoc:
162
+ get_options_from_invocations(groups, class_options) do |klass|
163
+ klass.send(:get_options_from_invocations, groups, class_options)
164
+ end
165
+ super(shell, groups)
166
+ end
167
+
168
+ # Get invocations array and merge options from invocations. Those
169
+ # options are added to group_options hash. Options that already exists
170
+ # in base_options are not added twice.
171
+ #
172
+ def get_options_from_invocations(group_options, base_options) #:nodoc: # rubocop:disable MethodLength
173
+ invocations.each do |name, from_option|
174
+ value = if from_option
175
+ option = class_options[name]
176
+ option.type == :boolean ? name : option.default
177
+ else
178
+ name
179
+ end
180
+ next unless value
181
+
182
+ klass, _ = prepare_for_invocation(name, value)
183
+ next unless klass && klass.respond_to?(:class_options)
184
+
185
+ value = value.to_s
186
+ human_name = value.respond_to?(:classify) ? value.classify : value
187
+
188
+ group_options[human_name] ||= []
189
+ group_options[human_name] += klass.class_options.values.select do |class_option|
190
+ base_options[class_option.name.to_sym].nil? && class_option.group.nil? &&
191
+ !group_options.values.flatten.any? { |i| i.name == class_option.name }
192
+ end
193
+
194
+ yield klass if block_given?
195
+ end
196
+ end
197
+
198
+ # Returns commands ready to be printed.
199
+ def printable_commands(*)
200
+ item = []
201
+ item << banner
202
+ item << (desc ? "# #{desc.gsub(/\s+/m, ' ')}" : "")
203
+ [item]
204
+ end
205
+ alias_method :printable_tasks, :printable_commands
206
+
207
+ def handle_argument_error(command, error, _args, arity) #:nodoc:
208
+ msg = "#{basename} #{command.name} takes #{arity} argument".dup
209
+ msg << "s" if arity > 1
210
+ msg << ", but it should not."
211
+ raise error, msg
212
+ end
213
+
214
+ protected
215
+
216
+ # The method responsible for dispatching given the args.
217
+ def dispatch(command, given_args, given_opts, config) #:nodoc:
218
+ if Thor::HELP_MAPPINGS.include?(given_args.first)
219
+ help(config[:shell])
220
+ return
221
+ end
222
+
223
+ args, opts = Thor::Options.split(given_args)
224
+ opts = given_opts || opts
225
+
226
+ instance = new(args, opts, config)
227
+ yield instance if block_given?
228
+
229
+ if command
230
+ instance.invoke_command(all_commands[command])
231
+ else
232
+ instance.invoke_all
233
+ end
234
+ end
235
+
236
+ # The banner for this class. You can customize it if you are invoking the
237
+ # thor class by another ways which is not the Thor::Runner.
238
+ def banner
239
+ "#{basename} #{self_command.formatted_usage(self, false)}"
240
+ end
241
+
242
+ # Represents the whole class as a command.
243
+ def self_command #:nodoc:
244
+ Thor::DynamicCommand.new(namespace, class_options)
245
+ end
246
+ alias_method :self_task, :self_command
247
+
248
+ def baseclass #:nodoc:
249
+ Thor::Group
250
+ end
251
+
252
+ def create_command(meth) #:nodoc:
253
+ commands[meth.to_s] = Thor::Command.new(meth, nil, nil, nil, nil)
254
+ true
255
+ end
256
+ alias_method :create_task, :create_command
257
+ end
258
+
259
+ include Thor::Base
260
+
261
+ protected
262
+
263
+ # Shortcut to invoke with padding and block handling. Use internally by
264
+ # invoke and invoke_from_option class methods.
265
+ def _invoke_for_class_method(klass, command = nil, *args, &block) #:nodoc:
266
+ with_padding do
267
+ if block
268
+ case block.arity
269
+ when 3
270
+ yield(self, klass, command)
271
+ when 2
272
+ yield(self, klass)
273
+ when 1
274
+ instance_exec(klass, &block)
275
+ end
276
+ else
277
+ invoke klass, command, *args
278
+ end
279
+ end
280
+ end
281
+ end