github_cli 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,266 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
class Thor
|
4
|
+
module Sandbox #:nodoc:
|
5
|
+
end
|
6
|
+
|
7
|
+
# This module holds several utilities:
|
8
|
+
#
|
9
|
+
# 1) Methods to convert thor namespaces to constants and vice-versa.
|
10
|
+
#
|
11
|
+
# Thor::Util.namespace_from_thor_class(Foo::Bar::Baz) #=> "foo:bar:baz"
|
12
|
+
#
|
13
|
+
# 2) Loading thor files and sandboxing:
|
14
|
+
#
|
15
|
+
# Thor::Util.load_thorfile("~/.thor/foo")
|
16
|
+
#
|
17
|
+
module Util
|
18
|
+
|
19
|
+
# Receives a namespace and search for it in the Thor::Base subclasses.
|
20
|
+
#
|
21
|
+
# ==== Parameters
|
22
|
+
# namespace<String>:: The namespace to search for.
|
23
|
+
#
|
24
|
+
def self.find_by_namespace(namespace)
|
25
|
+
namespace = "default#{namespace}" if namespace.empty? || namespace =~ /^:/
|
26
|
+
Thor::Base.subclasses.find { |klass| klass.namespace == namespace }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Receives a constant and converts it to a Thor namespace. Since Thor tasks
|
30
|
+
# can be added to a sandbox, this method is also responsable for removing
|
31
|
+
# the sandbox namespace.
|
32
|
+
#
|
33
|
+
# This method should not be used in general because it's used to deal with
|
34
|
+
# older versions of Thor. On current versions, if you need to get the
|
35
|
+
# namespace from a class, just call namespace on it.
|
36
|
+
#
|
37
|
+
# ==== Parameters
|
38
|
+
# constant<Object>:: The constant to be converted to the thor path.
|
39
|
+
#
|
40
|
+
# ==== Returns
|
41
|
+
# String:: If we receive Foo::Bar::Baz it returns "foo:bar:baz"
|
42
|
+
#
|
43
|
+
def self.namespace_from_thor_class(constant)
|
44
|
+
constant = constant.to_s.gsub(/^Thor::Sandbox::/, "")
|
45
|
+
constant = snake_case(constant).squeeze(":")
|
46
|
+
constant
|
47
|
+
end
|
48
|
+
|
49
|
+
# Given the contents, evaluate it inside the sandbox and returns the
|
50
|
+
# namespaces defined in the sandbox.
|
51
|
+
#
|
52
|
+
# ==== Parameters
|
53
|
+
# contents<String>
|
54
|
+
#
|
55
|
+
# ==== Returns
|
56
|
+
# Array[Object]
|
57
|
+
#
|
58
|
+
def self.namespaces_in_content(contents, file=__FILE__)
|
59
|
+
old_constants = Thor::Base.subclasses.dup
|
60
|
+
Thor::Base.subclasses.clear
|
61
|
+
|
62
|
+
load_thorfile(file, contents)
|
63
|
+
|
64
|
+
new_constants = Thor::Base.subclasses.dup
|
65
|
+
Thor::Base.subclasses.replace(old_constants)
|
66
|
+
|
67
|
+
new_constants.map!{ |c| c.namespace }
|
68
|
+
new_constants.compact!
|
69
|
+
new_constants
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the thor classes declared inside the given class.
|
73
|
+
#
|
74
|
+
def self.thor_classes_in(klass)
|
75
|
+
stringfied_constants = klass.constants.map { |c| c.to_s }
|
76
|
+
Thor::Base.subclasses.select do |subclass|
|
77
|
+
next unless subclass.name
|
78
|
+
stringfied_constants.include?(subclass.name.gsub("#{klass.name}::", ''))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Receives a string and convert it to snake case. SnakeCase returns snake_case.
|
83
|
+
#
|
84
|
+
# ==== Parameters
|
85
|
+
# String
|
86
|
+
#
|
87
|
+
# ==== Returns
|
88
|
+
# String
|
89
|
+
#
|
90
|
+
def self.snake_case(str)
|
91
|
+
return str.downcase if str =~ /^[A-Z_]+$/
|
92
|
+
str.gsub(/\B[A-Z]/, '_\&').squeeze('_') =~ /_*(.*)/
|
93
|
+
return $+.downcase
|
94
|
+
end
|
95
|
+
|
96
|
+
# Receives a string and convert it to camel case. camel_case returns CamelCase.
|
97
|
+
#
|
98
|
+
# ==== Parameters
|
99
|
+
# String
|
100
|
+
#
|
101
|
+
# ==== Returns
|
102
|
+
# String
|
103
|
+
#
|
104
|
+
def self.camel_case(str)
|
105
|
+
return str if str !~ /_/ && str =~ /[A-Z]+.*/
|
106
|
+
str.split('_').map { |i| i.capitalize }.join
|
107
|
+
end
|
108
|
+
|
109
|
+
# Receives a namespace and tries to retrieve a Thor or Thor::Group class
|
110
|
+
# from it. It first searches for a class using the all the given namespace,
|
111
|
+
# if it's not found, removes the highest entry and searches for the class
|
112
|
+
# again. If found, returns the highest entry as the class name.
|
113
|
+
#
|
114
|
+
# ==== Examples
|
115
|
+
#
|
116
|
+
# class Foo::Bar < Thor
|
117
|
+
# def baz
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# class Baz::Foo < Thor::Group
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
# Thor::Util.namespace_to_thor_class("foo:bar") #=> Foo::Bar, nil # will invoke default task
|
125
|
+
# Thor::Util.namespace_to_thor_class("baz:foo") #=> Baz::Foo, nil
|
126
|
+
# Thor::Util.namespace_to_thor_class("foo:bar:baz") #=> Foo::Bar, "baz"
|
127
|
+
#
|
128
|
+
# ==== Parameters
|
129
|
+
# namespace<String>
|
130
|
+
#
|
131
|
+
def self.find_class_and_task_by_namespace(namespace, fallback = true)
|
132
|
+
if namespace.include?(?:) # look for a namespaced task
|
133
|
+
pieces = namespace.split(":")
|
134
|
+
task = pieces.pop
|
135
|
+
klass = Thor::Util.find_by_namespace(pieces.join(":"))
|
136
|
+
end
|
137
|
+
unless klass # look for a Thor::Group with the right name
|
138
|
+
klass, task = Thor::Util.find_by_namespace(namespace), nil
|
139
|
+
end
|
140
|
+
if !klass && fallback # try a task in the default namespace
|
141
|
+
task = namespace
|
142
|
+
klass = Thor::Util.find_by_namespace('')
|
143
|
+
end
|
144
|
+
return klass, task
|
145
|
+
end
|
146
|
+
|
147
|
+
# Receives a path and load the thor file in the path. The file is evaluated
|
148
|
+
# inside the sandbox to avoid namespacing conflicts.
|
149
|
+
#
|
150
|
+
def self.load_thorfile(path, content=nil, debug=false)
|
151
|
+
content ||= File.binread(path)
|
152
|
+
|
153
|
+
begin
|
154
|
+
Thor::Sandbox.class_eval(content, path)
|
155
|
+
rescue Exception => e
|
156
|
+
$stderr.puts("WARNING: unable to load thorfile #{path.inspect}: #{e.message}")
|
157
|
+
if debug
|
158
|
+
$stderr.puts(*e.backtrace)
|
159
|
+
else
|
160
|
+
$stderr.puts(e.backtrace.first)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.user_home
|
166
|
+
@@user_home ||= if ENV["HOME"]
|
167
|
+
ENV["HOME"]
|
168
|
+
elsif ENV["USERPROFILE"]
|
169
|
+
ENV["USERPROFILE"]
|
170
|
+
elsif ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
|
171
|
+
File.join(ENV["HOMEDRIVE"], ENV["HOMEPATH"])
|
172
|
+
elsif ENV["APPDATA"]
|
173
|
+
ENV["APPDATA"]
|
174
|
+
else
|
175
|
+
begin
|
176
|
+
File.expand_path("~")
|
177
|
+
rescue
|
178
|
+
if File::ALT_SEPARATOR
|
179
|
+
"C:/"
|
180
|
+
else
|
181
|
+
"/"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Returns the root where thor files are located, depending on the OS.
|
188
|
+
#
|
189
|
+
def self.thor_root
|
190
|
+
File.join(user_home, ".thor").gsub(/\\/, '/')
|
191
|
+
end
|
192
|
+
|
193
|
+
# Returns the files in the thor root. On Windows thor_root will be something
|
194
|
+
# like this:
|
195
|
+
#
|
196
|
+
# C:\Documents and Settings\james\.thor
|
197
|
+
#
|
198
|
+
# If we don't #gsub the \ character, Dir.glob will fail.
|
199
|
+
#
|
200
|
+
def self.thor_root_glob
|
201
|
+
files = Dir["#{escape_globs(thor_root)}/*"]
|
202
|
+
|
203
|
+
files.map! do |file|
|
204
|
+
File.directory?(file) ? File.join(file, "main.thor") : file
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Where to look for Thor files.
|
209
|
+
#
|
210
|
+
def self.globs_for(path)
|
211
|
+
path = escape_globs(path)
|
212
|
+
["#{path}/Thorfile", "#{path}/*.thor", "#{path}/tasks/*.thor", "#{path}/lib/tasks/*.thor"]
|
213
|
+
end
|
214
|
+
|
215
|
+
# Return the path to the ruby interpreter taking into account multiple
|
216
|
+
# installations and windows extensions.
|
217
|
+
#
|
218
|
+
def self.ruby_command
|
219
|
+
@ruby_command ||= begin
|
220
|
+
ruby_name = RbConfig::CONFIG['ruby_install_name']
|
221
|
+
ruby = File.join(RbConfig::CONFIG['bindir'], ruby_name)
|
222
|
+
ruby << RbConfig::CONFIG['EXEEXT']
|
223
|
+
|
224
|
+
# avoid using different name than ruby (on platforms supporting links)
|
225
|
+
if ruby_name != 'ruby' && File.respond_to?(:readlink)
|
226
|
+
begin
|
227
|
+
alternate_ruby = File.join(RbConfig::CONFIG['bindir'], 'ruby')
|
228
|
+
alternate_ruby << RbConfig::CONFIG['EXEEXT']
|
229
|
+
|
230
|
+
# ruby is a symlink
|
231
|
+
if File.symlink? alternate_ruby
|
232
|
+
linked_ruby = File.readlink alternate_ruby
|
233
|
+
|
234
|
+
# symlink points to 'ruby_install_name'
|
235
|
+
ruby = alternate_ruby if linked_ruby == ruby_name || linked_ruby == ruby
|
236
|
+
end
|
237
|
+
rescue NotImplementedError
|
238
|
+
# just ignore on windows
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
# escape string in case path to ruby executable contain spaces.
|
243
|
+
ruby.sub!(/.*\s.*/m, '"\&"')
|
244
|
+
ruby
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
# Returns a string that has had any glob characters escaped.
|
249
|
+
# The glob characters are `* ? { } [ ]`.
|
250
|
+
#
|
251
|
+
# ==== Examples
|
252
|
+
#
|
253
|
+
# Thor::Util.escape_globs('[apps]') # => '\[apps\]'
|
254
|
+
#
|
255
|
+
# ==== Parameters
|
256
|
+
# String
|
257
|
+
#
|
258
|
+
# ==== Returns
|
259
|
+
# String
|
260
|
+
#
|
261
|
+
def self.escape_globs(path)
|
262
|
+
path.to_s.gsub(/[*?{}\[\]]/, '\\\\\\&')
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
end
|
@@ -0,0 +1,379 @@
|
|
1
|
+
require 'thor/base'
|
2
|
+
|
3
|
+
class Thor
|
4
|
+
class << self
|
5
|
+
# Sets the default task when thor is executed without an explicit task to be called.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# meth<Symbol>:: name of the default task
|
9
|
+
#
|
10
|
+
def default_task(meth=nil)
|
11
|
+
case meth
|
12
|
+
when :none
|
13
|
+
@default_task = 'help'
|
14
|
+
when nil
|
15
|
+
@default_task ||= from_superclass(:default_task, 'help')
|
16
|
+
else
|
17
|
+
@default_task = meth.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Registers another Thor subclass as a command.
|
22
|
+
#
|
23
|
+
# ==== Parameters
|
24
|
+
# klass<Class>:: Thor subclass to register
|
25
|
+
# command<String>:: Subcommand name to use
|
26
|
+
# usage<String>:: Short usage for the subcommand
|
27
|
+
# description<String>:: Description for the subcommand
|
28
|
+
def register(klass, subcommand_name, usage, description, options={})
|
29
|
+
if klass <= Thor::Group
|
30
|
+
desc usage, description, options
|
31
|
+
define_method(subcommand_name) { |*args| invoke(klass, args) }
|
32
|
+
else
|
33
|
+
desc usage, description, options
|
34
|
+
subcommand subcommand_name, klass
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Defines the usage and the description of the next task.
|
39
|
+
#
|
40
|
+
# ==== Parameters
|
41
|
+
# usage<String>
|
42
|
+
# description<String>
|
43
|
+
# options<String>
|
44
|
+
#
|
45
|
+
def desc(usage, description, options={})
|
46
|
+
if options[:for]
|
47
|
+
task = find_and_refresh_task(options[:for])
|
48
|
+
task.usage = usage if usage
|
49
|
+
task.description = description if description
|
50
|
+
else
|
51
|
+
@usage, @desc, @hide = usage, description, options[:hide] || false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Defines the long description of the next task.
|
56
|
+
#
|
57
|
+
# ==== Parameters
|
58
|
+
# long description<String>
|
59
|
+
#
|
60
|
+
def long_desc(long_description, options={})
|
61
|
+
if options[:for]
|
62
|
+
task = find_and_refresh_task(options[:for])
|
63
|
+
task.long_description = long_description if long_description
|
64
|
+
else
|
65
|
+
@long_desc = long_description
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Maps an input to a task. If you define:
|
70
|
+
#
|
71
|
+
# map "-T" => "list"
|
72
|
+
#
|
73
|
+
# Running:
|
74
|
+
#
|
75
|
+
# thor -T
|
76
|
+
#
|
77
|
+
# Will invoke the list task.
|
78
|
+
#
|
79
|
+
# ==== Parameters
|
80
|
+
# Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given task.
|
81
|
+
#
|
82
|
+
def map(mappings=nil)
|
83
|
+
@map ||= from_superclass(:map, {})
|
84
|
+
|
85
|
+
if mappings
|
86
|
+
mappings.each do |key, value|
|
87
|
+
if key.respond_to?(:each)
|
88
|
+
key.each {|subkey| @map[subkey] = value}
|
89
|
+
else
|
90
|
+
@map[key] = value
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
@map
|
96
|
+
end
|
97
|
+
|
98
|
+
# Declares the options for the next task to be declared.
|
99
|
+
#
|
100
|
+
# ==== Parameters
|
101
|
+
# Hash[Symbol => Object]:: The hash key is the name of the option and the value
|
102
|
+
# is the type of the option. Can be :string, :array, :hash, :boolean, :numeric
|
103
|
+
# or :required (string). If you give a value, the type of the value is used.
|
104
|
+
#
|
105
|
+
def method_options(options=nil)
|
106
|
+
@method_options ||= {}
|
107
|
+
build_options(options, @method_options) if options
|
108
|
+
@method_options
|
109
|
+
end
|
110
|
+
|
111
|
+
alias options method_options
|
112
|
+
|
113
|
+
# Adds an option to the set of method options. If :for is given as option,
|
114
|
+
# it allows you to change the options from a previous defined task.
|
115
|
+
#
|
116
|
+
# def previous_task
|
117
|
+
# # magic
|
118
|
+
# end
|
119
|
+
#
|
120
|
+
# method_option :foo => :bar, :for => :previous_task
|
121
|
+
#
|
122
|
+
# def next_task
|
123
|
+
# # magic
|
124
|
+
# end
|
125
|
+
#
|
126
|
+
# ==== Parameters
|
127
|
+
# name<Symbol>:: The name of the argument.
|
128
|
+
# options<Hash>:: Described below.
|
129
|
+
#
|
130
|
+
# ==== Options
|
131
|
+
# :desc - Description for the argument.
|
132
|
+
# :required - If the argument is required or not.
|
133
|
+
# :default - Default value for this argument. It cannot be required and have default values.
|
134
|
+
# :aliases - Aliases for this option.
|
135
|
+
# :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
|
136
|
+
# :banner - String to show on usage notes.
|
137
|
+
# :hide - If you want to hide this option from the help.
|
138
|
+
#
|
139
|
+
def method_option(name, options={})
|
140
|
+
scope = if options[:for]
|
141
|
+
find_and_refresh_task(options[:for]).options
|
142
|
+
else
|
143
|
+
method_options
|
144
|
+
end
|
145
|
+
|
146
|
+
build_option(name, options, scope)
|
147
|
+
end
|
148
|
+
|
149
|
+
alias option method_option
|
150
|
+
|
151
|
+
# Prints help information for the given task.
|
152
|
+
#
|
153
|
+
# ==== Parameters
|
154
|
+
# shell<Thor::Shell>
|
155
|
+
# task_name<String>
|
156
|
+
#
|
157
|
+
def task_help(shell, task_name)
|
158
|
+
meth = normalize_task_name(task_name)
|
159
|
+
task = all_tasks[meth]
|
160
|
+
handle_no_task_error(meth) unless task
|
161
|
+
|
162
|
+
shell.say "Usage:"
|
163
|
+
shell.say " #{banner(task)}"
|
164
|
+
shell.say
|
165
|
+
class_options_help(shell, nil => task.options.map { |_, o| o })
|
166
|
+
if task.long_description
|
167
|
+
shell.say "Description:"
|
168
|
+
shell.print_wrapped(task.long_description, :indent => 2)
|
169
|
+
else
|
170
|
+
shell.say task.description
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# Prints help information for this class.
|
175
|
+
#
|
176
|
+
# ==== Parameters
|
177
|
+
# shell<Thor::Shell>
|
178
|
+
#
|
179
|
+
def help(shell, subcommand = false)
|
180
|
+
list = printable_tasks(true, subcommand)
|
181
|
+
Thor::Util.thor_classes_in(self).each do |klass|
|
182
|
+
list += klass.printable_tasks(false)
|
183
|
+
end
|
184
|
+
list.sort!{ |a,b| a[0] <=> b[0] }
|
185
|
+
|
186
|
+
shell.say "Tasks:"
|
187
|
+
shell.print_table(list, :indent => 2, :truncate => true)
|
188
|
+
shell.say
|
189
|
+
class_options_help(shell)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Returns tasks ready to be printed.
|
193
|
+
def printable_tasks(all = true, subcommand = false)
|
194
|
+
(all ? all_tasks : tasks).map do |_, task|
|
195
|
+
next if task.hidden?
|
196
|
+
item = []
|
197
|
+
item << banner(task, false, subcommand)
|
198
|
+
item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "")
|
199
|
+
item
|
200
|
+
end.compact
|
201
|
+
end
|
202
|
+
|
203
|
+
def subcommands
|
204
|
+
@subcommands ||= from_superclass(:subcommands, [])
|
205
|
+
end
|
206
|
+
|
207
|
+
def subcommand(subcommand, subcommand_class)
|
208
|
+
self.subcommands << subcommand.to_s
|
209
|
+
subcommand_class.subcommand_help subcommand
|
210
|
+
|
211
|
+
define_method(subcommand) do |*args|
|
212
|
+
args, opts = Thor::Arguments.split(args)
|
213
|
+
invoke subcommand_class, args, opts
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
# Extend check unknown options to accept a hash of conditions.
|
218
|
+
#
|
219
|
+
# === Parameters
|
220
|
+
# options<Hash>: A hash containing :only and/or :except keys
|
221
|
+
def check_unknown_options!(options={})
|
222
|
+
@check_unknown_options ||= Hash.new
|
223
|
+
options.each do |key, value|
|
224
|
+
if value
|
225
|
+
@check_unknown_options[key] = Array(value)
|
226
|
+
else
|
227
|
+
@check_unknown_options.delete(key)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
@check_unknown_options
|
231
|
+
end
|
232
|
+
|
233
|
+
# Overwrite check_unknown_options? to take subcommands and options into account.
|
234
|
+
def check_unknown_options?(config) #:nodoc:
|
235
|
+
options = check_unknown_options
|
236
|
+
return false unless options
|
237
|
+
|
238
|
+
task = config[:current_task]
|
239
|
+
return true unless task
|
240
|
+
|
241
|
+
name = task.name
|
242
|
+
|
243
|
+
if subcommands.include?(name)
|
244
|
+
false
|
245
|
+
elsif options[:except]
|
246
|
+
!options[:except].include?(name.to_sym)
|
247
|
+
elsif options[:only]
|
248
|
+
options[:only].include?(name.to_sym)
|
249
|
+
else
|
250
|
+
true
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
protected
|
255
|
+
|
256
|
+
# The method responsible for dispatching given the args.
|
257
|
+
def dispatch(meth, given_args, given_opts, config) #:nodoc:
|
258
|
+
meth ||= retrieve_task_name(given_args)
|
259
|
+
task = all_tasks[normalize_task_name(meth)]
|
260
|
+
|
261
|
+
if task
|
262
|
+
args, opts = Thor::Options.split(given_args)
|
263
|
+
else
|
264
|
+
args, opts = given_args, nil
|
265
|
+
task = Thor::DynamicTask.new(meth)
|
266
|
+
end
|
267
|
+
|
268
|
+
opts = given_opts || opts || []
|
269
|
+
config.merge!(:current_task => task, :task_options => task.options)
|
270
|
+
|
271
|
+
instance = new(args, opts, config)
|
272
|
+
yield instance if block_given?
|
273
|
+
args = instance.args
|
274
|
+
trailing = args[Range.new(arguments.size, -1)]
|
275
|
+
instance.invoke_task(task, trailing || [])
|
276
|
+
end
|
277
|
+
|
278
|
+
# The banner for this class. You can customize it if you are invoking the
|
279
|
+
# thor class by another ways which is not the Thor::Runner. It receives
|
280
|
+
# the task that is going to be invoked and a boolean which indicates if
|
281
|
+
# the namespace should be displayed as arguments.
|
282
|
+
#
|
283
|
+
def banner(task, namespace = nil, subcommand = false)
|
284
|
+
"#{basename} #{task.formatted_usage(self, $thor_runner, subcommand)}"
|
285
|
+
end
|
286
|
+
|
287
|
+
def baseclass #:nodoc:
|
288
|
+
Thor
|
289
|
+
end
|
290
|
+
|
291
|
+
def create_task(meth) #:nodoc:
|
292
|
+
if @usage && @desc
|
293
|
+
base_class = @hide ? Thor::HiddenTask : Thor::Task
|
294
|
+
tasks[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
|
295
|
+
@usage, @desc, @long_desc, @method_options, @hide = nil
|
296
|
+
true
|
297
|
+
elsif self.all_tasks[meth] || meth == "method_missing"
|
298
|
+
true
|
299
|
+
else
|
300
|
+
puts "[WARNING] Attempted to create task #{meth.inspect} without usage or description. " <<
|
301
|
+
"Call desc if you want this method to be available as task or declare it inside a " <<
|
302
|
+
"no_tasks{} block. Invoked from #{caller[1].inspect}."
|
303
|
+
false
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def initialize_added #:nodoc:
|
308
|
+
class_options.merge!(method_options)
|
309
|
+
@method_options = nil
|
310
|
+
end
|
311
|
+
|
312
|
+
# Retrieve the task name from given args.
|
313
|
+
def retrieve_task_name(args) #:nodoc:
|
314
|
+
meth = args.first.to_s unless args.empty?
|
315
|
+
if meth && (map[meth] || meth !~ /^\-/)
|
316
|
+
args.shift
|
317
|
+
else
|
318
|
+
nil
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
# receives a (possibly nil) task name and returns a name that is in
|
323
|
+
# the tasks hash. In addition to normalizing aliases, this logic
|
324
|
+
# will determine if a shortened command is an unambiguous substring of
|
325
|
+
# a task or alias.
|
326
|
+
#
|
327
|
+
# +normalize_task_name+ also converts names like +animal-prison+
|
328
|
+
# into +animal_prison+.
|
329
|
+
def normalize_task_name(meth) #:nodoc:
|
330
|
+
return default_task.to_s.gsub('-', '_') unless meth
|
331
|
+
|
332
|
+
possibilities = find_task_possibilities(meth)
|
333
|
+
if possibilities.size > 1
|
334
|
+
raise ArgumentError, "Ambiguous task #{meth} matches [#{possibilities.join(', ')}]"
|
335
|
+
elsif possibilities.size < 1
|
336
|
+
meth = meth || default_task
|
337
|
+
elsif map[meth]
|
338
|
+
meth = map[meth]
|
339
|
+
else
|
340
|
+
meth = possibilities.first
|
341
|
+
end
|
342
|
+
|
343
|
+
meth.to_s.gsub('-','_') # treat foo-bar as foo_bar
|
344
|
+
end
|
345
|
+
|
346
|
+
# this is the logic that takes the task name passed in by the user
|
347
|
+
# and determines whether it is an unambiguous substrings of a task or
|
348
|
+
# alias name.
|
349
|
+
def find_task_possibilities(meth)
|
350
|
+
len = meth.to_s.length
|
351
|
+
possibilities = all_tasks.merge(map).keys.select { |n| meth == n[0, len] }.sort
|
352
|
+
unique_possibilities = possibilities.map { |k| map[k] || k }.uniq
|
353
|
+
|
354
|
+
if possibilities.include?(meth)
|
355
|
+
[meth]
|
356
|
+
elsif unique_possibilities.size == 1
|
357
|
+
unique_possibilities
|
358
|
+
else
|
359
|
+
possibilities
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def subcommand_help(cmd)
|
364
|
+
desc "help [COMMAND]", "Describe subcommands or one specific subcommand"
|
365
|
+
class_eval <<-RUBY
|
366
|
+
def help(task = nil, subcommand = true); super; end
|
367
|
+
RUBY
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
include Thor::Base
|
372
|
+
|
373
|
+
map HELP_MAPPINGS => :help
|
374
|
+
|
375
|
+
desc "help [TASK]", "Describe available tasks or one specific task"
|
376
|
+
def help(task = nil, subcommand = false)
|
377
|
+
task ? self.class.task_help(shell, task) : self.class.help(shell, subcommand)
|
378
|
+
end
|
379
|
+
end
|
data/lib/github_cli/vendor.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift File.join(dir, 'lib')
|
3
|
+
if defined?(Thor)
|
4
|
+
GithubCLI.ui.warn "Thor has already been required. "
|
6
5
|
end
|
7
|
-
|
6
|
+
|
7
|
+
vendor_dir = File.expand_path('../vendor', __FILE__)
|
8
|
+
$:.unshift(vendor_dir) unless $:.include?(vendor_dir)
|
8
9
|
|
9
10
|
require 'thor'
|
10
11
|
require 'thor/group'
|
12
|
+
require 'thor/actions'
|
data/lib/github_cli/version.rb
CHANGED