thor 0.14.6 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.autotest +8 -0
  2. data/.document +5 -0
  3. data/.gemtest +0 -0
  4. data/.gitignore +44 -0
  5. data/.rspec +2 -0
  6. data/.travis.yml +9 -0
  7. data/CHANGELOG.rdoc +4 -4
  8. data/Gemfile +19 -0
  9. data/{LICENSE → LICENSE.md} +2 -2
  10. data/README.md +21 -300
  11. data/Thorfile +21 -15
  12. data/lib/thor.rb +56 -11
  13. data/lib/thor/actions.rb +7 -3
  14. data/lib/thor/actions/create_link.rb +1 -1
  15. data/lib/thor/actions/directory.rb +7 -3
  16. data/lib/thor/actions/empty_directory.rb +24 -5
  17. data/lib/thor/actions/file_manipulation.rb +40 -2
  18. data/lib/thor/base.rb +66 -28
  19. data/lib/thor/error.rb +6 -1
  20. data/lib/thor/group.rb +20 -8
  21. data/lib/thor/invocation.rb +4 -2
  22. data/lib/thor/parser/arguments.rb +6 -2
  23. data/lib/thor/parser/option.rb +3 -2
  24. data/lib/thor/parser/options.rb +13 -8
  25. data/lib/thor/rake_compat.rb +13 -8
  26. data/lib/thor/runner.rb +16 -4
  27. data/lib/thor/shell.rb +2 -2
  28. data/lib/thor/shell/basic.rb +86 -29
  29. data/lib/thor/shell/color.rb +40 -4
  30. data/lib/thor/shell/html.rb +28 -26
  31. data/lib/thor/task.rb +26 -8
  32. data/lib/thor/util.rb +26 -7
  33. data/lib/thor/version.rb +1 -1
  34. data/spec/actions/create_link_spec.rb +81 -0
  35. data/spec/actions/empty_directory_spec.rb +32 -0
  36. data/spec/actions/file_manipulation_spec.rb +61 -1
  37. data/spec/actions_spec.rb +4 -0
  38. data/spec/base_spec.rb +10 -5
  39. data/spec/exit_condition_spec.rb +19 -0
  40. data/spec/fixtures/script.thor +8 -2
  41. data/spec/group_spec.rb +39 -1
  42. data/spec/parser/arguments_spec.rb +1 -0
  43. data/spec/parser/options_spec.rb +12 -2
  44. data/spec/rake_compat_spec.rb +11 -7
  45. data/spec/register_spec.rb +43 -0
  46. data/spec/runner_spec.rb +34 -3
  47. data/spec/shell/basic_spec.rb +50 -3
  48. data/spec/shell/color_spec.rb +46 -6
  49. data/spec/shell/html_spec.rb +10 -5
  50. data/spec/spec_helper.rb +4 -0
  51. data/spec/task_spec.rb +26 -16
  52. data/spec/thor_spec.rb +56 -3
  53. data/thor.gemspec +26 -0
  54. metadata +174 -117
