thor 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/{CHANGELOG.rdoc → CHANGELOG.md} +30 -36
  2. data/README.md +10 -3
  3. data/lib/thor.rb +205 -180
  4. data/lib/thor/actions.rb +5 -5
  5. data/lib/thor/actions/create_link.rb +3 -0
  6. data/lib/thor/actions/directory.rb +2 -0
  7. data/lib/thor/actions/file_manipulation.rb +1 -1
  8. data/lib/thor/base.rb +84 -95
  9. data/lib/thor/{task.rb → command.rb} +17 -13
  10. data/lib/thor/core_ext/io_binary_read.rb +12 -0
  11. data/lib/thor/error.rb +4 -7
  12. data/lib/thor/group.rb +30 -33
  13. data/lib/thor/invocation.rb +28 -26
  14. data/lib/thor/parser/options.rb +3 -1
  15. data/lib/thor/runner.rb +21 -20
  16. data/lib/thor/shell/basic.rb +5 -1
  17. data/lib/thor/shell/color.rb +4 -0
  18. data/lib/thor/shell/html.rb +4 -0
  19. data/lib/thor/util.rb +214 -210
  20. data/lib/thor/version.rb +1 -1
  21. data/spec/actions/create_file_spec.rb +1 -1
  22. data/spec/actions/create_link_spec.rb +15 -1
  23. data/spec/actions/directory_spec.rb +18 -5
  24. data/spec/actions/empty_directory_spec.rb +1 -1
  25. data/spec/actions/file_manipulation_spec.rb +13 -13
  26. data/spec/actions/inject_into_file_spec.rb +1 -1
  27. data/spec/actions_spec.rb +1 -1
  28. data/spec/base_spec.rb +40 -24
  29. data/spec/command_spec.rb +80 -0
  30. data/spec/core_ext/hash_with_indifferent_access_spec.rb +1 -1
  31. data/spec/core_ext/ordered_hash_spec.rb +1 -1
  32. data/spec/exit_condition_spec.rb +3 -3
  33. data/spec/fixtures/{task.thor → command.thor} +0 -0
  34. data/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  35. data/spec/fixtures/doc/COMMENTER +11 -0
  36. data/spec/fixtures/doc/README +3 -0
  37. data/spec/fixtures/doc/block_helper.rb +3 -0
  38. data/spec/fixtures/doc/config.rb +1 -0
  39. data/spec/fixtures/doc/config.yaml.tt +1 -0
  40. data/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
  41. data/spec/fixtures/group.thor +24 -10
  42. data/spec/fixtures/invoke.thor +3 -3
  43. data/spec/fixtures/script.thor +40 -15
  44. data/spec/fixtures/subcommand.thor +17 -0
  45. data/spec/group_spec.rb +13 -13
  46. data/spec/{spec_helper.rb → helper.rb} +11 -7
  47. data/spec/invocation_spec.rb +16 -16
  48. data/spec/parser/argument_spec.rb +4 -4
  49. data/spec/parser/arguments_spec.rb +1 -1
  50. data/spec/parser/option_spec.rb +1 -1
  51. data/spec/parser/options_spec.rb +6 -1
  52. data/spec/rake_compat_spec.rb +1 -1
  53. data/spec/register_spec.rb +12 -12
  54. data/spec/runner_spec.rb +36 -36
  55. data/spec/shell/basic_spec.rb +9 -10
  56. data/spec/shell/color_spec.rb +16 -2
  57. data/spec/shell/html_spec.rb +1 -1
  58. data/spec/shell_spec.rb +1 -1
  59. data/spec/subcommand_spec.rb +30 -0
  60. data/spec/thor_spec.rb +81 -78
  61. data/spec/util_spec.rb +10 -10
  62. data/thor.gemspec +22 -18
  63. metadata +49 -38
  64. data/.gitignore +0 -44
  65. data/.rspec +0 -3
  66. data/.travis.yml +0 -8
  67. data/Gemfile +0 -19
  68. data/bin/rake2thor +0 -86
  69. data/lib/thor/core_ext/file_binary_read.rb +0 -9
  70. data/spec/task_spec.rb +0 -80
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.18.0
4
5
  prerelease:
5
- version: 0.17.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Yehuda Katz
@@ -10,60 +10,67 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-24 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2013-03-26 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.0'
15
31
  description: A scripting framework that replaces rake, sake and rubigen
16
32
  email: ruby-thor@googlegroups.com
17
33
  executables:
18
- - rake2thor
19
34
  - thor
20
35
  extensions: []
21
- extra_rdoc_files:
22
- - CHANGELOG.rdoc
23
- - LICENSE.md
24
- - README.md
25
- - Thorfile
36
+ extra_rdoc_files: []
26
37
  files:
