vim-jar 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/Gemfile.lock +4 -1
  2. data/bin/vim-jar +1 -57
  3. data/bundler/ruby/1.8/bin/rake2thor +19 -0
  4. data/bundler/ruby/1.8/bin/thor +19 -0
  5. data/bundler/ruby/1.8/gems/thor-0.14.6/CHANGELOG.rdoc +103 -0
  6. data/bundler/ruby/1.8/gems/thor-0.14.6/LICENSE +20 -0
  7. data/bundler/ruby/1.8/gems/thor-0.14.6/README.md +307 -0
  8. data/bundler/ruby/1.8/gems/thor-0.14.6/Thorfile +24 -0
  9. data/bundler/ruby/1.8/gems/thor-0.14.6/bin/rake2thor +86 -0
  10. data/bundler/ruby/1.8/gems/thor-0.14.6/bin/thor +6 -0
  11. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/create_file.rb +105 -0
  12. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/create_link.rb +57 -0
  13. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/directory.rb +93 -0
  14. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/empty_directory.rb +134 -0
  15. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb +270 -0
  16. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/inject_into_file.rb +109 -0
  17. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions.rb +314 -0
  18. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/base.rb +579 -0
  19. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/core_ext/file_binary_read.rb +9 -0
  20. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  21. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/core_ext/ordered_hash.rb +100 -0
  22. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/error.rb +30 -0
  23. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/group.rb +273 -0
  24. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/invocation.rb +168 -0
  25. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/argument.rb +67 -0
  26. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/arguments.rb +161 -0
  27. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/option.rb +120 -0
  28. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/options.rb +173 -0
  29. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser.rb +4 -0
  30. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/rake_compat.rb +66 -0
  31. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/runner.rb +309 -0
  32. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell/basic.rb +290 -0
  33. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell/color.rb +108 -0
  34. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell/html.rb +121 -0
  35. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell.rb +88 -0
  36. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/task.rb +114 -0
  37. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/util.rb +229 -0
  38. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/version.rb +3 -0
  39. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor.rb +334 -0
  40. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/create_file_spec.rb +170 -0
  41. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/directory_spec.rb +136 -0
  42. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/empty_directory_spec.rb +98 -0
  43. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/file_manipulation_spec.rb +310 -0
  44. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/inject_into_file_spec.rb +135 -0
  45. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions_spec.rb +322 -0
  46. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/base_spec.rb +269 -0
  47. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
  48. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/core_ext/ordered_hash_spec.rb +115 -0
  49. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/application.rb +2 -0
  50. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/bundle/execute.rb +6 -0
  51. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/bundle/main.thor +1 -0
  52. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  53. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/README +3 -0
  54. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/block_helper.rb +3 -0
  55. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/components/.empty_directory +0 -0
  56. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/config.rb +1 -0
  57. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/group.thor +114 -0
  58. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/invoke.thor +112 -0
  59. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/path with spaces +0 -0
  60. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/script.thor +184 -0
  61. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/task.thor +10 -0
  62. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/group_spec.rb +178 -0
  63. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/invocation_spec.rb +100 -0
  64. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/argument_spec.rb +47 -0
  65. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/arguments_spec.rb +64 -0
  66. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/option_spec.rb +202 -0
  67. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/options_spec.rb +319 -0
  68. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/rake_compat_spec.rb +68 -0
  69. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/register_spec.rb +92 -0
  70. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/runner_spec.rb +210 -0
  71. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell/basic_spec.rb +223 -0
  72. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell/color_spec.rb +41 -0
  73. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell/html_spec.rb +27 -0
  74. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell_spec.rb +47 -0
  75. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/spec_helper.rb +54 -0
  76. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/task_spec.rb +69 -0
  77. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/thor_spec.rb +334 -0
  78. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/util_spec.rb +163 -0
  79. data/bundler/ruby/1.8/specifications/thor-0.14.6.gemspec +48 -0
  80. data/lib/vim-jar/cli.rb +84 -67
  81. data/lib/vim-jar/config.rb +9 -0
  82. data/lib/vim-jar/installer/git.rb +8 -7
  83. data/lib/vim-jar/plugin.rb +61 -18
  84. data/lib/vim-jar/version.rb +1 -1
  85. data/lib/vim-jar.rb +1 -0
  86. data/spec/vim-jar/config_spec.rb +17 -0
  87. data/spec/vim-jar/git-config +16 -0
  88. data/spec/vim-jar/gitmodules +6 -0
  89. data/spec/vim-jar/plugin_spec.rb +46 -0
  90. data/vim-jar.gemspec +1 -0
  91. metadata +104 -9
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vim-jar (0.0.1)
4
+ vim-jar (0.0.2)
5
5
  curb