@@ -0,0 +1,8 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ at.clear_mappings
3
+ at.add_exception(/\.git/)
4
+ at.add_exception(/spec\/sandbox/)
5
+ at.add_mapping(%r{^spec/.*_spec}) {|filename,_| at.files_matching %r{#{filename}}}
6
+ at.add_mapping(%r{^bin/thor}) {|_,_| at.files_matching %r{spec/thor_runner_spec}}
7
+ at.add_mapping(%r{}) {|_,_| at.files_matching %r{spec/.*_spec}}
8
+ end
@@ -0,0 +1,5 @@
1
+ lib/*.rb
2
+ lib/**/*.rb
3
+ -
4
+ CHANGELOG.rdoc
5
+ LICENSE.md
File without changes
@@ -0,0 +1,44 @@
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 ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order random
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - jruby-18mode
4
+ - jruby-19mode
5
+ - 1.8.7
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - ruby-head
9
+ script: bundle exec thor spec
@@ -1,8 +1,8 @@
1
1
  == 0.14, released 2010-07-25
2
2
 
3
- * Added CreateLink class and #link_file method
3
+ * Added CreateLink class and #link_file method
4
4
  * Made Thor::Actions#run use system as default method for system calls
5
- * Allow use of private methods from superclass as tasks
5
+ * Allow use of private methods from superclass as tasks
6
6
  * Added mute(&block) method which allows to run block without any output
7
7
  * Removed config[:pretend]
8
8
  * Enabled underscores for command line switches
@@ -38,7 +38,7 @@
38
38
 
39
39
  * thor help now show information about any class/task. All those calls are
40
40
  possible:
41
-
41
+
42
42
  thor help describe
43
43
  thor help describe:amazing
44
44
 
@@ -68,7 +68,7 @@
68
68
  are in the 'standard' group. Running 'thor -T' will only show the standard
69
69
  tasks - adding --all will show all tasks. You can also filter on a specific
70
70
  group using the --group option: thor -T --group advanced
71
-
71
+
72
72
  == 0.9.6, released 2008-09-13
73
73
 
74
74
  * Generic improvements
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ platforms :jruby do
6
+ gem 'jruby-openssl', '~> 0.7'
7
+ end
8
+
9
+ platforms :mri_18 do
10
+ gem 'ruby-debug', '>= 0.10.3'
11
+ end
12
+
13
+ platforms :mri_19 do
14
+ gem 'ruby-debug19'
15
+ end
16
+
17
+ group :development do
18
+ gem 'pry'
19
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Yehuda Katz
1
+ Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,307 +1,28 @@
1
- # Thor
1
+ [![Build Status](https://secure.travis-ci.org/wycats/thor.png?branch=master)](http://travis-ci.org/wycats/thor)
2
2
 
3
- ## Description
3
+ Thor
4
+ ====
4
5
 
5
- Thor is a simple and efficient tool for building self-documenting command line utilities. It removes the pain of parsing command line options, writing "USAGE:" banners, and can also be used as an alternative to the [Rake](http://github.com/jimweirich/rake) build tool. The syntax is Rake-like, so it should be familiar to most Rake users.
6
+ Description
7
+ -----------
8
+ Thor is a simple and efficient tool for building self-documenting command line
9
+ utilities. It removes the pain of parsing command line options, writing
10
+ "USAGE:" banners, and can also be used as an alternative to the [Rake][rake]
11
+ build tool. The syntax is Rake-like, so it should be familiar to most Rake
12
+ users.
6
13
 
7
- ## Installation
14
+ [rake]: https://github.com/jimweirich/rake
8
15
 
9
- $ gem install thor
16
+ Installation
17
+ ------------
18
+ gem install thor
10
19
 
11
- or
20
+ Usage and documentation
21
+ -----------------------
22
+ Please see [the wiki](https://github.com/wycats/thor/wiki) for basic usage and other documentation on using Thor.
12
23
 
13
- $ gem install wycats-thor -s http://gems.github.com
24
+ License
25
+ -------
26
+ Released under the MIT License. See the [LICENSE][license] file for further details.
14
27
 
15
- ## Usage
16
-
17
- Map options to a class. Simply create a class with the appropriate annotations
18
- and have options automatically map to functions and parameters.
19
-
20
- Example:
21
-
22
- class App < Thor # [1]
23
- map "-L" => :list # [2]
24
-
25
- desc "install APP_NAME", "install one of the available apps" # [3]
26
- method_options :force => :boolean, :alias => :string # [4]
27
- def install(name)
28
- user_alias = options[:alias]
29
- if options.force?
30
- # do something
31
- end
32
- # other code
33
- end
34
-
35
- desc "list [SEARCH]", "list all of the available apps, limited by SEARCH"
36
- def list(search="")
37
- # list everything
38
- end
39
- end
40
-
41
- Thor automatically maps commands as such:
42
-
43
- thor app:install myname --force
44
-
45
- That gets converted to:
46
-
47
- App.new.install("myname")
48
- # with {'force' => true} as options hash
49
-
50
- 1. Inherit from Thor to turn a class into an option mapper.
51
- 2. Map additional non-valid identifiers to specific methods. In this case, convert -L to :list
52
- 3. Describe the method immediately below. The first parameter is the usage information, and the second parameter is the description.
53
- 4. Provide any additional options that will be available the instance method options.
54
-
55
- ## Types for <tt>method_options</tt>
56
-
57
- * :boolean - is parsed as <tt>--option</tt> or <tt>--option=true</tt>
58
- * :string - is parsed as <tt>--option=VALUE</tt>
59
- * :numeric - is parsed as <tt>--option=N</tt>
60
- * :array - is parsed as <tt>--option=one two three</tt>
61
- * :hash - is parsed as <tt>--option=name:string age:integer</tt>
62
-
63
- Besides, method_option allows a default value to be given. Examples:
64
-
65
- method_options :force => false
66
- #=> Creates a boolean option with default value false
67
-
68
- method_options :alias => "bar"
69
- #=> Creates a string option with default value "bar"
70
-
71
- method_options :threshold => 3.0
72
- #=> Creates a numeric option with default value 3.0
73
-
74
- You can also supply <tt>:option => :required</tt> to mark an option as required. The
75
- type is assumed to be string. If you want a required hash with default values
76
- as option, you can use <tt>method_option</tt> which uses a more declarative style:
77
-
78
- method_option :attributes, :type => :hash, :default => {}, :required => true
79
-
80
- All arguments can be set to nil (except required arguments), by suppling a no or
81
- skip variant. For example:
82
-
83
- thor app name --no-attributes
84
-
85
- In previous versions, aliases for options were created automatically, but now
86
- they should be explicit. You can supply aliases in both short and declarative
87
- styles:
88
-
89
- method_options %w( force -f ) => :boolean
90
-
91
- Or:
92
-
93
- method_option :force, :type => :boolean, :aliases => "-f"
94
-
95
- You can supply as many aliases as you want.
96
-
97
- NOTE: Type :optional available in Thor 0.9.0 was deprecated. Use :string or :boolean instead.
98
-
99
- ## Namespaces
100
-
101
- By default, your Thor tasks are invoked using Ruby namespace. In the example
102
- above, tasks are invoked as:
103
-
104
- thor app:install name --force
105
-
106
- However, you could namespace your class as:
107
-
108
- module Sinatra
109
- class App < Thor
110
- # tasks
111
- end
112
- end
113
-
114
- And then you should invoke your tasks as:
115
-
116
- thor sinatra:app:install name --force
117
-
118
- If desired, you can change the namespace:
119
-
120
- module Sinatra
121
- class App < Thor
122
- namespace :myapp
123
- # tasks
124
- end
125
- end
126
-
127
- And then your tasks should be invoked as:
128
-
129
- thor myapp:install name --force
130
-
131
- ## Invocations
132
-
133
- Thor comes with a invocation-dependency system as well, which allows a task to be invoked only once. For example:
134
-
135
- class Counter < Thor
136
- desc "one", "Prints 1, 2, 3"
137
- def one
138
- puts 1
139
- invoke :two
140
- invoke :three
141
- end
142
-
143
- desc "two", "Prints 2, 3"
144
- def two
145
- puts 2
146
- invoke :three
147
- end
148
-
149
- desc "three", "Prints 3"
150
- def three
151
- puts 3
152
- end
153
- end
154
-
155
- When invoking the task one:
156
-
157
- thor counter:one
158
-
159
- The output is "1 2 3", which means that the three task was invoked only once.
160
- You can even invoke tasks from another class, so be sure to check the
161
- [documentation](http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor.html).
162
-
163
- Notice invocations do not share the same object. I.e, Thor will instantiate Counter once to invoke the task one, then, it instantiates another to invoke the task two and another for task three. This happens to allow options and arguments to parsed again. For example, if two and three have different options and both of them were given to the command line, calling invoke makes them be parsed each time and used accordingly by each task.
164
-
165
- ## Thor::Group
166
-
167
- Thor has a special class called Thor::Group. The main difference to Thor class
168
- is that it invokes all tasks at once. The example above could be rewritten in
169
- Thor::Group as this:
170
-
171
- class Counter < Thor::Group
172
- desc "Prints 1, 2, 3"
173
-
174
- def one
175
- puts 1
176
- end
177
-
178
- def two
179
- puts 2
180
- end
181
-
182
- def three
183
- puts 3
184
- end
185
- end
186
-
187
- When invoked:
188
-
189
- thor counter
190
-
191
- It prints "1 2 3" as well. Notice you should describe (using the method <tt>desc</tt>)
192
- only the class and not each task anymore. Thor::Group is a great tool to create
193
- generators, since you can define several steps which are invoked in the order they
194
- are defined (Thor::Group is the tool use in generators in Rails 3.0).
195
-
196
- Besides, Thor::Group can parse arguments and options as Thor tasks:
197
-
198
- class Counter < Thor::Group
199
- # number will be available as attr_accessor
200
- argument :number, :type => :numeric, :desc => "The number to start counting"
201
- desc "Prints the 'number' given upto 'number+2'"
202
-
203
- def one
204
- puts number + 0
205
- end
206
-
207
- def two
208
- puts number + 1
209
- end
210
-
211
- def three
212
- puts number + 2
213
- end
214
- end
215
-
216
- The counter above expects one parameter and has the folling outputs:
217
-
218
- thor counter 5
219
- # Prints "5 6 7"
220
-
221
- thor counter 11
222
- # Prints "11 12 13"
223
-
224
- You can also give options to Thor::Group, but instead of using <tt>method_option</tt>
225
- and <tt>method_options</tt>, you should use <tt>class_option</tt> and <tt>class_options</tt>.
226
- Both argument and class_options methods are available to Thor class as well.
227
-
228
- ## Actions
229
-
230
- Thor comes with several actions which helps with script and generator tasks. You
231
- might be familiar with them since some came from Rails Templates. They are:
232
- <tt>say</tt>, <tt>ask</tt>, <tt>yes?</tt>, <tt>no?</tt>, <tt>add_file</tt>,
233
- <tt>remove_file</tt>, <tt>copy_file</tt>, <tt>template</tt>, <tt>directory</tt>,
234
- <tt>inside</tt>, <tt>run</tt>, <tt>inject_into_file</tt> and a couple more.
235
-
236
- To use them, you just need to include Thor::Actions in your Thor classes:
237
-
238
- class App < Thor
239
- include Thor::Actions
240
- # tasks
241
- end
242
-
243
- Some actions like copy file requires that a class method called source_root is
244
- defined in your class. This is the directory where your templates should be
245
- placed. Be sure to check the documentation on [actions](http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html).
246
-
247
- ## Generators
248
-
249
- A great use for Thor is creating custom generators. Combining Thor::Group,
250
- Thor::Actions and ERB templates makes this very easy. Here is an example:
251
-
252
- class Newgem < Thor::Group
253
- include Thor::Actions
254
-
255
- # Define arguments and options
256
- argument :name
257
- class_option :test_framework, :default => :test_unit
258
-
259
- def self.source_root
260
- File.dirname(__FILE__)
261
- end
262
-
263
- def create_lib_file
264
- template('templates/newgem.tt', "#{name}/lib/#{name}.rb")
265
- end
266
-
267
- def create_test_file
268
- test = options[:test_framework] == "rspec" ? :spec : :test
269
- create_file "#{name}/#{test}/#{name}_#{test}.rb"
270
- end
271
-
272
- def copy_licence
273
- if yes?("Use MIT license?")
274
- # Make a copy of the MITLICENSE file at the source root
275
- copy_file "MITLICENSE", "#{name}/MITLICENSE"
276
- else
277
- say "Shame on you…", :red
278
- end
279
- end
280
- end
281
-
282
- Doing a <tt>thor -T</tt> will show how to run our generator. It should read:
283
- <tt>thor newgem NAME</tt>. This shows that we have to supply a NAME
284
- argument for our generator to run.
285
-
286
- The <tt>create_lib_file</tt> uses an ERB template. This is what it looks like:
287
-
288
- class <%= name.capitalize %>
289
- end
290
-
291
- The arguments that you set in your generator will automatically be passed in
292
- when <tt>template</tt> gets called. Be sure to read the [documentation](http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html) for
293
- more options.
294
-
295
- Running the generator with <tt>thor newgem devise</tt> will
296
- create two files: "devise/lib/devise.rb", and "devise/test/devise_test.rb". The user will then be asked (via a prompt by the <tt>yes?</tt> method) whether or not they would like to copy the MIT License. If you want to change the test framework, you can add the option: <tt>thor newgem devise --test-framework=rspec</tt>
297
-
298
- This will generate two files - "devise/lib/devise.rb" and "devise/spec/devise_spec.rb".
299
-
300
- ## Further Reading
301
-
302
- Thor offers many scripting possibilities beyond these examples. Be sure to read
303
- through the [documentation](http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor.html) and [specs](http://github.com/wycats/thor/tree/master/spec/) to get a better understanding of the options available.
304
-
305
- ## License
306
-
307
- Released under the MIT License. See the LICENSE file for further details.
28
+ [license]: https://github.com/wycats/thor/blob/master/LICENSE.md