27
38
  - .document
28
- - .gitignore
29
- - .rspec
30
- - .travis.yml
31
- - CHANGELOG.rdoc
32
- - Gemfile
39
+ - CHANGELOG.md
33
40
  - LICENSE.md
34
41
  - README.md
35
42
  - Thorfile
36
- - bin/rake2thor
43
+ - thor.gemspec
37
44
  - bin/thor
38
- - lib/thor.rb
39
- - lib/thor/actions.rb
40
45
  - lib/thor/actions/create_file.rb
41
46
  - lib/thor/actions/create_link.rb
42
47
  - lib/thor/actions/directory.rb
43
48
  - lib/thor/actions/empty_directory.rb
44
49
  - lib/thor/actions/file_manipulation.rb
45
50
  - lib/thor/actions/inject_into_file.rb
51
+ - lib/thor/actions.rb
46
52
  - lib/thor/base.rb
47
- - lib/thor/core_ext/file_binary_read.rb
53
+ - lib/thor/command.rb
48
54
  - lib/thor/core_ext/hash_with_indifferent_access.rb
55
+ - lib/thor/core_ext/io_binary_read.rb
49
56
  - lib/thor/core_ext/ordered_hash.rb
50
57
  - lib/thor/error.rb
51
58
  - lib/thor/group.rb
52
59
  - lib/thor/invocation.rb
53
- - lib/thor/parser.rb
54
60
  - lib/thor/parser/argument.rb
55
61
  - lib/thor/parser/arguments.rb
56
62
  - lib/thor/parser/option.rb
57
63
  - lib/thor/parser/options.rb
64
+ - lib/thor/parser.rb
58
65
  - lib/thor/rake_compat.rb
59
66
  - lib/thor/runner.rb
60
- - lib/thor/shell.rb
61
67
  - lib/thor/shell/basic.rb
62
68
  - lib/thor/shell/color.rb
63
69
  - lib/thor/shell/html.rb
64
- - lib/thor/task.rb
70
+ - lib/thor/shell.rb
65
71
  - lib/thor/util.rb
66
72
  - lib/thor/version.rb
73
+ - lib/thor.rb
67
74
  - spec/actions/create_file_spec.rb
68
75
  - spec/actions/create_link_spec.rb
69
76
  - spec/actions/directory_spec.rb
@@ -72,6 +79,7 @@ files:
72
79
  - spec/actions/inject_into_file_spec.rb
73
80
  - spec/actions_spec.rb
74
81
  - spec/base_spec.rb
82
+ - spec/command_spec.rb
75
83
  - spec/core_ext/hash_with_indifferent_access_spec.rb
76
84
  - spec/core_ext/ordered_hash_spec.rb
77
85
  - spec/exit_condition_spec.rb
@@ -79,21 +87,23 @@ files:
79
87
  - spec/fixtures/app{1}/README
80
88
  - spec/fixtures/bundle/execute.rb
81
89
  - spec/fixtures/bundle/main.thor
90
+ - spec/fixtures/command.thor
82
91
  - spec/fixtures/doc/%file_name%.rb.tt
83
- - spec/fixtures/doc/COMMENTER
84
- - spec/fixtures/doc/README
85
92
  - spec/fixtures/doc/block_helper.rb
86
- - spec/fixtures/doc/components/.empty_directory
93
+ - spec/fixtures/doc/COMMENTER
87
94
  - spec/fixtures/doc/config.rb
88
95
  - spec/fixtures/doc/config.yaml.tt
96
+ - spec/fixtures/doc/excluding/%file_name%.rb.tt
97
+ - spec/fixtures/doc/README
89
98
  - spec/fixtures/enum.thor
90
99
  - spec/fixtures/group.thor
91
100
  - spec/fixtures/invoke.thor
92
101
  - spec/fixtures/path with spaces
93
102
  - spec/fixtures/preserve/script.sh
94
103
  - spec/fixtures/script.thor
95
- - spec/fixtures/task.thor
104
+ - spec/fixtures/subcommand.thor
96
105
  - spec/group_spec.rb
106
+ - spec/helper.rb
97
107
  - spec/invocation_spec.rb
98
108
  - spec/parser/argument_spec.rb
99
109
  - spec/parser/arguments_spec.rb
@@ -106,17 +116,14 @@ files:
106
116
  - spec/shell/color_spec.rb
107
117
  - spec/shell/html_spec.rb
108
118
  - spec/shell_spec.rb
109
- - spec/spec_helper.rb
110
- - spec/task_spec.rb
119
+ - spec/subcommand_spec.rb
111
120
  - spec/thor_spec.rb
112
121
  - spec/util_spec.rb
113
- - thor.gemspec
114
122
  homepage: http://whatisthor.com/
