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.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/colorcode_convert_rgb.gemspec +30 -0
- data/exe/colorcode_convert_rgb +4 -0
- data/lib/colorcode_convert_rgb.rb +7 -0
- data/lib/colorcode_convert_rgb/cli.rb +13 -0
- data/lib/colorcode_convert_rgb/version.rb +3 -0
- data/vendor/bundle/ruby/2.5.0/bin/colorcode_convert_rgb +27 -0
- data/vendor/bundle/ruby/2.5.0/bin/rake +27 -0
- data/vendor/bundle/ruby/2.5.0/bin/thor +27 -0
- data/vendor/bundle/ruby/2.5.0/cache/minitest-5.14.2.gem +0 -0
- data/vendor/bundle/ruby/2.5.0/cache/rake-12.3.3.gem +0 -0
- data/vendor/bundle/ruby/2.5.0/cache/thor-1.0.1.gem +0 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/.autotest +34 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/History.rdoc +1397 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Manifest.txt +27 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/README.rdoc +764 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Rakefile +74 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/design_rationale.rb +52 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/hoe/minitest.rb +32 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest.rb +1056 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/assertions.rb +807 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/autorun.rb +13 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/benchmark.rb +455 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/expectations.rb +303 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/hell.rb +11 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/mock.rb +240 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/parallel.rb +70 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride.rb +4 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride_plugin.rb +142 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/spec.rb +342 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/test.rb +220 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/unit.rb +45 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/metametameta.rb +136 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_assertions.rb +1575 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_benchmark.rb +137 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_mock.rb +872 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_reporter.rb +299 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_spec.rb +1061 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_test.rb +1084 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/CONTRIBUTING.rdoc +43 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Gemfile +3 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/History.rdoc +2344 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/MIT-LICENSE +21 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/README.rdoc +156 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Rakefile +41 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/azure-pipelines.yml +11 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/bundle +105 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/console +7 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rake +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rdoc +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rubocop +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/setup +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/command_line_usage.rdoc +158 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile1 +38 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile2 +35 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/a.c +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/b.c +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/main.c +11 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/glossary.rdoc +42 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/jamis.rb +592 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/proto_rake.rdoc +127 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rake.1 +156 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rakefile.rdoc +622 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rational.rdoc +151 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/exe/rake +27 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake.rb +71 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb +824 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/backtrace.rb +24 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/clean.rb +78 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cloneable.rb +17 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cpu_counter.rb +107 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/default_loader.rb +15 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/dsl_definition.rb +195 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/early_time.rb +22 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/core.rb +26 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/string.rb +176 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_creation_task.rb +25 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_list.rb +435 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_task.rb +54 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils.rb +137 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils_ext.rb +145 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_chain.rb +57 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_exception_mixin.rb +17 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/late_time.rb +18 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/linked_list.rb +112 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/loaders/makefile.rb +54 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/multi_task.rb +14 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/name_space.rb +38 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/packagetask.rb +207 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/phony.rb +16 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/private_reader.rb +21 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/promise.rb +100 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/pseudo_status.rb +30 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_module.rb +67 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_test_loader.rb +27 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rule_recursion_overflow_error.rb +20 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/scope.rb +43 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task.rb +413 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_argument_error.rb +8 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_arguments.rb +109 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_manager.rb +324 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/tasklib.rb +12 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/testtask.rb +224 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_history_display.rb +49 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_pool.rb +163 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/trace_output.rb +23 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/version.rb +10 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/win32.rb +51 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/rake.gemspec +42 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/.document +5 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CHANGELOG.md +220 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CONTRIBUTING.md +15 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/LICENSE.md +20 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/README.md +51 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/bin/thor +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor.rb +517 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions.rb +336 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_file.rb +104 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_link.rb +61 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/directory.rb +108 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/empty_directory.rb +143 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/file_manipulation.rb +373 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/inject_into_file.rb +120 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/base.rb +699 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/command.rb +142 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/core_ext/hash_with_indifferent_access.rb +97 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/error.rb +110 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/group.rb +281 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/invocation.rb +178 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor.rb +17 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/basic.rb +37 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/readline.rb +88 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/nested_context.rb +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser.rb +4 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/argument.rb +70 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/arguments.rb +175 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/option.rb +159 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/options.rb +236 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/rake_compat.rb +72 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/runner.rb +325 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell.rb +81 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/basic.rb +491 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/color.rb +153 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/html.rb +126 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/util.rb +284 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/version.rb +3 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/thor.gemspec +28 -0
- data/vendor/bundle/ruby/2.5.0/specifications/minitest-5.14.2.gemspec +38 -0
- data/vendor/bundle/ruby/2.5.0/specifications/rake-12.3.3.gemspec +43 -0
- data/vendor/bundle/ruby/2.5.0/specifications/thor-1.0.1.gemspec +34 -0
- metadata +214 -0
@@ -0,0 +1,159 @@
|
|
1
|
+
class Thor
|
2
|
+
class Option < Argument #:nodoc:
|
3
|
+
attr_reader :aliases, :group, :lazy_default, :hide, :repeatable
|
4
|
+
|
5
|
+
VALID_TYPES = [:boolean, :numeric, :hash, :array, :string]
|
6
|
+
|
7
|
+
def initialize(name, options = {})
|
8
|
+
@check_default_type = options[:check_default_type]
|
9
|
+
options[:required] = false unless options.key?(:required)
|
10
|
+
@repeatable = options.fetch(:repeatable, false)
|
11
|
+
super
|
12
|
+
@lazy_default = options[:lazy_default]
|
13
|
+
@group = options[:group].to_s.capitalize if options[:group]
|
14
|
+
@aliases = Array(options[:aliases])
|
15
|
+
@hide = options[:hide]
|
16
|
+
end
|
17
|
+
|
18
|
+
# This parse quick options given as method_options. It makes several
|
19
|
+
# assumptions, but you can be more specific using the option method.
|
20
|
+
#
|
21
|
+
# parse :foo => "bar"
|
22
|
+
# #=> Option foo with default value bar
|
23
|
+
#
|
24
|
+
# parse [:foo, :baz] => "bar"
|
25
|
+
# #=> Option foo with default value bar and alias :baz
|
26
|
+
#
|
27
|
+
# parse :foo => :required
|
28
|
+
# #=> Required option foo without default value
|
29
|
+
#
|
30
|
+
# parse :foo => 2
|
31
|
+
# #=> Option foo with default value 2 and type numeric
|
32
|
+
#
|
33
|
+
# parse :foo => :numeric
|
34
|
+
# #=> Option foo without default value and type numeric
|
35
|
+
#
|
36
|
+
# parse :foo => true
|
37
|
+
# #=> Option foo with default value true and type boolean
|
38
|
+
#
|
39
|
+
# The valid types are :boolean, :numeric, :hash, :array and :string. If none
|
40
|
+
# is given a default type is assumed. This default type accepts arguments as
|
41
|
+
# string (--foo=value) or booleans (just --foo).
|
42
|
+
#
|
43
|
+
# By default all options are optional, unless :required is given.
|
44
|
+
#
|
45
|
+
def self.parse(key, value)
|
46
|
+
if key.is_a?(Array)
|
47
|
+
name, *aliases = key
|
48
|
+
else
|
49
|
+
name = key
|
50
|
+
aliases = []
|
51
|
+
end
|
52
|
+
|
53
|
+
name = name.to_s
|
54
|
+
default = value
|
55
|
+
|
56
|
+
type = case value
|
57
|
+
when Symbol
|
58
|
+
default = nil
|
59
|
+
if VALID_TYPES.include?(value)
|
60
|
+
value
|
61
|
+
elsif required = (value == :required) # rubocop:disable AssignmentInCondition
|
62
|
+
:string
|
63
|
+
end
|
64
|
+
when TrueClass, FalseClass
|
65
|
+
:boolean
|
66
|
+
when Numeric
|
67
|
+
:numeric
|
68
|
+
when Hash, Array, String
|
69
|
+
value.class.name.downcase.to_sym
|
70
|
+
end
|
71
|
+
|
72
|
+
new(name.to_s, :required => required, :type => type, :default => default, :aliases => aliases)
|
73
|
+
end
|
74
|
+
|
75
|
+
def switch_name
|
76
|
+
@switch_name ||= dasherized? ? name : dasherize(name)
|
77
|
+
end
|
78
|
+
|
79
|
+
def human_name
|
80
|
+
@human_name ||= dasherized? ? undasherize(name) : name
|
81
|
+
end
|
82
|
+
|
83
|
+
def usage(padding = 0)
|
84
|
+
sample = if banner && !banner.to_s.empty?
|
85
|
+
"#{switch_name}=#{banner}".dup
|
86
|
+
else
|
87
|
+
switch_name
|
88
|
+
end
|
89
|
+
|
90
|
+
sample = "[#{sample}]".dup unless required?
|
91
|
+
|
92
|
+
if boolean?
|
93
|
+
sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-")
|
94
|
+
end
|
95
|
+
|
96
|
+
if aliases.empty?
|
97
|
+
(" " * padding) << sample
|
98
|
+
else
|
99
|
+
"#{aliases.join(', ')}, #{sample}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
VALID_TYPES.each do |type|
|
104
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
105
|
+
def #{type}?
|
106
|
+
self.type == #{type.inspect}
|
107
|
+
end
|
108
|
+
RUBY
|
109
|
+
end
|
110
|
+
|
111
|
+
protected
|
112
|
+
|
113
|
+
def validate!
|
114
|
+
raise ArgumentError, "An option cannot be boolean and required." if boolean? && required?
|
115
|
+
validate_default_type!
|
116
|
+
end
|
117
|
+
|
118
|
+
def validate_default_type!
|
119
|
+
default_type = case @default
|
120
|
+
when nil
|
121
|
+
return
|
122
|
+
when TrueClass, FalseClass
|
123
|
+
required? ? :string : :boolean
|
124
|
+
when Numeric
|
125
|
+
:numeric
|
126
|
+
when Symbol
|
127
|
+
:string
|
128
|
+
when Hash, Array, String
|
129
|
+
@default.class.name.downcase.to_sym
|
130
|
+
end
|
131
|
+
|
132
|
+
expected_type = (@repeatable && @type != :hash) ? :array : @type
|
133
|
+
|
134
|
+
if default_type != expected_type
|
135
|
+
err = "Expected #{expected_type} default value for '#{switch_name}'; got #{@default.inspect} (#{default_type})"
|
136
|
+
|
137
|
+
if @check_default_type
|
138
|
+
raise ArgumentError, err
|
139
|
+
elsif @check_default_type == nil
|
140
|
+
Thor.deprecation_warning "#{err}.\n" +
|
141
|
+
'This will be rejected in the future unless you explicitly pass the options `check_default_type: false`' +
|
142
|
+
' or call `allow_incompatible_default_type!` in your code'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def dasherized?
|
148
|
+
name.index("-") == 0
|
149
|
+
end
|
150
|
+
|
151
|
+
def undasherize(str)
|
152
|
+
str.sub(/^-{1,2}/, "")
|
153
|
+
end
|
154
|
+
|
155
|
+
def dasherize(str)
|
156
|
+
(str.length > 1 ? "--" : "-") + str.tr("_", "-")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
class Thor
|
2
|
+
class Options < Arguments #:nodoc: # rubocop:disable ClassLength
|
3
|
+
LONG_RE = /^(--\w+(?:-\w+)*)$/
|
4
|
+
SHORT_RE = /^(-[a-z])$/i
|
5
|
+
EQ_RE = /^(--\w+(?:-\w+)*|-[a-z])=(.*)$/i
|
6
|
+
SHORT_SQ_RE = /^-([a-z]{2,})$/i # Allow either -x -v or -xv style for single char args
|
7
|
+
SHORT_NUM = /^(-[a-z])#{NUMERIC}$/i
|
8
|
+
OPTS_END = "--".freeze
|
9
|
+
|
10
|
+
# Receives a hash and makes it switches.
|
11
|
+
def self.to_switches(options)
|
12
|
+
options.map do |key, value|
|
13
|
+
case value
|
14
|
+
when true
|
15
|
+
"--#{key}"
|
16
|
+
when Array
|
17
|
+
"--#{key} #{value.map(&:inspect).join(' ')}"
|
18
|
+
when Hash
|
19
|
+
"--#{key} #{value.map { |k, v| "#{k}:#{v}" }.join(' ')}"
|
20
|
+
when nil, false
|
21
|
+
nil
|
22
|
+
else
|
23
|
+
"--#{key} #{value.inspect}"
|
24
|
+
end
|
25
|
+
end.compact.join(" ")
|
26
|
+
end
|
27
|
+
|
28
|
+
# Takes a hash of Thor::Option and a hash with defaults.
|
29
|
+
#
|
30
|
+
# If +stop_on_unknown+ is true, #parse will stop as soon as it encounters
|
31
|
+
# an unknown option or a regular argument.
|
32
|
+
def initialize(hash_options = {}, defaults = {}, stop_on_unknown = false, disable_required_check = false)
|
33
|
+
@stop_on_unknown = stop_on_unknown
|
34
|
+
@disable_required_check = disable_required_check
|
35
|
+
options = hash_options.values
|
36
|
+
super(options)
|
37
|
+
|
38
|
+
# Add defaults
|
39
|
+
defaults.each do |key, value|
|
40
|
+
@assigns[key.to_s] = value
|
41
|
+
@non_assigned_required.delete(hash_options[key])
|
42
|
+
end
|
43
|
+
|
44
|
+
@shorts = {}
|
45
|
+
@switches = {}
|
46
|
+
@extra = []
|
47
|
+
@stopped_parsing_after_extra_index = nil
|
48
|
+
|
49
|
+
options.each do |option|
|
50
|
+
@switches[option.switch_name] = option
|
51
|
+
|
52
|
+
option.aliases.each do |short|
|
53
|
+
name = short.to_s.sub(/^(?!\-)/, "-")
|
54
|
+
@shorts[name] ||= option.switch_name
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def remaining
|
60
|
+
@extra
|
61
|
+
end
|
62
|
+
|
63
|
+
def peek
|
64
|
+
return super unless @parsing_options
|
65
|
+
|
66
|
+
result = super
|
67
|
+
if result == OPTS_END
|
68
|
+
shift
|
69
|
+
@parsing_options = false
|
70
|
+
@stopped_parsing_after_extra_index ||= @extra.size
|
71
|
+
super
|
72
|
+
else
|
73
|
+
result
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def parse(args) # rubocop:disable MethodLength
|
78
|
+
@pile = args.dup
|
79
|
+
@parsing_options = true
|
80
|
+
|
81
|
+
while peek
|
82
|
+
if parsing_options?
|
83
|
+
match, is_switch = current_is_switch?
|
84
|
+
shifted = shift
|
85
|
+
|
86
|
+
if is_switch
|
87
|
+
case shifted
|
88
|
+
when SHORT_SQ_RE
|
89
|
+
unshift($1.split("").map { |f| "-#{f}" })
|
90
|
+
next
|
91
|
+
when EQ_RE, SHORT_NUM
|
92
|
+
unshift($2)
|
93
|
+
switch = $1
|
94
|
+
when LONG_RE, SHORT_RE
|
95
|
+
switch = $1
|
96
|
+
end
|
97
|
+
|
98
|
+
switch = normalize_switch(switch)
|
99
|
+
option = switch_option(switch)
|
100
|
+
result = parse_peek(switch, option)
|
101
|
+
assign_result!(option, result)
|
102
|
+
elsif @stop_on_unknown
|
103
|
+
@parsing_options = false
|
104
|
+
@extra << shifted
|
105
|
+
@stopped_parsing_after_extra_index ||= @extra.size
|
106
|
+
@extra << shift while peek
|
107
|
+
break
|
108
|
+
elsif match
|
109
|
+
@extra << shifted
|
110
|
+
@extra << shift while peek && peek !~ /^-/
|
111
|
+
else
|
112
|
+
@extra << shifted
|
113
|
+
end
|
114
|
+
else
|
115
|
+
@extra << shift
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
check_requirement! unless @disable_required_check
|
120
|
+
|
121
|
+
assigns = Thor::CoreExt::HashWithIndifferentAccess.new(@assigns)
|
122
|
+
assigns.freeze
|
123
|
+
assigns
|
124
|
+
end
|
125
|
+
|
126
|
+
def check_unknown!
|
127
|
+
to_check = @stopped_parsing_after_extra_index ? @extra[0...@stopped_parsing_after_extra_index] : @extra
|
128
|
+
|
129
|
+
# an unknown option starts with - or -- and has no more --'s afterward.
|
130
|
+
unknown = to_check.select { |str| str =~ /^--?(?:(?!--).)*$/ }
|
131
|
+
raise UnknownArgumentError.new(@switches.keys, unknown) unless unknown.empty?
|
132
|
+
end
|
133
|
+
|
134
|
+
protected
|
135
|
+
|
136
|
+
def assign_result!(option, result)
|
137
|
+
if option.repeatable && option.type == :hash
|
138
|
+
(@assigns[option.human_name] ||= {}).merge!(result)
|
139
|
+
elsif option.repeatable
|
140
|
+
(@assigns[option.human_name] ||= []) << result
|
141
|
+
else
|
142
|
+
@assigns[option.human_name] = result
|
143
|
+
end
|
144
|
+
end
|
145
|
+
# Check if the current value in peek is a registered switch.
|
146
|
+
#
|
147
|
+
# Two booleans are returned. The first is true if the current value
|
148
|
+
# starts with a hyphen; the second is true if it is a registered switch.
|
149
|
+
def current_is_switch?
|
150
|
+
case peek
|
151
|
+
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM
|
152
|
+
[true, switch?($1)]
|
153
|
+
when SHORT_SQ_RE
|
154
|
+
[true, $1.split("").any? { |f| switch?("-#{f}") }]
|
155
|
+
else
|
156
|
+
[false, false]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def current_is_switch_formatted?
|
161
|
+
case peek
|
162
|
+
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM, SHORT_SQ_RE
|
163
|
+
true
|
164
|
+
else
|
165
|
+
false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def current_is_value?
|
170
|
+
peek && (!parsing_options? || super)
|
171
|
+
end
|
172
|
+
|
173
|
+
def switch?(arg)
|
174
|
+
!switch_option(normalize_switch(arg)).nil?
|
175
|
+
end
|
176
|
+
|
177
|
+
def switch_option(arg)
|
178
|
+
if match = no_or_skip?(arg) # rubocop:disable AssignmentInCondition
|
179
|
+
@switches[arg] || @switches["--#{match}"]
|
180
|
+
else
|
181
|
+
@switches[arg]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# Check if the given argument is actually a shortcut.
|
186
|
+
#
|
187
|
+
def normalize_switch(arg)
|
188
|
+
(@shorts[arg] || arg).tr("_", "-")
|
189
|
+
end
|
190
|
+
|
191
|
+
def parsing_options?
|
192
|
+
peek
|
193
|
+
@parsing_options
|
194
|
+
end
|
195
|
+
|
196
|
+
# Parse boolean values which can be given as --foo=true, --foo or --no-foo.
|
197
|
+
#
|
198
|
+
def parse_boolean(switch)
|
199
|
+
if current_is_value?
|
200
|
+
if ["true", "TRUE", "t", "T", true].include?(peek)
|
201
|
+
shift
|
202
|
+
true
|
203
|
+
elsif ["false", "FALSE", "f", "F", false].include?(peek)
|
204
|
+
shift
|
205
|
+
false
|
206
|
+
else
|
207
|
+
@switches.key?(switch) || !no_or_skip?(switch)
|
208
|
+
end
|
209
|
+
else
|
210
|
+
@switches.key?(switch) || !no_or_skip?(switch)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# Parse the value at the peek analyzing if it requires an input or not.
|
215
|
+
#
|
216
|
+
def parse_peek(switch, option)
|
217
|
+
if parsing_options? && (current_is_switch_formatted? || last?)
|
218
|
+
if option.boolean?
|
219
|
+
# No problem for boolean types
|
220
|
+
elsif no_or_skip?(switch)
|
221
|
+
return nil # User set value to nil
|
222
|
+
elsif option.string? && !option.required?
|
223
|
+
# Return the default if there is one, else the human name
|
224
|
+
return option.lazy_default || option.default || option.human_name
|
225
|
+
elsif option.lazy_default
|
226
|
+
return option.lazy_default
|
227
|
+
else
|
228
|
+
raise MalformattedArgumentError, "No value provided for option '#{switch}'"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
@non_assigned_required.delete(option)
|
233
|
+
send(:"parse_#{option.type}", switch)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rake/dsl_definition"
|
3
|
+
|
4
|
+
class Thor
|
5
|
+
# Adds a compatibility layer to your Thor classes which allows you to use
|
6
|
+
# rake package tasks. For example, to use rspec rake tasks, one can do:
|
7
|
+
#
|
8
|
+
# require 'thor/rake_compat'
|
9
|
+
# require 'rspec/core/rake_task'
|
10
|
+
#
|
11
|
+
# class Default < Thor
|
12
|
+
# include Thor::RakeCompat
|
13
|
+
#
|
14
|
+
# RSpec::Core::RakeTask.new(:spec) do |t|
|
15
|
+
# t.spec_opts = ['--options', './.rspec']
|
16
|
+
# t.spec_files = FileList['spec/**/*_spec.rb']
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
module RakeCompat
|
21
|
+
include Rake::DSL if defined?(Rake::DSL)
|
22
|
+
|
23
|
+
def self.rake_classes
|
24
|
+
@rake_classes ||= []
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.included(base)
|
28
|
+
super(base)
|
29
|
+
# Hack. Make rakefile point to invoker, so rdoc task is generated properly.
|
30
|
+
rakefile = File.basename(caller[0].match(/(.*):\d+/)[1])
|
31
|
+
Rake.application.instance_variable_set(:@rakefile, rakefile)
|
32
|
+
rake_classes << base
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# override task on (main), for compatibility with Rake 0.9
|
38
|
+
instance_eval do
|
39
|
+
alias rake_namespace namespace
|
40
|
+
|
41
|
+
def task(*)
|
42
|
+
task = super
|
43
|
+
|
44
|
+
if klass = Thor::RakeCompat.rake_classes.last # rubocop:disable AssignmentInCondition
|
45
|
+
non_namespaced_name = task.name.split(":").last
|
46
|
+
|
47
|
+
description = non_namespaced_name
|
48
|
+
description << task.arg_names.map { |n| n.to_s.upcase }.join(" ")
|
49
|
+
description.strip!
|
50
|
+
|
51
|
+
klass.desc description, Rake.application.last_description || non_namespaced_name
|
52
|
+
Rake.application.last_description = nil
|
53
|
+
klass.send :define_method, non_namespaced_name do |*args|
|
54
|
+
Rake::Task[task.name.to_sym].invoke(*args)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
task
|
59
|
+
end
|
60
|
+
|
61
|
+
def namespace(name)
|
62
|
+
if klass = Thor::RakeCompat.rake_classes.last # rubocop:disable AssignmentInCondition
|
63
|
+
const_name = Thor::Util.camel_case(name.to_s).to_sym
|
64
|
+
klass.const_set(const_name, Class.new(Thor))
|
65
|
+
new_klass = klass.const_get(const_name)
|
66
|
+
Thor::RakeCompat.rake_classes << new_klass
|
67
|
+
end
|
68
|
+
|
69
|
+
super
|
70
|
+
Thor::RakeCompat.rake_classes.pop
|
71
|
+
end
|
72
|
+
end
|