thor 0.16.0 → 1.2.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.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +15 -0
- data/README.md +23 -6
- data/bin/thor +1 -1
- data/lib/thor/actions/create_file.rb +34 -35
- data/lib/thor/actions/create_link.rb +9 -5
- data/lib/thor/actions/directory.rb +33 -23
- data/lib/thor/actions/empty_directory.rb +75 -85
- data/lib/thor/actions/file_manipulation.rb +103 -36
- data/lib/thor/actions/inject_into_file.rb +46 -36
- data/lib/thor/actions.rb +90 -68
- data/lib/thor/base.rb +302 -244
- data/lib/thor/command.rb +142 -0
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +52 -24
- data/lib/thor/error.rb +90 -10
- data/lib/thor/group.rb +70 -74
- data/lib/thor/invocation.rb +63 -55
- data/lib/thor/line_editor/basic.rb +37 -0
- data/lib/thor/line_editor/readline.rb +88 -0
- data/lib/thor/line_editor.rb +17 -0
- data/lib/thor/nested_context.rb +29 -0
- data/lib/thor/parser/argument.rb +24 -28
- data/lib/thor/parser/arguments.rb +110 -102
- data/lib/thor/parser/option.rb +53 -15
- data/lib/thor/parser/options.rb +174 -97
- data/lib/thor/parser.rb +4 -4
- data/lib/thor/rake_compat.rb +12 -11
- data/lib/thor/runner.rb +159 -155
- data/lib/thor/shell/basic.rb +216 -93
- data/lib/thor/shell/color.rb +53 -40
- data/lib/thor/shell/html.rb +61 -58
- data/lib/thor/shell.rb +29 -36
- data/lib/thor/util.rb +231 -213
- data/lib/thor/version.rb +1 -1
- data/lib/thor.rb +303 -166
- data/thor.gemspec +27 -24
- metadata +36 -226
- data/.gitignore +0 -44
- data/.rspec +0 -2
- data/.travis.yml +0 -7
- data/CHANGELOG.rdoc +0 -134
- data/Gemfile +0 -15
- data/Thorfile +0 -30
- data/bin/rake2thor +0 -86
- data/lib/thor/core_ext/dir_escape.rb +0 -0
- data/lib/thor/core_ext/file_binary_read.rb +0 -9
- data/lib/thor/core_ext/ordered_hash.rb +0 -100
- data/lib/thor/task.rb +0 -132
- data/spec/actions/create_file_spec.rb +0 -170
- data/spec/actions/create_link_spec.rb +0 -81
- data/spec/actions/directory_spec.rb +0 -149
- data/spec/actions/empty_directory_spec.rb +0 -130
- data/spec/actions/file_manipulation_spec.rb +0 -370
- data/spec/actions/inject_into_file_spec.rb +0 -135
- data/spec/actions_spec.rb +0 -331
- data/spec/base_spec.rb +0 -279
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -43
- data/spec/core_ext/ordered_hash_spec.rb +0 -115
- data/spec/exit_condition_spec.rb +0 -19
- data/spec/fixtures/application.rb +0 -2
- data/spec/fixtures/app{1}/README +0 -3
- data/spec/fixtures/bundle/execute.rb +0 -6
- data/spec/fixtures/bundle/main.thor +0 -1
- data/spec/fixtures/doc/%file_name%.rb.tt +0 -1
- data/spec/fixtures/doc/COMMENTER +0 -10
- data/spec/fixtures/doc/README +0 -3
- data/spec/fixtures/doc/block_helper.rb +0 -3
- data/spec/fixtures/doc/components/.empty_directory +0 -0
- data/spec/fixtures/doc/config.rb +0 -1
- data/spec/fixtures/doc/config.yaml.tt +0 -1
- data/spec/fixtures/enum.thor +0 -10
- data/spec/fixtures/group.thor +0 -114
- data/spec/fixtures/invoke.thor +0 -112
- data/spec/fixtures/path with spaces +0 -0
- data/spec/fixtures/script.thor +0 -190
- data/spec/fixtures/task.thor +0 -10
- data/spec/group_spec.rb +0 -216
- data/spec/invocation_spec.rb +0 -100
- data/spec/parser/argument_spec.rb +0 -53
- data/spec/parser/arguments_spec.rb +0 -66
- data/spec/parser/option_spec.rb +0 -202
- data/spec/parser/options_spec.rb +0 -330
- data/spec/rake_compat_spec.rb +0 -72
- data/spec/register_spec.rb +0 -135
- data/spec/runner_spec.rb +0 -241
- data/spec/shell/basic_spec.rb +0 -300
- data/spec/shell/color_spec.rb +0 -81
- data/spec/shell/html_spec.rb +0 -32
- data/spec/shell_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -59
- data/spec/task_spec.rb +0 -80
- data/spec/thor_spec.rb +0 -418
- data/spec/util_spec.rb +0 -196
data/spec/shell/color_spec.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Thor::Shell::Color do
|
4
|
-
def shell
|
5
|
-
@shell ||= Thor::Shell::Color.new
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#say" do
|
9
|
-
it "set the color if specified" do
|
10
|
-
out = capture(:stdout) do
|
11
|
-
shell.say "Wow! Now we have colors!", :green
|
12
|
-
end
|
13
|
-
|
14
|
-
out.chomp.should == "\e[32mWow! Now we have colors!\e[0m"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "does not use a new line even with colors" do
|
18
|
-
out = capture(:stdout) do
|
19
|
-
shell.say "Wow! Now we have colors! ", :green
|
20
|
-
end
|
21
|
-
|
22
|
-
out.chomp.should == "\e[32mWow! Now we have colors! \e[0m"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "handles an Array of colors" do
|
26
|
-
out = capture(:stdout) do
|
27
|
-
shell.say "Wow! Now we have colors *and* background colors", [:green, :on_red, :bold]
|
28
|
-
end
|
29
|
-
|
30
|
-
out.chomp.should == "\e[32m\e[41m\e[1mWow! Now we have colors *and* background colors\e[0m"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#say_status" do
|
35
|
-
it "uses color to say status" do
|
36
|
-
out = capture(:stdout) do
|
37
|
-
shell.say_status :conflict, "README", :red
|
38
|
-
end
|
39
|
-
|
40
|
-
out.chomp.should == "\e[1m\e[31m conflict\e[0m README"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#set_color" do
|
45
|
-
it "colors a string with a foreground color" do
|
46
|
-
red = shell.set_color "hi!", :red
|
47
|
-
red.should == "\e[31mhi!\e[0m"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "colors a string with a background color" do
|
51
|
-
on_red = shell.set_color "hi!", :white, :on_red
|
52
|
-
on_red.should == "\e[37m\e[41mhi!\e[0m"
|
53
|
-
end
|
54
|
-
|
55
|
-
it "colors a string with a bold color" do
|
56
|
-
bold = shell.set_color "hi!", :white, true
|
57
|
-
bold.should == "\e[1m\e[37mhi!\e[0m"
|
58
|
-
|
59
|
-
bold = shell.set_color "hi!", :white, :bold
|
60
|
-
bold.should == "\e[37m\e[1mhi!\e[0m"
|
61
|
-
|
62
|
-
bold = shell.set_color "hi!", :white, :on_red, :bold
|
63
|
-
bold.should == "\e[37m\e[41m\e[1mhi!\e[0m"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "#file_collision" do
|
68
|
-
describe "when a block is given" do
|
69
|
-
it "invokes the diff command" do
|
70
|
-
$stdout.stub!(:print)
|
71
|
-
$stdin.should_receive(:gets).and_return('d')
|
72
|
-
$stdin.should_receive(:gets).and_return('n')
|
73
|
-
|
74
|
-
output = capture(:stdout){ shell.file_collision('spec/fixtures/doc/README'){ "README\nEND\n" } }
|
75
|
-
output.should =~ /\e\[31m\- __start__\e\[0m/
|
76
|
-
output.should =~ /^ README/
|
77
|
-
output.should =~ /\e\[32m\+ END\e\[0m/
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
data/spec/shell/html_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Thor::Shell::HTML do
|
4
|
-
def shell
|
5
|
-
@shell ||= Thor::Shell::HTML.new
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#say" do
|
9
|
-
it "set the color if specified" do
|
10
|
-
out = capture(:stdout) { shell.say "Wow! Now we have colors!", :green }
|
11
|
-
out.chomp.should == '<span style="color: green;">Wow! Now we have colors!</span>'
|
12
|
-
end
|
13
|
-
|
14
|
-
it "sets bold if specified" do
|
15
|
-
out = capture(:stdout) { shell.say "Wow! Now we have colors *and* bold!", [:green, :bold] }
|
16
|
-
out.chomp.should == '<span style="color: green; font-weight: bold;">Wow! Now we have colors *and* bold!</span>'
|
17
|
-
end
|
18
|
-
|
19
|
-
it "does not use a new line even with colors" do
|
20
|
-
out = capture(:stdout) { shell.say "Wow! Now we have colors! ", :green }
|
21
|
-
out.chomp.should == '<span style="color: green;">Wow! Now we have colors! </span>'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#say_status" do
|
26
|
-
it "uses color to say status" do
|
27
|
-
$stdout.should_receive(:puts).with('<span style="color: red; font-weight: bold;"> conflict</span> README')
|
28
|
-
shell.say_status :conflict, "README", :red
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/spec/shell_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Thor::Shell do
|
4
|
-
def shell
|
5
|
-
@shell ||= Thor::Base.shell.new
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#initialize" do
|
9
|
-
it "sets shell value" do
|
10
|
-
base = MyCounter.new [1, 2], { }, :shell => shell
|
11
|
-
base.shell.should == shell
|
12
|
-
end
|
13
|
-
|
14
|
-
it "sets the base value on the shell if an accessor is available" do
|
15
|
-
base = MyCounter.new [1, 2], { }, :shell => shell
|
16
|
-
shell.base.should == base
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#shell" do
|
21
|
-
it "returns the shell in use" do
|
22
|
-
MyCounter.new([1,2]).shell.should be_kind_of(Thor::Base.shell)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "uses $THOR_SHELL" do
|
26
|
-
class Thor::Shell::TestShell < Thor::Shell::Basic; end
|
27
|
-
|
28
|
-
Thor::Base.shell.should == shell.class
|
29
|
-
ENV['THOR_SHELL'] = 'TestShell'
|
30
|
-
Thor::Base.shell = nil
|
31
|
-
Thor::Base.shell.should == Thor::Shell::TestShell
|
32
|
-
ENV['THOR_SHELL'] = ''
|
33
|
-
Thor::Base.shell = shell.class
|
34
|
-
Thor::Base.shell.should == shell.class
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "with_padding" do
|
39
|
-
it "uses padding for inside block outputs" do
|
40
|
-
base = MyCounter.new([1,2])
|
41
|
-
base.with_padding do
|
42
|
-
capture(:stdout){ base.say_status :padding, "cool" }.strip.should == "padding cool"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
$TESTING=true
|
2
|
-
|
3
|
-
require 'simplecov'
|
4
|
-
SimpleCov.start do
|
5
|
-
add_group 'Libraries', 'lib'
|
6
|
-
add_group 'Specs', 'spec'
|
7
|
-
end
|
8
|
-
|
9
|
-
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
10
|
-
require 'thor'
|
11
|
-
require 'thor/group'
|
12
|
-
require 'stringio'
|
13
|
-
|
14
|
-
require 'rdoc'
|
15
|
-
require 'rspec'
|
16
|
-
require 'diff/lcs' # You need diff/lcs installed to run specs (but not to run Thor).
|
17
|
-
require 'fakeweb' # You need fakeweb installed to run specs (but not to run Thor).
|
18
|
-
|
19
|
-
# Set shell to basic
|
20
|
-
$0 = "thor"
|
21
|
-
$thor_runner = true
|
22
|
-
ARGV.clear
|
23
|
-
Thor::Base.shell = Thor::Shell::Basic
|
24
|
-
|
25
|
-
# Load fixtures
|
26
|
-
load File.join(File.dirname(__FILE__), "fixtures", "task.thor")
|
27
|
-
load File.join(File.dirname(__FILE__), "fixtures", "group.thor")
|
28
|
-
load File.join(File.dirname(__FILE__), "fixtures", "script.thor")
|
29
|
-
load File.join(File.dirname(__FILE__), "fixtures", "invoke.thor")
|
30
|
-
load File.join(File.dirname(__FILE__), "fixtures", "enum.thor")
|
31
|
-
|
32
|
-
RSpec.configure do |config|
|
33
|
-
config.before do
|
34
|
-
ARGV.replace []
|
35
|
-
end
|
36
|
-
|
37
|
-
def capture(stream)
|
38
|
-
begin
|
39
|
-
stream = stream.to_s
|
40
|
-
eval "$#{stream} = StringIO.new"
|
41
|
-
yield
|
42
|
-
result = eval("$#{stream}").string
|
43
|
-
ensure
|
44
|
-
eval("$#{stream} = #{stream.upcase}")
|
45
|
-
end
|
46
|
-
|
47
|
-
result
|
48
|
-
end
|
49
|
-
|
50
|
-
def source_root
|
51
|
-
File.join(File.dirname(__FILE__), 'fixtures')
|
52
|
-
end
|
53
|
-
|
54
|
-
def destination_root
|
55
|
-
File.join(File.dirname(__FILE__), 'sandbox')
|
56
|
-
end
|
57
|
-
|
58
|
-
alias :silence :capture
|
59
|
-
end
|
data/spec/task_spec.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Thor::Task do
|
4
|
-
def task(options={})
|
5
|
-
options.each do |key, value|
|
6
|
-
options[key] = Thor::Option.parse(key, value)
|
7
|
-
end
|
8
|
-
|
9
|
-
@task ||= Thor::Task.new(:can_has, "I can has cheezburger", "I can has cheezburger\nLots and lots of it", "can_has", options)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#formatted_usage" do
|
13
|
-
it "includes namespace within usage" do
|
14
|
-
object = Struct.new(:namespace, :arguments).new("foo", [])
|
15
|
-
task(:bar => :required).formatted_usage(object).should == "foo:can_has --bar=BAR"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "includes subcommand name within subcommand usage" do
|
19
|
-
object = Struct.new(:namespace, :arguments).new("main:foo", [])
|
20
|
-
task(:bar => :required).formatted_usage(object, false, true).should == "foo can_has --bar=BAR"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "removes default from namespace" do
|
24
|
-
object = Struct.new(:namespace, :arguments).new("default:foo", [])
|
25
|
-
task(:bar => :required).formatted_usage(object).should == ":foo:can_has --bar=BAR"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "injects arguments into usage" do
|
29
|
-
options = {:required => true, :type => :string}
|
30
|
-
object = Struct.new(:namespace, :arguments).new("foo", [Thor::Argument.new(:bar, options)])
|
31
|
-
task(:foo => :required).formatted_usage(object).should == "foo:can_has BAR --foo=FOO"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#dynamic" do
|
36
|
-
it "creates a dynamic task with the given name" do
|
37
|
-
Thor::DynamicTask.new('task').name.should == 'task'
|
38
|
-
Thor::DynamicTask.new('task').description.should == 'A dynamically-generated task'
|
39
|
-
Thor::DynamicTask.new('task').usage.should == 'task'
|
40
|
-
Thor::DynamicTask.new('task').options.should == {}
|
41
|
-
end
|
42
|
-
|
43
|
-
it "does not invoke an existing method" do
|
44
|
-
mock = mock()
|
45
|
-
mock.class.should_receive(:handle_no_task_error).with("to_s")
|
46
|
-
Thor::DynamicTask.new('to_s').run(mock)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#dup" do
|
51
|
-
it "dup options hash" do
|
52
|
-
task = Thor::Task.new("can_has", nil, nil, nil, :foo => true, :bar => :required)
|
53
|
-
task.dup.options.delete(:foo)
|
54
|
-
task.options[:foo].should be
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#run" do
|
59
|
-
it "runs a task by calling a method in the given instance" do
|
60
|
-
mock = mock()
|
61
|
-
mock.should_receive(:can_has).and_return {|*args| args }
|
62
|
-
task.run(mock, [1, 2, 3]).should == [1, 2, 3]
|
63
|
-
end
|
64
|
-
|
65
|
-
it "raises an error if the method to be invoked is private" do
|
66
|
-
klass = Class.new do
|
67
|
-
def self.handle_no_task_error(name)
|
68
|
-
name
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
def can_has
|
73
|
-
"fail"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
task.run(klass.new).should == "can_has"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|