115
123
  licenses:
116
124
  - MIT
117
125
  post_install_message:
118
- rdoc_options:
119
- - --charset=UTF-8
126
+ rdoc_options: []
120
127
  require_paths:
121
128
  - lib
122
129
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -125,6 +132,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
132
  - - ! '>='
126
133
  - !ruby/object:Gem::Version
127
134
  version: '0'
135
+ segments:
136
+ - 0
137
+ hash: 1077930939435781644
128
138
  required_rubygems_version: !ruby/object:Gem::Requirement
129
139
  none: false
130
140
  requirements:
@@ -133,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
143
  version: 1.3.6
134
144
  requirements: []
135
145
  rubyforge_project:
136
- rubygems_version: 1.8.24
146
+ rubygems_version: 1.8.25
137
147
  signing_key:
138
148
  specification_version: 3
139
149
  summary: A scripting framework that replaces rake, sake and rubigen
@@ -146,6 +156,7 @@ test_files:
146
156
  - spec/actions/inject_into_file_spec.rb
147
157
  - spec/actions_spec.rb
148
158
  - spec/base_spec.rb
159
+ - spec/command_spec.rb
149
160
  - spec/core_ext/hash_with_indifferent_access_spec.rb
150
161
  - spec/core_ext/ordered_hash_spec.rb
151
162
  - spec/exit_condition_spec.rb
@@ -153,21 +164,23 @@ test_files:
153
164
  - spec/fixtures/app{1}/README
154
165
  - spec/fixtures/bundle/execute.rb
155
166
  - spec/fixtures/bundle/main.thor
167
+ - spec/fixtures/command.thor
156
168
  - spec/fixtures/doc/%file_name%.rb.tt
157
- - spec/fixtures/doc/COMMENTER
158
- - spec/fixtures/doc/README
159
169
  - spec/fixtures/doc/block_helper.rb
160
- - spec/fixtures/doc/components/.empty_directory
170
+ - spec/fixtures/doc/COMMENTER
161
171
  - spec/fixtures/doc/config.rb
162
172
  - spec/fixtures/doc/config.yaml.tt
173
+ - spec/fixtures/doc/excluding/%file_name%.rb.tt
174
+ - spec/fixtures/doc/README
163
175
  - spec/fixtures/enum.thor
164
176
  - spec/fixtures/group.thor
165
177
  - spec/fixtures/invoke.thor
166
178
  - spec/fixtures/path with spaces
167
179
  - spec/fixtures/preserve/script.sh
168
180
  - spec/fixtures/script.thor
169
- - spec/fixtures/task.thor
181
+ - spec/fixtures/subcommand.thor
170
182
  - spec/group_spec.rb
183
+ - spec/helper.rb
171
184
  - spec/invocation_spec.rb
172
185
  - spec/parser/argument_spec.rb
173
186
  - spec/parser/arguments_spec.rb
@@ -180,8 +193,6 @@ test_files:
180
193
  - spec/shell/color_spec.rb
181
194
  - spec/shell/html_spec.rb
182
195
  - spec/shell_spec.rb
183
- - spec/spec_helper.rb
184
- - spec/task_spec.rb
196
+ - spec/subcommand_spec.rb
185
197
  - spec/thor_spec.rb
186
198
  - spec/util_spec.rb
