github_cli 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +4 -1
- data/github_cli.gemspec +3 -1
- data/lib/github_cli/dsl.rb +7 -3
- data/lib/github_cli/thor_ext.rb +1 -3
- data/lib/github_cli/vendor/thor/actions/create_file.rb +105 -0
- data/lib/github_cli/vendor/thor/actions/create_link.rb +57 -0
- data/lib/github_cli/vendor/thor/actions/directory.rb +98 -0
- data/lib/github_cli/vendor/thor/actions/empty_directory.rb +153 -0
- data/lib/github_cli/vendor/thor/actions/file_manipulation.rb +308 -0
- data/lib/github_cli/vendor/thor/actions/inject_into_file.rb +109 -0
- data/lib/github_cli/vendor/thor/actions.rb +318 -0
- data/lib/github_cli/vendor/thor/base.rb +641 -0
- data/lib/github_cli/vendor/thor/core_ext/dir_escape.rb +0 -0
- data/lib/github_cli/vendor/thor/core_ext/file_binary_read.rb +9 -0
- data/lib/github_cli/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/lib/github_cli/vendor/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/github_cli/vendor/thor/empty.txt +0 -0
- data/lib/github_cli/vendor/thor/error.rb +35 -0
- data/lib/github_cli/vendor/thor/group.rb +285 -0
- data/lib/github_cli/vendor/thor/invocation.rb +170 -0
- data/lib/github_cli/vendor/thor/parser/argument.rb +74 -0
- data/lib/github_cli/vendor/thor/parser/arguments.rb +171 -0
- data/lib/github_cli/vendor/thor/parser/option.rb +121 -0
- data/lib/github_cli/vendor/thor/parser/options.rb +178 -0
- data/lib/github_cli/vendor/thor/parser.rb +4 -0
- data/lib/github_cli/vendor/thor/rake_compat.rb +71 -0
- data/lib/github_cli/vendor/thor/runner.rb +321 -0
- data/lib/github_cli/vendor/thor/shell/basic.rb +389 -0
- data/lib/github_cli/vendor/thor/shell/color.rb +144 -0
- data/lib/github_cli/vendor/thor/shell/html.rb +123 -0
- data/lib/github_cli/vendor/thor/shell.rb +88 -0
- data/lib/github_cli/vendor/thor/task.rb +132 -0
- data/lib/github_cli/vendor/thor/util.rb +266 -0
- data/lib/github_cli/vendor/thor/version.rb +3 -0
- data/lib/github_cli/vendor/thor.rb +379 -0
- data/lib/github_cli/vendor.rb +7 -5
- data/lib/github_cli/version.rb +3 -1
- metadata +45 -22
- data/bin/ghc +0 -2
@@ -0,0 +1,74 @@
|
|
1
|
+
class Thor
|
2
|
+
class Argument #:nodoc:
|
3
|
+
VALID_TYPES = [ :numeric, :hash, :array, :string ]
|
4
|
+
|
5
|
+
attr_reader :name, :description, :enum, :required, :type, :default, :banner
|
6
|
+
alias :human_name :name
|
7
|
+
|
8
|
+
def initialize(name, options={})
|
9
|
+
class_name = self.class.name.split("::").last
|
10
|
+
|
11
|
+
type = options[:type]
|
12
|
+
|
13
|
+
raise ArgumentError, "#{class_name} name can't be nil." if name.nil?
|
14
|
+
raise ArgumentError, "Type :#{type} is not valid for #{class_name.downcase}s." if type && !valid_type?(type)
|
15
|
+
|
16
|
+
@name = name.to_s
|
17
|
+
@description = options[:desc]
|
18
|
+
@required = options.key?(:required) ? options[:required] : true
|
19
|
+
@type = (type || :string).to_sym
|
20
|
+
@default = options[:default]
|
21
|
+
@banner = options[:banner] || default_banner
|
22
|
+
@enum = options[:enum]
|
23
|
+
|
24
|
+
validate! # Trigger specific validations
|
25
|
+
end
|
26
|
+
|
27
|
+
def usage
|
28
|
+
required? ? banner : "[#{banner}]"
|
29
|
+
end
|
30
|
+
|
31
|
+
def required?
|
32
|
+
required
|
33
|
+
end
|
34
|
+
|
35
|
+
def show_default?
|
36
|
+
case default
|
37
|
+
when Array, String, Hash
|
38
|
+
!default.empty?
|
39
|
+
else
|
40
|
+
default
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def validate!
|
47
|
+
if required? && !default.nil?
|
48
|
+
raise ArgumentError, "An argument cannot be required and have default value."
|
49
|
+
elsif @enum && !@enum.is_a?(Array)
|
50
|
+
raise ArgumentError, "An argument cannot have an enum other than an array."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid_type?(type)
|
55
|
+
self.class::VALID_TYPES.include?(type.to_sym)
|
56
|
+
end
|
57
|
+
|
58
|
+
def default_banner
|
59
|
+
case type
|
60
|
+
when :boolean
|
61
|
+
nil
|
62
|
+
when :string, :default
|
63
|
+
human_name.upcase
|
64
|
+
when :numeric
|
65
|
+
"N"
|
66
|
+
when :hash
|
67
|
+
"key:value"
|
68
|
+
when :array
|
69
|
+
"one two three"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
class Thor
|
2
|
+
class Arguments #:nodoc:
|
3
|
+
NUMERIC = /(\d*\.\d+|\d+)/
|
4
|
+
|
5
|
+
# Receives an array of args and returns two arrays, one with arguments
|
6
|
+
# and one with switches.
|
7
|
+
#
|
8
|
+
def self.split(args)
|
9
|
+
arguments = []
|
10
|
+
|
11
|
+
args.each do |item|
|
12
|
+
break if item =~ /^-/
|
13
|
+
arguments << item
|
14
|
+
end
|
15
|
+
|
16
|
+
return arguments, args[Range.new(arguments.size, -1)]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.parse(*args)
|
20
|
+
to_parse = args.pop
|
21
|
+
new(*args).parse(to_parse)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Takes an array of Thor::Argument objects.
|
25
|
+
#
|
26
|
+
def initialize(arguments=[])
|
27
|
+
@assigns, @non_assigned_required = {}, []
|
28
|
+
@switches = arguments
|
29
|
+
|
30
|
+
arguments.each do |argument|
|
31
|
+
if argument.default != nil
|
32
|
+
@assigns[argument.human_name] = argument.default
|
33
|
+
elsif argument.required?
|
34
|
+
@non_assigned_required << argument
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse(args)
|
40
|
+
@pile = args.dup
|
41
|
+
|
42
|
+
@switches.each do |argument|
|
43
|
+
break unless peek
|
44
|
+
@non_assigned_required.delete(argument)
|
45
|
+
@assigns[argument.human_name] = send(:"parse_#{argument.type}", argument.human_name)
|
46
|
+
end
|
47
|
+
|
48
|
+
check_requirement!
|
49
|
+
@assigns
|
50
|
+
end
|
51
|
+
|
52
|
+
def remaining
|
53
|
+
@pile
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def no_or_skip?(arg)
|
59
|
+
arg =~ /^--(no|skip)-([-\w]+)$/
|
60
|
+
$2
|
61
|
+
end
|
62
|
+
|
63
|
+
def last?
|
64
|
+
@pile.empty?
|
65
|
+
end
|
66
|
+
|
67
|
+
def peek
|
68
|
+
@pile.first
|
69
|
+
end
|
70
|
+
|
71
|
+
def shift
|
72
|
+
@pile.shift
|
73
|
+
end
|
74
|
+
|
75
|
+
def unshift(arg)
|
76
|
+
unless arg.kind_of?(Array)
|
77
|
+
@pile.unshift(arg)
|
78
|
+
else
|
79
|
+
@pile = arg + @pile
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def current_is_value?
|
84
|
+
peek && peek.to_s !~ /^-/
|
85
|
+
end
|
86
|
+
|
87
|
+
# Runs through the argument array getting strings that contains ":" and
|
88
|
+
# mark it as a hash:
|
89
|
+
#
|
90
|
+
# [ "name:string", "age:integer" ]
|
91
|
+
#
|
92
|
+
# Becomes:
|
93
|
+
#
|
94
|
+
# { "name" => "string", "age" => "integer" }
|
95
|
+
#
|
96
|
+
def parse_hash(name)
|
97
|
+
return shift if peek.is_a?(Hash)
|
98
|
+
hash = {}
|
99
|
+
|
100
|
+
while current_is_value? && peek.include?(?:)
|
101
|
+
key, value = shift.split(':',2)
|
102
|
+
hash[key] = value
|
103
|
+
end
|
104
|
+
hash
|
105
|
+
end
|
106
|
+
|
107
|
+
# Runs through the argument array getting all strings until no string is
|
108
|
+
# found or a switch is found.
|
109
|
+
#
|
110
|
+
# ["a", "b", "c"]
|
111
|
+
#
|
112
|
+
# And returns it as an array:
|
113
|
+
#
|
114
|
+
# ["a", "b", "c"]
|
115
|
+
#
|
116
|
+
def parse_array(name)
|
117
|
+
return shift if peek.is_a?(Array)
|
118
|
+
array = []
|
119
|
+
|
120
|
+
while current_is_value?
|
121
|
+
array << shift
|
122
|
+
end
|
123
|
+
array
|
124
|
+
end
|
125
|
+
|
126
|
+
# Check if the peek is numeric format and return a Float or Integer.
|
127
|
+
# Otherwise raises an error.
|
128
|
+
#
|
129
|
+
def parse_numeric(name)
|
130
|
+
return shift if peek.is_a?(Numeric)
|
131
|
+
|
132
|
+
unless peek =~ NUMERIC && $& == peek
|
133
|
+
raise MalformattedArgumentError, "Expected numeric value for '#{name}'; got #{peek.inspect}"
|
134
|
+
end
|
135
|
+
|
136
|
+
$&.index('.') ? shift.to_f : shift.to_i
|
137
|
+
end
|
138
|
+
|
139
|
+
# Parse string:
|
140
|
+
# for --string-arg, just return the current value in the pile
|
141
|
+
# for --no-string-arg, nil
|
142
|
+
#
|
143
|
+
def parse_string(name)
|
144
|
+
if no_or_skip?(name)
|
145
|
+
nil
|
146
|
+
else
|
147
|
+
value = shift
|
148
|
+
if @switches.is_a?(Hash) && switch = @switches[name]
|
149
|
+
if switch.enum && !switch.enum.include?(value)
|
150
|
+
raise MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
value
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Raises an error if @non_assigned_required array is not empty.
|
158
|
+
#
|
159
|
+
def check_requirement!
|
160
|
+
unless @non_assigned_required.empty?
|
161
|
+
names = @non_assigned_required.map do |o|
|
162
|
+
o.respond_to?(:switch_name) ? o.switch_name : o.human_name
|
163
|
+
end.join("', '")
|
164
|
+
|
165
|
+
class_name = self.class.name.split('::').last.downcase
|
166
|
+
raise RequiredArgumentMissingError, "No value provided for required #{class_name} '#{names}'"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
class Thor
|
2
|
+
class Option < Argument #:nodoc:
|
3
|
+
attr_reader :aliases, :group, :lazy_default, :hide
|
4
|
+
|
5
|
+
VALID_TYPES = [:boolean, :numeric, :hash, :array, :string]
|
6
|
+
|
7
|
+
def initialize(name, options={})
|
8
|
+
options[:required] = false unless options.key?(:required)
|
9
|
+
super
|
10
|
+
@lazy_default = options[:lazy_default]
|
11
|
+
@group = options[:group].to_s.capitalize if options[:group]
|
12
|
+
@aliases = Array(options[:aliases])
|
13
|
+
@hide = options[:hide]
|
14
|
+
end
|
15
|
+
|
16
|
+
# This parse quick options given as method_options. It makes several
|
17
|
+
# assumptions, but you can be more specific using the option method.
|
18
|
+
#
|
19
|
+
# parse :foo => "bar"
|
20
|
+
# #=> Option foo with default value bar
|
21
|
+
#
|
22
|
+
# parse [:foo, :baz] => "bar"
|
23
|
+
# #=> Option foo with default value bar and alias :baz
|
24
|
+
#
|
25
|
+
# parse :foo => :required
|
26
|
+
# #=> Required option foo without default value
|
27
|
+
#
|
28
|
+
# parse :foo => 2
|
29
|
+
# #=> Option foo with default value 2 and type numeric
|
30
|
+
#
|
31
|
+
# parse :foo => :numeric
|
32
|
+
# #=> Option foo without default value and type numeric
|
33
|
+
#
|
34
|
+
# parse :foo => true
|
35
|
+
# #=> Option foo with default value true and type boolean
|
36
|
+
#
|
37
|
+
# The valid types are :boolean, :numeric, :hash, :array and :string. If none
|
38
|
+
# is given a default type is assumed. This default type accepts arguments as
|
39
|
+
# string (--foo=value) or booleans (just --foo).
|
40
|
+
#
|
41
|
+
# By default all options are optional, unless :required is given.
|
42
|
+
#
|
43
|
+
def self.parse(key, value)
|
44
|
+
if key.is_a?(Array)
|
45
|
+
name, *aliases = key
|
46
|
+
else
|
47
|
+
name, aliases = key, []
|
48
|
+
end
|
49
|
+
|
50
|
+
name = name.to_s
|
51
|
+
default = value
|
52
|
+
|
53
|
+
type = case value
|
54
|
+
when Symbol
|
55
|
+
default = nil
|
56
|
+
if VALID_TYPES.include?(value)
|
57
|
+
value
|
58
|
+
elsif required = (value == :required)
|
59
|
+
:string
|
60
|
+
end
|
61
|
+
when TrueClass, FalseClass
|
62
|
+
:boolean
|
63
|
+
when Numeric
|
64
|
+
:numeric
|
65
|
+
when Hash, Array, String
|
66
|
+
value.class.name.downcase.to_sym
|
67
|
+
end
|
68
|
+
self.new(name.to_s, :required => required, :type => type, :default => default, :aliases => aliases)
|
69
|
+
end
|
70
|
+
|
71
|
+
def switch_name
|
72
|
+
@switch_name ||= dasherized? ? name : dasherize(name)
|
73
|
+
end
|
74
|
+
|
75
|
+
def human_name
|
76
|
+
@human_name ||= dasherized? ? undasherize(name) : name
|
77
|
+
end
|
78
|
+
|
79
|
+
def usage(padding=0)
|
80
|
+
sample = if banner && !banner.to_s.empty?
|
81
|
+
"#{switch_name}=#{banner}"
|
82
|
+
else
|
83
|
+
switch_name
|
84
|
+
end
|
85
|
+
|
86
|
+
sample = "[#{sample}]" unless required?
|
87
|
+
|
88
|
+
if aliases.empty?
|
89
|
+
(" " * padding) << sample
|
90
|
+
else
|
91
|
+
"#{aliases.join(', ')}, #{sample}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
VALID_TYPES.each do |type|
|
96
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
97
|
+
def #{type}?
|
98
|
+
self.type == #{type.inspect}
|
99
|
+
end
|
100
|
+
RUBY
|
101
|
+
end
|
102
|
+
|
103
|
+
protected
|
104
|
+
|
105
|
+
def validate!
|
106
|
+
raise ArgumentError, "An option cannot be boolean and required." if boolean? && required?
|
107
|
+
end
|
108
|
+
|
109
|
+
def dasherized?
|
110
|
+
name.index('-') == 0
|
111
|
+
end
|
112
|
+
|
113
|
+
def undasherize(str)
|
114
|
+
str.sub(/^-{1,2}/, '')
|
115
|
+
end
|
116
|
+
|
117
|
+
def dasherize(str)
|
118
|
+
(str.length > 1 ? "--" : "-") + str.gsub('_', '-')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
class Thor
|
2
|
+
class Options < Arguments #:nodoc:
|
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
|
+
|
9
|
+
# Receives a hash and makes it switches.
|
10
|
+
def self.to_switches(options)
|
11
|
+
options.map do |key, value|
|
12
|
+
case value
|
13
|
+
when true
|
14
|
+
"--#{key}"
|
15
|
+
when Array
|
16
|
+
"--#{key} #{value.map{ |v| v.inspect }.join(' ')}"
|
17
|
+
when Hash
|
18
|
+
"--#{key} #{value.map{ |k,v| "#{k}:#{v}" }.join(' ')}"
|
19
|
+
when nil, false
|
20
|
+
""
|
21
|
+
else
|
22
|
+
"--#{key} #{value.inspect}"
|
23
|
+
end
|
24
|
+
end.join(" ")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Takes a hash of Thor::Option and a hash with defaults.
|
28
|
+
def initialize(hash_options={}, defaults={})
|
29
|
+
options = hash_options.values
|
30
|
+
super(options)
|
31
|
+
|
32
|
+
# Add defaults
|
33
|
+
defaults.each do |key, value|
|
34
|
+
@assigns[key.to_s] = value
|
35
|
+
@non_assigned_required.delete(hash_options[key])
|
36
|
+
end
|
37
|
+
|
38
|
+
@shorts, @switches, @extra = {}, {}, []
|
39
|
+
|
40
|
+
options.each do |option|
|
41
|
+
@switches[option.switch_name] = option
|
42
|
+
|
43
|
+
option.aliases.each do |short|
|
44
|
+
@shorts[short.to_s] ||= option.switch_name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def remaining
|
50
|
+
@extra
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse(args)
|
54
|
+
@pile = args.dup
|
55
|
+
|
56
|
+
while peek
|
57
|
+
match, is_switch = current_is_switch?
|
58
|
+
shifted = shift
|
59
|
+
|
60
|
+
if is_switch
|
61
|
+
case shifted
|
62
|
+
when SHORT_SQ_RE
|
63
|
+
unshift($1.split('').map { |f| "-#{f}" })
|
64
|
+
next
|
65
|
+
when EQ_RE, SHORT_NUM
|
66
|
+
unshift($2)
|
67
|
+
switch = $1
|
68
|
+
when LONG_RE, SHORT_RE
|
69
|
+
switch = $1
|
70
|
+
end
|
71
|
+
|
72
|
+
switch = normalize_switch(switch)
|
73
|
+
option = switch_option(switch)
|
74
|
+
@assigns[option.human_name] = parse_peek(switch, option)
|
75
|
+
elsif match
|
76
|
+
@extra << shifted
|
77
|
+
@extra << shift while peek && peek !~ /^-/
|
78
|
+
else
|
79
|
+
@extra << shifted
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
check_requirement!
|
84
|
+
|
85
|
+
assigns = Thor::CoreExt::HashWithIndifferentAccess.new(@assigns)
|
86
|
+
assigns.freeze
|
87
|
+
assigns
|
88
|
+
end
|
89
|
+
|
90
|
+
def check_unknown!
|
91
|
+
# an unknown option starts with - or -- and has no more --'s afterward.
|
92
|
+
unknown = @extra.select { |str| str =~ /^--?(?:(?!--).)*$/ }
|
93
|
+
raise UnknownArgumentError, "Unknown switches '#{unknown.join(', ')}'" unless unknown.empty?
|
94
|
+
end
|
95
|
+
|
96
|
+
protected
|
97
|
+
|
98
|
+
# Returns true if the current value in peek is a registered switch.
|
99
|
+
#
|
100
|
+
def current_is_switch?
|
101
|
+
case peek
|
102
|
+
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM
|
103
|
+
[true, switch?($1)]
|
104
|
+
when SHORT_SQ_RE
|
105
|
+
[true, $1.split('').any? { |f| switch?("-#{f}") }]
|
106
|
+
else
|
107
|
+
[false, false]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def current_is_switch_formatted?
|
112
|
+
case peek
|
113
|
+
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM, SHORT_SQ_RE
|
114
|
+
true
|
115
|
+
else
|
116
|
+
false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def switch?(arg)
|
121
|
+
switch_option(normalize_switch(arg))
|
122
|
+
end
|
123
|
+
|
124
|
+
def switch_option(arg)
|
125
|
+
if match = no_or_skip?(arg)
|
126
|
+
@switches[arg] || @switches["--#{match}"]
|
127
|
+
else
|
128
|
+
@switches[arg]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Check if the given argument is actually a shortcut.
|
133
|
+
#
|
134
|
+
def normalize_switch(arg)
|
135
|
+
(@shorts[arg] || arg).tr('_', '-')
|
136
|
+
end
|
137
|
+
|
138
|
+
# Parse boolean values which can be given as --foo=true, --foo or --no-foo.
|
139
|
+
#
|
140
|
+
def parse_boolean(switch)
|
141
|
+
if current_is_value?
|
142
|
+
if ["true", "TRUE", "t", "T", true].include?(peek)
|
143
|
+
shift
|
144
|
+
true
|
145
|
+
elsif ["false", "FALSE", "f", "F", false].include?(peek)
|
146
|
+
shift
|
147
|
+
false
|
148
|
+
else
|
149
|
+
true
|
150
|
+
end
|
151
|
+
else
|
152
|
+
@switches.key?(switch) || !no_or_skip?(switch)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Parse the value at the peek analyzing if it requires an input or not.
|
157
|
+
#
|
158
|
+
def parse_peek(switch, option)
|
159
|
+
if current_is_switch_formatted? || last?
|
160
|
+
if option.boolean?
|
161
|
+
# No problem for boolean types
|
162
|
+
elsif no_or_skip?(switch)
|
163
|
+
return nil # User set value to nil
|
164
|
+
elsif option.string? && !option.required?
|
165
|
+
# Return the default if there is one, else the human name
|
166
|
+
return option.lazy_default || option.default || option.human_name
|
167
|
+
elsif option.lazy_default
|
168
|
+
return option.lazy_default
|
169
|
+
else
|
170
|
+
raise MalformattedArgumentError, "No value provided for option '#{switch}'"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
@non_assigned_required.delete(option)
|
175
|
+
send(:"parse_#{option.type}", switch)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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
|
+
#
|
10
|
+
# class Default < Thor
|
11
|
+
# include Thor::RakeCompat
|
12
|
+
#
|
13
|
+
# Spec::Rake::SpecTask.new(:spec) do |t|
|
14
|
+
# t.spec_opts = ['--options', "spec/spec.opts"]
|
15
|
+
# t.spec_files = FileList['spec/**/*_spec.rb']
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
module RakeCompat
|
20
|
+
include Rake::DSL if defined?(Rake::DSL)
|
21
|
+
|
22
|
+
def self.rake_classes
|
23
|
+
@rake_classes ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.included(base)
|
27
|
+
# Hack. Make rakefile point to invoker, so rdoc task is generated properly.
|
28
|
+
rakefile = File.basename(caller[0].match(/(.*):\d+/)[1])
|
29
|
+
Rake.application.instance_variable_set(:@rakefile, rakefile)
|
30
|
+
self.rake_classes << base
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# override task on (main), for compatibility with Rake 0.9
|
36
|
+
self.instance_eval do
|
37
|
+
alias rake_namespace namespace
|
38
|
+
|
39
|
+
def task(*)
|
40
|
+
task = super
|
41
|
+
|
42
|
+
if klass = Thor::RakeCompat.rake_classes.last
|
43
|
+
non_namespaced_name = task.name.split(':').last
|
44
|
+
|
45
|
+
description = non_namespaced_name
|
46
|
+
description << task.arg_names.map{ |n| n.to_s.upcase }.join(' ')
|
47
|
+
description.strip!
|
48
|
+
|
49
|
+
klass.desc description, Rake.application.last_description || non_namespaced_name
|
50
|
+
Rake.application.last_description = nil
|
51
|
+
klass.send :define_method, non_namespaced_name do |*args|
|
52
|
+
Rake::Task[task.name.to_sym].invoke(*args)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
task
|
57
|
+
end
|
58
|
+
|
59
|
+
def namespace(name)
|
60
|
+
if klass = Thor::RakeCompat.rake_classes.last
|
61
|
+
const_name = Thor::Util.camel_case(name.to_s).to_sym
|
62
|
+
klass.const_set(const_name, Class.new(Thor))
|
63
|
+
new_klass = klass.const_get(const_name)
|
64
|
+
Thor::RakeCompat.rake_classes << new_klass
|
65
|
+
end
|
66
|
+
|
67
|
+
super
|
68
|
+
Thor::RakeCompat.rake_classes.pop
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|