6
+ thor
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
@@ -31,6 +32,7 @@ GEM
31
32
  ruby-debug-base (0.10.4)
32
33
  linecache (>= 0.3)
33
34
  ruby-progressbar (0.0.9)
35
+ thor (0.14.6)
34
36
 
35
37
  PLATFORMS
36
38
  ruby
@@ -41,4 +43,5 @@ DEPENDENCIES
41
43
  rr
42
44
  rspec
43
45
  ruby-debug
46
+ thor
44
47
  vim-jar!
data/bin/vim-jar CHANGED
@@ -1,27 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'optparse'
4
-
5
- options = {}
6
-
7
- opt = OptionParser.new do |opts|
8
- opts.banner = "Usage: vim-jar [command] options"
9
- opts.separator ""
10
- opts.separator " Commands:"
11
- opts.separator " init -- init environment"
12
- opts.separator " install NAME -- install plugin"
13
- opts.separator " list -- list all avaliable plugins"
14
- opts.separator " installed -- list all installed plugins"
15
- opts.separator " import -- import plugin info from github.com"
16
- opts.separator " e.g: vim-jar import https://github.com/vim-scripts/ZenCoding.vim"
17
- opts.on("-h", "--help") do
18
- STDOUT.puts opt
19
- exit 0
20
- end
21
- end
22
-
23
- opt.parse!
24
-
25
3
  if ENV['VIM_JAR_TEST']
26
4
  $:.unshift File.expand_path("./../lib", File.dirname(__FILE__)) #TODO remove me before release
27
5
  require 'rubygems'
@@ -29,40 +7,6 @@ end
29
7
 
30
8
  require 'vim-jar/cli'
31
9
 
32
- if ARGV.first.nil?
33
- puts opt
34
- exit 0
35
- end
36
-
37
- def print_error(msg)
38
- STDERR.puts msg
39
- end
40
-
41
- case ARGV.first
42
- when "init"
43
- Vim::Jar::Cli.init
44
- when "install"
45
- if plugin_name = ARGV[1]
46
- Vim::Jar::Cli.install(plugin_name)
47
- else
48
- print_error "missing plugin name"
49
- exit 1
50
- end
51
- when "list"
52
- Vim::Jar::Cli.list
53
- when "import"
54
- if github_url = ARGV[1]
55
- Vim::Jar::Cli.import(github_url)
56
- else
57
- print_error "github repository url"
58
- exit 1
59
- end
60
- when "installed"
61
- ::Vim::Jar::Cli.installed
62
- else
63
- print_error "missing command"
64
- puts opt
65
- exit 0
66
- end
10
+ Vim::Jar::Cli.start
67
11
 