187
- has_rdoc:
data/.gitignore DELETED
@@ -1,44 +0,0 @@
1
- !.gitignore
2
- *.gem
3
- *.rbc
4
- *.sw[a-p]
5
- *.tmproj
6
- *.tmproject
7
- *.un~
8
- *~
9
- .Spotlight-V100
10
- .Trashes
11
- ._*
12
- .bundle
13
- .config
14
- .directory
15
- .elc
16
- .emacs.desktop
17
- .emacs.desktop.lock
18
- .idea
19
- .redcar
20
- .rvmrc
21
- .yardoc
22
- Desktop.ini
23
- Gemfile.lock
24
- Icon?
25
- InstalledFiles
26
- Session.vim
27
- \#*\#
28
- _yardoc
29
- auto-save-list
30
- coverage
31
- doc/
32
- lib/bundler/man
33
- pkg
34
- pkg/*
35
- rdoc
36
- spec/reports
37
- spec/sandbox
38
- test/tmp
39
- test/version_tmp
40
- tmp
41
- tmtags
42
- tramp
43
- .rbx
44
- b/
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --fail-fast
3
- --order random
@@ -1,8 +0,0 @@
1
- bundler_args: --without development
2
- language: ruby
3
- rvm:
4
- - 1.8.7
5
- - 1.9.2
6
- - 1.9.3
7
- - 2.0.0
8
- script: bundle exec thor spec
data/Gemfile DELETED
@@ -1,19 +0,0 @@
1
- source :rubygems
2
-
3
- gemspec
4
-
5
- gem 'rake', '~> 0.9'
6
- gem 'rdoc', '~> 3.9'
7
-
8
- group :development do
9
- gem 'pry'
10
- gem 'pry-debugger', :platforms => :mri_19
11
- end
12
-
13
- group :test do
14
- gem 'childlabor'
15
- gem 'fakeweb', '~> 1.3'
16
- gem 'rspec', '~> 2.11'
17
- gem 'rspec-mocks', :git => 'git://github.com/rspec/rspec-mocks.git'
18
- gem 'simplecov'
19
- end
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'ruby2ruby'
4
- require 'parse_tree'
5
- if Ruby2Ruby::VERSION >= "1.2.0"
6
- require 'parse_tree_extensions'
7
- end
8
- require 'rake'
9
-
10
- input = ARGV[0] || 'Rakefile'
11
- output = ARGV[1] || 'Thorfile'
12
-
13
- $requires = []
14
-
15
- module Kernel
16
- def require_with_record(file)
17
- $requires << file if caller[1] =~ /rake2thor:/
18
- require_without_record file
19
- end
20
- alias_method :require_without_record, :require
21
- alias_method :require, :require_with_record
22
- end
23
-
24
- load input
25
-
26
- @private_methods = []
27
-
28
- def file_task_name(name)
29
- "compile_" + name.gsub('/', '_slash_').gsub('.', '_dot_').gsub(/\W/, '_')
30
- end
31
-
32
- def method_for_task(task)
33
- file_task = task.is_a?(Rake::FileTask)
34
- comment = task.instance_variable_get('@comment')
35
- prereqs = task.instance_variable_get('@prerequisites').select(&Rake::Task.method(:task_defined?))
36
- actions = task.instance_variable_get('@actions')
37
- name = task.name.gsub(/^([^:]+:)+/, '')
38
- name = file_task_name(name) if file_task
39
- meth = ''
40
-
41
- meth << "desc #{name.inspect}, #{comment.inspect}\n" if comment
42
- meth << "def #{name}\n"
43
-
44
- meth << prereqs.map do |pre|
45
- pre = pre.to_s
46
- pre = file_task_name(pre) if Rake::Task[pre].is_a?(Rake::FileTask)
47
- ' ' + pre
48
- end.join("\n")
49
-
50
- meth << "\n\n" unless prereqs.empty? || actions.empty?
51
-
52
- meth << actions.map do |act|
53
- act = act.to_ruby
54
- unless act.gsub!(/^proc \{ \|(\w+)\|\n/,
55
- " \\1 = Struct.new(:name).new(#{name.inspect}) # A crude mock Rake::Task object\n")
56
- act.gsub!(/^proc \{\n/, '')
57
- end
58
- act.gsub(/\n\}$/, '')
59
- end.join("\n")
60
-
61
- meth << "\nend"
62
-
63
- if file_task
64
- @private_methods << meth
65
- return
66
- end
67
-
68
- meth
69
- end
70
-
71
- body = Rake::Task.tasks.map(&method(:method_for_task)).compact.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n")
72
-
73
- unless @private_methods.empty?
74
- body << "\n\n private\n\n"
75
- body << @private_methods.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n")
76
- end
77
-
78
- requires = $requires.map { |r| "require #{r.inspect}" }.join("\n")
79
-
80
- File.open(output, 'w') { |f| f.write(<<END.lstrip) }
81
- #{requires}
82
-
83
- class Default < Thor
84
- #{body}
85
- end
86
- END
@@ -1,9 +0,0 @@
1
- class File #:nodoc:
2
-
3
- unless File.respond_to?(:binread)
4
- def self.binread(file)
5
- File.open(file, 'rb') { |f| f.read }
6
- end
7
- end
8
-
9
- end
@@ -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
- expect(task(:bar => :required).formatted_usage(object)).to eq("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
- expect(task(:bar => :required).formatted_usage(object, false, true)).to eq("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
- expect(task(:bar => :required).formatted_usage(object)).to eq(":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
- expect(task(:foo => :required).formatted_usage(object)).to eq("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
- expect(Thor::DynamicTask.new('task').name).to eq('task')
38
- expect(Thor::DynamicTask.new('task').description).to eq('A dynamically-generated task')
39
- expect(Thor::DynamicTask.new('task').usage).to eq('task')
40
- expect(Thor::DynamicTask.new('task').options).to eq({})
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
- expect(task.options[:foo]).to 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
- expect(task.run(mock, [1, 2, 3])).to eq([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
- expect(task.run(klass.new)).to eq("can_has")
78
- end
79
- end
80
- end