rkh-bundler 1.2.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/.travis.yml +42 -0
- data/CHANGELOG.md +1105 -0
- data/ISSUES.md +67 -0
- data/LICENSE +23 -0
- data/README.md +31 -0
- data/Rakefile +208 -0
- data/UPGRADING.md +103 -0
- data/bin/bundle +31 -0
- data/bundler.gemspec +31 -0
- data/lib/bundler.rb +353 -0
- data/lib/bundler/capistrano.rb +11 -0
- data/lib/bundler/cli.rb +693 -0
- data/lib/bundler/definition.rb +568 -0
- data/lib/bundler/dep_proxy.rb +43 -0
- data/lib/bundler/dependency.rb +134 -0
- data/lib/bundler/deployment.rb +58 -0
- data/lib/bundler/dsl.rb +256 -0
- data/lib/bundler/endpoint_specification.rb +78 -0
- data/lib/bundler/environment.rb +47 -0
- data/lib/bundler/fetcher.rb +225 -0
- data/lib/bundler/gem_helper.rb +162 -0
- data/lib/bundler/gem_helpers.rb +23 -0
- data/lib/bundler/gem_installer.rb +9 -0
- data/lib/bundler/gem_tasks.rb +2 -0
- data/lib/bundler/graph.rb +148 -0
- data/lib/bundler/index.rb +187 -0
- data/lib/bundler/installer.rb +190 -0
- data/lib/bundler/lazy_specification.rb +79 -0
- data/lib/bundler/lockfile_parser.rb +127 -0
- data/lib/bundler/match_platform.rb +13 -0
- data/lib/bundler/psyched_yaml.rb +15 -0
- data/lib/bundler/remote_specification.rb +57 -0
- data/lib/bundler/resolver.rb +486 -0
- data/lib/bundler/ruby_version.rb +94 -0
- data/lib/bundler/rubygems_ext.rb +153 -0
- data/lib/bundler/rubygems_integration.rb +394 -0
- data/lib/bundler/runtime.rb +233 -0
- data/lib/bundler/settings.rb +128 -0
- data/lib/bundler/setup.rb +23 -0
- data/lib/bundler/shared_helpers.rb +71 -0
- data/lib/bundler/source.rb +869 -0
- data/lib/bundler/spec_set.rb +137 -0
- data/lib/bundler/templates/Executable +16 -0
- data/lib/bundler/templates/Executable.standalone +12 -0
- data/lib/bundler/templates/Gemfile +4 -0
- data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
- data/lib/bundler/templates/newgem/LICENSE.tt +22 -0
- data/lib/bundler/templates/newgem/README.md.tt +29 -0
- data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
- data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
- data/lib/bundler/templates/newgem/gitignore.tt +17 -0
- data/lib/bundler/templates/newgem/lib/newgem.rb.tt +9 -0
- data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
- data/lib/bundler/templates/newgem/newgem.gemspec.tt +17 -0
- data/lib/bundler/ui.rb +88 -0
- data/lib/bundler/vendor/net/http/faster.rb +27 -0
- data/lib/bundler/vendor/net/http/persistent.rb +468 -0
- data/lib/bundler/vendor/thor.rb +358 -0
- data/lib/bundler/vendor/thor/actions.rb +314 -0
- data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
- data/lib/bundler/vendor/thor/actions/create_link.rb +57 -0
- data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
- data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
- data/lib/bundler/vendor/thor/actions/file_manipulation.rb +270 -0
- data/lib/bundler/vendor/thor/actions/inject_into_file.rb +109 -0
- data/lib/bundler/vendor/thor/base.rb +576 -0
- data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
- data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/bundler/vendor/thor/error.rb +30 -0
- data/lib/bundler/vendor/thor/group.rb +273 -0
- data/lib/bundler/vendor/thor/invocation.rb +168 -0
- data/lib/bundler/vendor/thor/parser.rb +4 -0
- data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
- data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
- data/lib/bundler/vendor/thor/parser/option.rb +120 -0
- data/lib/bundler/vendor/thor/parser/options.rb +172 -0
- data/lib/bundler/vendor/thor/rake_compat.rb +66 -0
- data/lib/bundler/vendor/thor/runner.rb +309 -0
- data/lib/bundler/vendor/thor/shell.rb +88 -0
- data/lib/bundler/vendor/thor/shell/basic.rb +302 -0
- data/lib/bundler/vendor/thor/shell/color.rb +108 -0
- data/lib/bundler/vendor/thor/shell/html.rb +121 -0
- data/lib/bundler/vendor/thor/task.rb +113 -0
- data/lib/bundler/vendor/thor/util.rb +229 -0
- data/lib/bundler/vendor/thor/version.rb +3 -0
- data/lib/bundler/vendored_thor.rb +7 -0
- data/lib/bundler/version.rb +6 -0
- data/lib/bundler/vlad.rb +11 -0
- data/man/bundle-config.ronn +130 -0
- data/man/bundle-exec.ronn +111 -0
- data/man/bundle-install.ronn +335 -0
- data/man/bundle-package.ronn +59 -0
- data/man/bundle-update.ronn +176 -0
- data/man/bundle.ronn +83 -0
- data/man/gemfile.5.ronn +324 -0
- data/man/index.txt +6 -0
- data/spec/bundler/dsl_spec.rb +48 -0
- data/spec/bundler/gem_helper_spec.rb +174 -0
- data/spec/bundler/source_spec.rb +25 -0
- data/spec/cache/gems_spec.rb +239 -0
- data/spec/cache/git_spec.rb +124 -0
- data/spec/cache/path_spec.rb +103 -0
- data/spec/cache/platform_spec.rb +57 -0
- data/spec/install/deploy_spec.rb +211 -0
- data/spec/install/gems/c_ext_spec.rb +48 -0
- data/spec/install/gems/dependency_api_spec.rb +402 -0
- data/spec/install/gems/env_spec.rb +107 -0
- data/spec/install/gems/flex_spec.rb +313 -0
- data/spec/install/gems/groups_spec.rb +268 -0
- data/spec/install/gems/packed_spec.rb +84 -0
- data/spec/install/gems/platform_spec.rb +208 -0
- data/spec/install/gems/post_install_spec.rb +47 -0
- data/spec/install/gems/resolving_spec.rb +72 -0
- data/spec/install/gems/simple_case_spec.rb +814 -0
- data/spec/install/gems/standalone_spec.rb +260 -0
- data/spec/install/gems/sudo_spec.rb +74 -0
- data/spec/install/gems/win32_spec.rb +26 -0
- data/spec/install/gemspec_spec.rb +170 -0
- data/spec/install/git_spec.rb +796 -0
- data/spec/install/invalid_spec.rb +35 -0
- data/spec/install/path_spec.rb +405 -0
- data/spec/install/upgrade_spec.rb +26 -0
- data/spec/lock/git_spec.rb +35 -0
- data/spec/lock/lockfile_spec.rb +809 -0
- data/spec/other/check_spec.rb +265 -0
- data/spec/other/clean_spec.rb +492 -0
- data/spec/other/config_spec.rb +138 -0
- data/spec/other/console_spec.rb +54 -0
- data/spec/other/exec_spec.rb +229 -0
- data/spec/other/ext_spec.rb +37 -0
- data/spec/other/help_spec.rb +39 -0
- data/spec/other/init_spec.rb +40 -0
- data/spec/other/newgem_spec.rb +87 -0
- data/spec/other/open_spec.rb +35 -0
- data/spec/other/outdated_spec.rb +93 -0
- data/spec/other/platform_spec.rb +881 -0
- data/spec/other/show_spec.rb +88 -0
- data/spec/quality_spec.rb +62 -0
- data/spec/realworld/edgecases_spec.rb +177 -0
- data/spec/resolver/basic_spec.rb +20 -0
- data/spec/resolver/platform_spec.rb +82 -0
- data/spec/runtime/executable_spec.rb +120 -0
- data/spec/runtime/load_spec.rb +107 -0
- data/spec/runtime/platform_spec.rb +90 -0
- data/spec/runtime/require_spec.rb +261 -0
- data/spec/runtime/setup_spec.rb +755 -0
- data/spec/runtime/with_clean_env_spec.rb +80 -0
- data/spec/spec_helper.rb +98 -0
- data/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +13 -0
- data/spec/support/artifice/endpoint.rb +54 -0
- data/spec/support/artifice/endpoint_500.rb +37 -0
- data/spec/support/artifice/endpoint_api_missing.rb +16 -0
- data/spec/support/artifice/endpoint_basic_authentication.rb +13 -0
- data/spec/support/artifice/endpoint_extra.rb +27 -0
- data/spec/support/artifice/endpoint_extra_missing.rb +15 -0
- data/spec/support/artifice/endpoint_fallback.rb +18 -0
- data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
- data/spec/support/artifice/endpoint_redirect.rb +15 -0
- data/spec/support/builders.rb +604 -0
- data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
- data/spec/support/fakeweb/windows.rb +23 -0
- data/spec/support/helpers.rb +317 -0
- data/spec/support/indexes.rb +112 -0
- data/spec/support/matchers.rb +77 -0
- data/spec/support/path.rb +73 -0
- data/spec/support/platforms.rb +86 -0
- data/spec/support/ruby_ext.rb +20 -0
- data/spec/support/rubygems_ext.rb +37 -0
- data/spec/support/rubygems_hax/platform.rb +22 -0
- data/spec/support/sudo.rb +21 -0
- data/spec/update/gems_spec.rb +134 -0
- data/spec/update/git_spec.rb +196 -0
- data/spec/update/source_spec.rb +51 -0
- metadata +338 -0
@@ -0,0 +1,172 @@
|
|
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, @unknown = {}, {}, []
|
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 parse(args)
|
50
|
+
@pile = args.dup
|
51
|
+
|
52
|
+
while peek
|
53
|
+
match, is_switch = current_is_switch?
|
54
|
+
|
55
|
+
if is_switch
|
56
|
+
case shift
|
57
|
+
when SHORT_SQ_RE
|
58
|
+
unshift($1.split('').map { |f| "-#{f}" })
|
59
|
+
next
|
60
|
+
when EQ_RE, SHORT_NUM
|
61
|
+
unshift($2)
|
62
|
+
switch = $1
|
63
|
+
when LONG_RE, SHORT_RE
|
64
|
+
switch = $1
|
65
|
+
end
|
66
|
+
|
67
|
+
switch = normalize_switch(switch)
|
68
|
+
option = switch_option(switch)
|
69
|
+
@assigns[option.human_name] = parse_peek(switch, option)
|
70
|
+
elsif match
|
71
|
+
@unknown << shift
|
72
|
+
else
|
73
|
+
shift
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
check_requirement!
|
78
|
+
|
79
|
+
assigns = Thor::CoreExt::HashWithIndifferentAccess.new(@assigns)
|
80
|
+
assigns.freeze
|
81
|
+
assigns
|
82
|
+
end
|
83
|
+
|
84
|
+
def check_unknown!
|
85
|
+
unless ARGV.include?("exec") || ARGV.include?("config")
|
86
|
+
raise UnknownArgumentError, "Unknown switches '#{@unknown.join(', ')}'" unless @unknown.empty?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
# Returns true if the current value in peek is a registered switch.
|
93
|
+
#
|
94
|
+
def current_is_switch?
|
95
|
+
case peek
|
96
|
+
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM
|
97
|
+
[true, switch?($1)]
|
98
|
+
when SHORT_SQ_RE
|
99
|
+
[true, $1.split('').any? { |f| switch?("-#{f}") }]
|
100
|
+
else
|
101
|
+
[false, false]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def current_is_switch_formatted?
|
106
|
+
case peek
|
107
|
+
when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM, SHORT_SQ_RE
|
108
|
+
true
|
109
|
+
else
|
110
|
+
false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def switch?(arg)
|
115
|
+
switch_option(normalize_switch(arg))
|
116
|
+
end
|
117
|
+
|
118
|
+
def switch_option(arg)
|
119
|
+
if match = no_or_skip?(arg)
|
120
|
+
@switches[arg] || @switches["--#{match}"]
|
121
|
+
else
|
122
|
+
@switches[arg]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Check if the given argument is actually a shortcut.
|
127
|
+
#
|
128
|
+
def normalize_switch(arg)
|
129
|
+
(@shorts[arg] || arg).tr('_', '-')
|
130
|
+
end
|
131
|
+
|
132
|
+
# Parse boolean values which can be given as --foo=true, --foo or --no-foo.
|
133
|
+
#
|
134
|
+
def parse_boolean(switch)
|
135
|
+
if current_is_value?
|
136
|
+
if ["true", "TRUE", "t", "T", true].include?(peek)
|
137
|
+
shift
|
138
|
+
true
|
139
|
+
elsif ["false", "FALSE", "f", "F", false].include?(peek)
|
140
|
+
shift
|
141
|
+
false
|
142
|
+
else
|
143
|
+
true
|
144
|
+
end
|
145
|
+
else
|
146
|
+
@switches.key?(switch) || !no_or_skip?(switch)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# Parse the value at the peek analyzing if it requires an input or not.
|
151
|
+
#
|
152
|
+
def parse_peek(switch, option)
|
153
|
+
if current_is_switch_formatted? || last?
|
154
|
+
if option.boolean?
|
155
|
+
# No problem for boolean types
|
156
|
+
elsif no_or_skip?(switch)
|
157
|
+
return nil # User set value to nil
|
158
|
+
elsif option.string? && !option.required?
|
159
|
+
# Return the default if there is one, else the human name
|
160
|
+
return option.lazy_default || option.default || option.human_name
|
161
|
+
elsif option.lazy_default
|
162
|
+
return option.lazy_default
|
163
|
+
else
|
164
|
+
raise MalformattedArgumentError, "No value provided for option '#{switch}'"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
@non_assigned_required.delete(option)
|
169
|
+
send(:"parse_#{option.type}", switch)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
class Thor
|
4
|
+
# Adds a compatibility layer to your Thor classes which allows you to use
|
5
|
+
# rake package tasks. For example, to use rspec rake tasks, one can do:
|
6
|
+
#
|
7
|
+
# require 'thor/rake_compat'
|
8
|
+
#
|
9
|
+
# class Default < Thor
|
10
|
+
# include Thor::RakeCompat
|
11
|
+
#
|
12
|
+
# Spec::Rake::SpecTask.new(:spec) do |t|
|
13
|
+
# t.spec_opts = ['--options', "spec/spec.opts"]
|
14
|
+
# t.spec_files = FileList['spec/**/*_spec.rb']
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
module RakeCompat
|
19
|
+
def self.rake_classes
|
20
|
+
@rake_classes ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.included(base)
|
24
|
+
# Hack. Make rakefile point to invoker, so rdoc task is generated properly.
|
25
|
+
rakefile = File.basename(caller[0].match(/(.*):\d+/)[1])
|
26
|
+
Rake.application.instance_variable_set(:@rakefile, rakefile)
|
27
|
+
self.rake_classes << base
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Object #:nodoc:
|
33
|
+
alias :rake_task :task
|
34
|
+
alias :rake_namespace :namespace
|
35
|
+
|
36
|
+
def task(*args, &block)
|
37
|
+
task = rake_task(*args, &block)
|
38
|
+
|
39
|
+
if klass = Thor::RakeCompat.rake_classes.last
|
40
|
+
non_namespaced_name = task.name.split(':').last
|
41
|
+
|
42
|
+
description = non_namespaced_name
|
43
|
+
description << task.arg_names.map{ |n| n.to_s.upcase }.join(' ')
|
44
|
+
description.strip!
|
45
|
+
|
46
|
+
klass.desc description, task.comment || non_namespaced_name
|
47
|
+
klass.send :define_method, non_namespaced_name do |*args|
|
48
|
+
Rake::Task[task.name.to_sym].invoke(*args)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
task
|
53
|
+
end
|
54
|
+
|
55
|
+
def namespace(name, &block)
|
56
|
+
if klass = Thor::RakeCompat.rake_classes.last
|
57
|
+
const_name = Thor::Util.camel_case(name.to_s).to_sym
|
58
|
+
klass.const_set(const_name, Class.new(Thor))
|
59
|
+
new_klass = klass.const_get(const_name)
|
60
|
+
Thor::RakeCompat.rake_classes << new_klass
|
61
|
+
end
|
62
|
+
|
63
|
+
rake_namespace(name, &block)
|
64
|
+
Thor::RakeCompat.rake_classes.pop
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,309 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/group'
|
3
|
+
require 'thor/core_ext/file_binary_read'
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
require 'open-uri'
|
7
|
+
require 'yaml'
|
8
|
+
require 'digest/md5'
|
9
|
+
require 'pathname'
|
10
|
+
|
11
|
+
class Thor::Runner < Thor #:nodoc:
|
12
|
+
map "-T" => :list, "-i" => :install, "-u" => :update, "-v" => :version
|
13
|
+
|
14
|
+
# Override Thor#help so it can give information about any class and any method.
|
15
|
+
#
|
16
|
+
def help(meth = nil)
|
17
|
+
if meth && !self.respond_to?(meth)
|
18
|
+
initialize_thorfiles(meth)
|
19
|
+
klass, task = Thor::Util.find_class_and_task_by_namespace(meth)
|
20
|
+
klass.start(["-h", task].compact, :shell => self.shell)
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# If a task is not found on Thor::Runner, method missing is invoked and
|
27
|
+
# Thor::Runner is then responsable for finding the task in all classes.
|
28
|
+
#
|
29
|
+
def method_missing(meth, *args)
|
30
|
+
meth = meth.to_s
|
31
|
+
initialize_thorfiles(meth)
|
32
|
+
klass, task = Thor::Util.find_class_and_task_by_namespace(meth)
|
33
|
+
args.unshift(task) if task
|
34
|
+
klass.start(args, :shell => self.shell)
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "install NAME", "Install an optionally named Thor file into your system tasks"
|
38
|
+
method_options :as => :string, :relative => :boolean, :force => :boolean
|
39
|
+
def install(name)
|
40
|
+
initialize_thorfiles
|
41
|
+
|
42
|
+
# If a directory name is provided as the argument, look for a 'main.thor'
|
43
|
+
# task in said directory.
|
44
|
+
begin
|
45
|
+
if File.directory?(File.expand_path(name))
|
46
|
+
base, package = File.join(name, "main.thor"), :directory
|
47
|
+
contents = open(base) {|input| input.read }
|
48
|
+
else
|
49
|
+
base, package = name, :file
|
50
|
+
contents = open(name) {|input| input.read }
|
51
|
+
end
|
52
|
+
rescue OpenURI::HTTPError
|
53
|
+
raise Error, "Error opening URI '#{name}'"
|
54
|
+
rescue Errno::ENOENT
|
55
|
+
raise Error, "Error opening file '#{name}'"
|
56
|
+
end
|
57
|
+
|
58
|
+
say "Your Thorfile contains:"
|
59
|
+
say contents
|
60
|
+
|
61
|
+
unless options["force"]
|
62
|
+
return false if no?("Do you wish to continue [y/N]?")
|
63
|
+
end
|
64
|
+
|
65
|
+
as = options["as"] || begin
|
66
|
+
first_line = contents.split("\n")[0]
|
67
|
+
(match = first_line.match(/\s*#\s*module:\s*([^\n]*)/)) ? match[1].strip : nil
|
68
|
+
end
|
69
|
+
|
70
|
+
unless as
|
71
|
+
basename = File.basename(name)
|
72
|
+
as = ask("Please specify a name for #{name} in the system repository [#{basename}]:")
|
73
|
+
as = basename if as.empty?
|
74
|
+
end
|
75
|
+
|
76
|
+
location = if options[:relative] || name =~ /^https?:\/\//
|
77
|
+
name
|
78
|
+
else
|
79
|
+
File.expand_path(name)
|
80
|
+
end
|
81
|
+
|
82
|
+
thor_yaml[as] = {
|
83
|
+
:filename => Digest::MD5.hexdigest(name + as),
|
84
|
+
:location => location,
|
85
|
+
:namespaces => Thor::Util.namespaces_in_content(contents, base)
|
86
|
+
}
|
87
|
+
|
88
|
+
save_yaml(thor_yaml)
|
89
|
+
say "Storing thor file in your system repository"
|
90
|
+
destination = File.join(thor_root, thor_yaml[as][:filename])
|
91
|
+
|
92
|
+
if package == :file
|
93
|
+
File.open(destination, "w") { |f| f.puts contents }
|
94
|
+
else
|
95
|
+
FileUtils.cp_r(name, destination)
|
96
|
+
end
|
97
|
+
|
98
|
+
thor_yaml[as][:filename] # Indicate success
|
99
|
+
end
|
100
|
+
|
101
|
+
desc "version", "Show Thor version"
|
102
|
+
def version
|
103
|
+
require 'thor/version'
|
104
|
+
say "Thor #{Thor::VERSION}"
|
105
|
+
end
|
106
|
+
|
107
|
+
desc "uninstall NAME", "Uninstall a named Thor module"
|
108
|
+
def uninstall(name)
|
109
|
+
raise Error, "Can't find module '#{name}'" unless thor_yaml[name]
|
110
|
+
say "Uninstalling #{name}."
|
111
|
+
FileUtils.rm_rf(File.join(thor_root, "#{thor_yaml[name][:filename]}"))
|
112
|
+
|
113
|
+
thor_yaml.delete(name)
|
114
|
+
save_yaml(thor_yaml)
|
115
|
+
|
116
|
+
puts "Done."
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "update NAME", "Update a Thor file from its original location"
|
120
|
+
def update(name)
|
121
|
+
raise Error, "Can't find module '#{name}'" if !thor_yaml[name] || !thor_yaml[name][:location]
|
122
|
+
|
123
|
+
say "Updating '#{name}' from #{thor_yaml[name][:location]}"
|
124
|
+
|
125
|
+
old_filename = thor_yaml[name][:filename]
|
126
|
+
self.options = self.options.merge("as" => name)
|
127
|
+
filename = install(thor_yaml[name][:location])
|
128
|
+
|
129
|
+
unless filename == old_filename
|
130
|
+
File.delete(File.join(thor_root, old_filename))
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
desc "installed", "List the installed Thor modules and tasks"
|
135
|
+
method_options :internal => :boolean
|
136
|
+
def installed
|
137
|
+
initialize_thorfiles(nil, true)
|
138
|
+
display_klasses(true, options["internal"])
|
139
|
+
end
|
140
|
+
|
141
|
+
desc "list [SEARCH]", "List the available thor tasks (--substring means .*SEARCH)"
|
142
|
+
method_options :substring => :boolean, :group => :string, :all => :boolean, :debug => :boolean
|
143
|
+
def list(search="")
|
144
|
+
initialize_thorfiles
|
145
|
+
|
146
|
+
search = ".*#{search}" if options["substring"]
|
147
|
+
search = /^#{search}.*/i
|
148
|
+
group = options[:group] || "standard"
|
149
|
+
|
150
|
+
klasses = Thor::Base.subclasses.select do |k|
|
151
|
+
(options[:all] || k.group == group) && k.namespace =~ search
|
152
|
+
end
|
153
|
+
|
154
|
+
display_klasses(false, false, klasses)
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
|
159
|
+
def self.banner(task, all = false, subcommand = false)
|
160
|
+
"thor " + task.formatted_usage(self, all, subcommand)
|
161
|
+
end
|
162
|
+
|
163
|
+
def thor_root
|
164
|
+
Thor::Util.thor_root
|
165
|
+
end
|
166
|
+
|
167
|
+
def thor_yaml
|
168
|
+
@thor_yaml ||= begin
|
169
|
+
yaml_file = File.join(thor_root, "thor.yml")
|
170
|
+
yaml = YAML.load_file(yaml_file) if File.exists?(yaml_file)
|
171
|
+
yaml || {}
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# Save the yaml file. If none exists in thor root, creates one.
|
176
|
+
#
|
177
|
+
def save_yaml(yaml)
|
178
|
+
yaml_file = File.join(thor_root, "thor.yml")
|
179
|
+
|
180
|
+
unless File.exists?(yaml_file)
|
181
|
+
FileUtils.mkdir_p(thor_root)
|
182
|
+
yaml_file = File.join(thor_root, "thor.yml")
|
183
|
+
FileUtils.touch(yaml_file)
|
184
|
+
end
|
185
|
+
|
186
|
+
File.open(yaml_file, "w") { |f| f.puts yaml.to_yaml }
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.exit_on_failure?
|
190
|
+
true
|
191
|
+
end
|
192
|
+
|
193
|
+
# Load the thorfiles. If relevant_to is supplied, looks for specific files
|
194
|
+
# in the thor_root instead of loading them all.
|
195
|
+
#
|
196
|
+
# By default, it also traverses the current path until find Thor files, as
|
197
|
+
# described in thorfiles. This look up can be skipped by suppliying
|
198
|
+
# skip_lookup true.
|
199
|
+
#
|
200
|
+
def initialize_thorfiles(relevant_to=nil, skip_lookup=false)
|
201
|
+
thorfiles(relevant_to, skip_lookup).each do |f|
|
202
|
+
Thor::Util.load_thorfile(f, nil, options[:debug]) unless Thor::Base.subclass_files.keys.include?(File.expand_path(f))
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Finds Thorfiles by traversing from your current directory down to the root
|
207
|
+
# directory of your system. If at any time we find a Thor file, we stop.
|
208
|
+
#
|
209
|
+
# We also ensure that system-wide Thorfiles are loaded first, so local
|
210
|
+
# Thorfiles can override them.
|
211
|
+
#
|
212
|
+
# ==== Example
|
213
|
+
#
|
214
|
+
# If we start at /Users/wycats/dev/thor ...
|
215
|
+
#
|
216
|
+
# 1. /Users/wycats/dev/thor
|
217
|
+
# 2. /Users/wycats/dev
|
218
|
+
# 3. /Users/wycats <-- we find a Thorfile here, so we stop
|
219
|
+
#
|
220
|
+
# Suppose we start at c:\Documents and Settings\james\dev\thor ...
|
221
|
+
#
|
222
|
+
# 1. c:\Documents and Settings\james\dev\thor
|
223
|
+
# 2. c:\Documents and Settings\james\dev
|
224
|
+
# 3. c:\Documents and Settings\james
|
225
|
+
# 4. c:\Documents and Settings
|
226
|
+
# 5. c:\ <-- no Thorfiles found!
|
227
|
+
#
|
228
|
+
def thorfiles(relevant_to=nil, skip_lookup=false)
|
229
|
+
thorfiles = []
|
230
|
+
|
231
|
+
unless skip_lookup
|
232
|
+
Pathname.pwd.ascend do |path|
|
233
|
+
thorfiles = Thor::Util.globs_for(path).map { |g| Dir[g] }.flatten
|
234
|
+
break unless thorfiles.empty?
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
files = (relevant_to ? thorfiles_relevant_to(relevant_to) : Thor::Util.thor_root_glob)
|
239
|
+
files += thorfiles
|
240
|
+
files -= ["#{thor_root}/thor.yml"]
|
241
|
+
|
242
|
+
files.map! do |file|
|
243
|
+
File.directory?(file) ? File.join(file, "main.thor") : file
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
# Load thorfiles relevant to the given method. If you provide "foo:bar" it
|
248
|
+
# will load all thor files in the thor.yaml that has "foo" e "foo:bar"
|
249
|
+
# namespaces registered.
|
250
|
+
#
|
251
|
+
def thorfiles_relevant_to(meth)
|
252
|
+
lookup = [ meth, meth.split(":")[0...-1].join(":") ]
|
253
|
+
|
254
|
+
files = thor_yaml.select do |k, v|
|
255
|
+
v[:namespaces] && !(v[:namespaces] & lookup).empty?
|
256
|
+
end
|
257
|
+
|
258
|
+
files.map { |k, v| File.join(thor_root, "#{v[:filename]}") }
|
259
|
+
end
|
260
|
+
|
261
|
+
# Display information about the given klasses. If with_module is given,
|
262
|
+
# it shows a table with information extracted from the yaml file.
|
263
|
+
#
|
264
|
+
def display_klasses(with_modules=false, show_internal=false, klasses=Thor::Base.subclasses)
|
265
|
+
klasses -= [Thor, Thor::Runner, Thor::Group] unless show_internal
|
266
|
+
|
267
|
+
raise Error, "No Thor tasks available" if klasses.empty?
|
268
|
+
show_modules if with_modules && !thor_yaml.empty?
|
269
|
+
|
270
|
+
list = Hash.new { |h,k| h[k] = [] }
|
271
|
+
groups = klasses.select { |k| k.ancestors.include?(Thor::Group) }
|
272
|
+
|
273
|
+
# Get classes which inherit from Thor
|
274
|
+
(klasses - groups).each { |k| list[k.namespace.split(":").first] += k.printable_tasks(false) }
|
275
|
+
|
276
|
+
# Get classes which inherit from Thor::Base
|
277
|
+
groups.map! { |k| k.printable_tasks(false).first }
|
278
|
+
list["root"] = groups
|
279
|
+
|
280
|
+
# Order namespaces with default coming first
|
281
|
+
list = list.sort{ |a,b| a[0].sub(/^default/, '') <=> b[0].sub(/^default/, '') }
|
282
|
+
list.each { |n, tasks| display_tasks(n, tasks) unless tasks.empty? }
|
283
|
+
end
|
284
|
+
|
285
|
+
def display_tasks(namespace, list) #:nodoc:
|
286
|
+
list.sort!{ |a,b| a[0] <=> b[0] }
|
287
|
+
|
288
|
+
say shell.set_color(namespace, :blue, true)
|
289
|
+
say "-" * namespace.size
|
290
|
+
|
291
|
+
print_table(list, :truncate => true)
|
292
|
+
say
|
293
|
+
end
|
294
|
+
|
295
|
+
def show_modules #:nodoc:
|
296
|
+
info = []
|
297
|
+
labels = ["Modules", "Namespaces"]
|
298
|
+
|
299
|
+
info << labels
|
300
|
+
info << [ "-" * labels[0].size, "-" * labels[1].size ]
|
301
|
+
|
302
|
+
thor_yaml.each do |name, hash|
|
303
|
+
info << [ name, hash[:namespaces].join(", ") ]
|
304
|
+
end
|
305
|
+
|
306
|
+
print_table info
|
307
|
+
say ""
|
308
|
+
end
|
309
|
+
end
|