68
12
 
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ version = ">= 0"
12
+
13
+ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
14
+ version = $1
15
+ ARGV.shift
16
+ end
17
+
18
+ gem 'thor', version
19
+ load Gem.bin_path('thor', 'rake2thor', version)
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ version = ">= 0"
12
+
13
+ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
14
+ version = $1
15
+ ARGV.shift
16
+ end
17
+
18
+ gem 'thor', version
19
+ load Gem.bin_path('thor', 'thor', version)
@@ -0,0 +1,103 @@
1
+ == 0.14, released 2010-07-25
2
+
3
+ * Added CreateLink class and #link_file method
4
+ * Made Thor::Actions#run use system as default method for system calls
5
+ * Allow use of private methods from superclass as tasks
6
+ * Added mute(&block) method which allows to run block without any output
7
+ * Removed config[:pretend]
8
+ * Enabled underscores for command line switches
9
+ * Added Thor::Base.basename which is used by both Thor.banner and Thor::Group.banner
10
+ * Deprecated invoke() without arguments
11
+ * Added :only and :except to check_unknown_options
12
+
13
+ == 0.13, released 2010-02-03
14
+
15
+ * Added :lazy_default which is only triggered if a switch is given
16
+ * Added Thor::Shell::HTML
17
+ * Added subcommands
18
+ * Decoupled Thor::Group and Thor, so it's easier to vendor
19
+ * Added check_unknown_options! in case you want error messages to be raised in valid switches
20
+ * run(command) should return the results of command
21
+
22
+ == 0.12, released 2010-01-02
23
+
24
+ * Methods generated by attr_* are automatically not marked as tasks
25
+ * inject_into_file does not add the same content twice, unless :force is set
26
+ * Removed rr in favor to rspec mock framework
27
+ * Improved output for thor -T
28
+ * [#7] Do not force white color on status
29
+ * [#8] Yield a block with the filename on directory
30
+
31
+ == 0.11, released 2009-07-01
32
+
33
+ * Added a rake compatibility layer. It allows you to use spec and rdoc tasks on
34
+ Thor classes.
35
+
36
+ * BACKWARDS INCOMPATIBLE: aliases are not generated automatically anymore
37
+ since it may cause wrong behavior in the invocation system.
38
+
39
+ * thor help now show information about any class/task. All those calls are
40
+ possible:
41
+
42
+ thor help describe
43
+ thor help describe:amazing
44
+
45
+ Or even with default namespaces:
46
+
47
+ thor help :spec
48
+
49
+ * Thor::Runner now invokes the default task if none is supplied:
50
+
51
+ thor describe # invokes the default task, usually help
52
+
53
+ * Thor::Runner now works with mappings:
54
+
55
+ thor describe -h
56
+
57
+ * Added some documentation and code refactoring.
58
+
59
+ == 0.9.8, released 2008-10-20
60
+
61
+ * Fixed some tiny issues that were introduced lately.
62
+
63
+ == 0.9.7, released 2008-10-13
64
+
65
+ * Setting global method options on the initialize method works as expected:
66
+ All other tasks will accept these global options in addition to their own.
67
+ * Added 'group' notion to Thor task sets (class Thor); by default all tasks
68
+ are in the 'standard' group. Running 'thor -T' will only show the standard
69
+ tasks - adding --all will show all tasks. You can also filter on a specific
70
+ group using the --group option: thor -T --group advanced
71
+
72
+ == 0.9.6, released 2008-09-13
73
+
74
+ * Generic improvements
75
+
76
+ == 0.9.5, released 2008-08-27
77
+
78
+ * Improve Windows compatibility
79
+ * Update (incorrect) README and task.thor sample file
80
+ * Options hash is now frozen (once returned)
81
+ * Allow magic predicates on options object. For instance: `options.force?`
82
+ * Add support for :numeric type
83
+ * BACKWARDS INCOMPATIBLE: Refactor Thor::Options. You cannot access shorthand forms in options hash anymore (for instance, options[:f])
84
+ * Allow specifying optional args with default values: method_options(:user => "mislav")
85
+ * Don't write options for nil or false values. This allows, for example, turning color off when running specs.
86
+ * Exit with the status of the spec command to help CI stuff out some.
87
+
88
+ == 0.9.4, released 2008-08-13
89
+
90
+ * Try to add Windows compatibility.
91
+ * BACKWARDS INCOMPATIBLE: options hash is now accessed as a property in your class and is not passed as last argument anymore
92
+ * Allow options at the beginning of the argument list as well as the end.
93
+ * Make options available with symbol keys in addition to string keys.
94
+ * Allow true to be passed to Thor#method_options to denote a boolean option.
95
+ * If loading a thor file fails, don't give up, just print a warning and keep going.
96
+ * Make sure that we re-raise errors if they happened further down the pipe than we care about.
97
+ * Only delete the old file on updating when the installation of the new one is a success
98
+ * Make it Ruby 1.8.5 compatible.
99
+ * Don't raise an error if a boolean switch is defined multiple times.
100
+ * Thor::Options now doesn't parse through things that look like options but aren't.
101
+ * Add URI detection to install task, and make sure we don't append ".thor" to URIs
102
+ * Add rake2thor to the gem binfiles.
103
+ * Make sure local Thorfiles override system-wide ones.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Yehuda Katz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
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.
@@ -0,0 +1,307 @@
1
+ # Thor
2
+
3
+ ## Description
4
+
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
+
7
+ ## Installation
8
+
9
+ $ gem install thor
10
+
11
+ or
12
+
13
+ $ gem install wycats-thor -s http://gems.github.com
14
+
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.
@@ -0,0 +1,24 @@
1
+ # enconding: utf-8
2
+ require 'thor/rake_compat'
3
+
4
+ class Default < Thor
5
+ include Thor::RakeCompat
6
+
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ require 'bundler'
11
+ Bundler::GemHelper.install_tasks
12
+
13
+ require 'rdoc/task'
14
+ if defined?(RDoc)
15
+ RDoc::Task.new do |rdoc|
16
+ rdoc.main = 'README.md'
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'thor'
19
+ rdoc.rdoc_files.include('README.md', 'LICENSE', 'CHANGELOG.rdoc', 'Thorfile')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,86 @@
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
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require 'thor/runner'
5
+ $thor_runner = true
6
+ Thor::Runner.start