thor 0.14.3 → 0.14.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thor/actions.rb +12 -2
- data/lib/thor/actions/directory.rb +1 -1
- data/lib/thor/actions/file_manipulation.rb +1 -1
- data/lib/thor/base.rb +16 -0
- data/lib/thor/shell/basic.rb +16 -1
- data/lib/thor/version.rb +1 -1
- data/spec/actions/directory_spec.rb +5 -0
- data/spec/actions/empty_directory_spec.rb +7 -0
- data/spec/actions/file_manipulation_spec.rb +9 -0
- data/spec/actions_spec.rb +7 -0
- data/spec/fixtures/group.thor +19 -0
- data/spec/group_spec.rb +7 -0
- data/spec/shell/basic_spec.rb +9 -0
- metadata +4 -4
data/lib/thor/actions.rb
CHANGED
@@ -158,13 +158,23 @@ class Thor
|
|
158
158
|
#
|
159
159
|
def inside(dir='', config={}, &block)
|
160
160
|
verbose = config.fetch(:verbose, false)
|
161
|
+
pretend = options[:pretend]
|
161
162
|
|
162
163
|
say_status :inside, dir, verbose
|
163
164
|
shell.padding += 1 if verbose
|
164
165
|
@destination_stack.push File.expand_path(dir, destination_root)
|
165
166
|
|
166
|
-
|
167
|
-
|
167
|
+
# If the directory doesnt exist and we're not pretending
|
168
|
+
if !File.exist?(destination_root) && !pretend
|
169
|
+
FileUtils.mkdir_p(destination_root)
|
170
|
+
end
|
171
|
+
|
172
|
+
if pretend
|
173
|
+
# In pretend mode, just yield down to the block
|
174
|
+
block.arity == 1 ? yield(destination_root) : yield
|
175
|
+
else
|
176
|
+
FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
|
177
|
+
end
|
168
178
|
|
169
179
|
@destination_stack.pop
|
170
180
|
shell.padding -= 1 if verbose
|
@@ -70,7 +70,7 @@ class Thor
|
|
70
70
|
lookup = config[:recursive] ? File.join(source, '**') : source
|
71
71
|
lookup = File.join(lookup, '{*,.[a-z]*}')
|
72
72
|
|
73
|
-
Dir[lookup].each do |file_source|
|
73
|
+
Dir[lookup].sort.each do |file_source|
|
74
74
|
next if File.directory?(file_source)
|
75
75
|
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
|
76
76
|
file_destination.gsub!('/./', '/')
|
@@ -51,7 +51,7 @@ class Thor
|
|
51
51
|
config = args.last.is_a?(Hash) ? args.pop : {}
|
52
52
|
destination = args.first
|
53
53
|
|
54
|
-
source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ /^
|
54
|
+
source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ /^https?\:\/\//
|
55
55
|
render = open(source) {|input| input.binmode.read }
|
56
56
|
|
57
57
|
destination ||= if block_given?
|
data/lib/thor/base.rb
CHANGED
@@ -392,6 +392,22 @@ class Thor
|
|
392
392
|
exit(1) if exit_on_failure?
|
393
393
|
end
|
394
394
|
|
395
|
+
# Allows to use private methods from parent in child classes as tasks.
|
396
|
+
#
|
397
|
+
# ==== Paremeters
|
398
|
+
# names<Array>:: Method names to be used as tasks
|
399
|
+
#
|
400
|
+
# ==== Examples
|
401
|
+
#
|
402
|
+
# public_task :foo
|
403
|
+
# public_task :foo, :bar, :baz
|
404
|
+
#
|
405
|
+
def public_task(*names)
|
406
|
+
names.each do |name|
|
407
|
+
class_eval "def #{name}(*); super end"
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
395
411
|
def handle_no_task_error(task) #:nodoc:
|
396
412
|
if $thor_runner
|
397
413
|
raise UndefinedTaskError, "Could not find task #{task.inspect} in #{namespace.inspect} namespace."
|
data/lib/thor/shell/basic.rb
CHANGED
@@ -11,6 +11,21 @@ class Thor
|
|
11
11
|
@base, @padding = nil, 0
|
12
12
|
end
|
13
13
|
|
14
|
+
# Mute everything that's inside given block
|
15
|
+
#
|
16
|
+
def mute
|
17
|
+
@mute = true
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
@mute = false
|
21
|
+
end
|
22
|
+
|
23
|
+
# Check if base is muted
|
24
|
+
#
|
25
|
+
def mute?
|
26
|
+
@mute
|
27
|
+
end
|
28
|
+
|
14
29
|
# Sets the output padding, not allowing less than zero values.
|
15
30
|
#
|
16
31
|
def padding=(value)
|
@@ -229,7 +244,7 @@ HELP
|
|
229
244
|
end
|
230
245
|
|
231
246
|
def quiet? #:nodoc:
|
232
|
-
base && base.options[:quiet]
|
247
|
+
mute? || (base && base.options[:quiet])
|
233
248
|
end
|
234
249
|
|
235
250
|
# This code was copied from Rake, available under MIT-LICENSE
|
data/lib/thor/version.rb
CHANGED
@@ -39,6 +39,11 @@ describe Thor::Actions::Directory do
|
|
39
39
|
invoke! "unknown"
|
40
40
|
}.must raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/)
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should not create a directory in pretend mode" do
|
44
|
+
invoke! "doc", "ghost", :pretend => true
|
45
|
+
File.exists?("ghost").must be_false
|
46
|
+
end
|
42
47
|
|
43
48
|
it "copies the whole directory recursively to the default destination" do
|
44
49
|
invoke! "doc"
|
@@ -62,6 +62,13 @@ describe Thor::Actions::EmptyDirectory do
|
|
62
62
|
invoke!.must == " create doc\n"
|
63
63
|
end
|
64
64
|
|
65
|
+
it "does not create a directory if pretending" do
|
66
|
+
base.inside("foo", :pretend => true) do
|
67
|
+
empty_directory("ghost")
|
68
|
+
end
|
69
|
+
File.exists?(File.join(base.destination_root, "ghost")).must be_false
|
70
|
+
end
|
71
|
+
|
65
72
|
describe "when directory exists" do
|
66
73
|
it "shows exist status" do
|
67
74
|
empty_directory("doc")
|
@@ -114,6 +114,15 @@ describe Thor::Actions do
|
|
114
114
|
end
|
115
115
|
FakeWeb.clean_registry
|
116
116
|
end
|
117
|
+
|
118
|
+
it "accepts https remote sources" do
|
119
|
+
body = "__start__\nHTTPSFILE\n__end__\n"
|
120
|
+
FakeWeb.register_uri(:get, 'https://example.com/file.txt', :body => body)
|
121
|
+
action :get, 'https://example.com/file.txt' do |content|
|
122
|
+
content.must == body
|
123
|
+
end
|
124
|
+
FakeWeb.clean_registry
|
125
|
+
end
|
117
126
|
end
|
118
127
|
|
119
128
|
describe "#template" do
|
data/spec/actions_spec.rb
CHANGED
@@ -140,6 +140,13 @@ describe Thor::Actions do
|
|
140
140
|
File.exists?(file).must be_true
|
141
141
|
end
|
142
142
|
end
|
143
|
+
|
144
|
+
describe "when pretending" do
|
145
|
+
it "no directories should be created" do
|
146
|
+
runner.inside("bar", :pretend => true) {}
|
147
|
+
File.exists?("bar").must be_false
|
148
|
+
end
|
149
|
+
end
|
143
150
|
|
144
151
|
describe "when verbose" do
|
145
152
|
it "logs status" do
|
data/spec/fixtures/group.thor
CHANGED
@@ -93,3 +93,22 @@ class TaskConflict < Thor::Group
|
|
93
93
|
puts "group"
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
class ParentGroup < Thor::Group
|
98
|
+
private
|
99
|
+
def foo
|
100
|
+
"foo"
|
101
|
+
end
|
102
|
+
|
103
|
+
def baz(name = 'baz')
|
104
|
+
name
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class ChildGroup < ParentGroup
|
109
|
+
def bar
|
110
|
+
"bar"
|
111
|
+
end
|
112
|
+
|
113
|
+
public_task :foo, :baz
|
114
|
+
end
|
data/spec/group_spec.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe Thor::Group do
|
4
|
+
describe "task" do
|
5
|
+
it "allows to use private methods from parent class as tasks" do
|
6
|
+
ChildGroup.start.must == ["bar", "foo", "baz"]
|
7
|
+
ChildGroup.new.baz("bar").must == "bar"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
4
11
|
describe "#start" do
|
5
12
|
it "invokes all the tasks under the Thor group" do
|
6
13
|
MyCounter.start(["1", "2", "--third", "3"]).must == [ 1, 2, 3 ]
|
data/spec/shell/basic_spec.rb
CHANGED
@@ -75,6 +75,15 @@ describe Thor::Shell::Basic do
|
|
75
75
|
shell.say_status(:create, "")
|
76
76
|
end
|
77
77
|
|
78
|
+
it "does not print a message if base is muted" do
|
79
|
+
shell.should_receive(:mute?).and_return(true)
|
80
|
+
$stdout.should_not_receive(:puts)
|
81
|
+
|
82
|
+
shell.mute do
|
83
|
+
shell.say_status(:created, "~/.thor/task.thor")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
78
87
|
it "does not print a message if base is set to quiet" do
|
79
88
|
base = MyCounter.new [1,2]
|
80
89
|
base.should_receive(:options).and_return(:quiet => true)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 47
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 14
|
9
|
-
-
|
10
|
-
version: 0.14.
|
9
|
+
- 4
|
10
|
+
version: 0.14.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yehuda Katz
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-11-04 00:00:00 -02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|