shake 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gems ADDED
@@ -0,0 +1 @@
1
+ contest
@@ -0,0 +1,4 @@
1
+ *~
2
+ .rvmrc
3
+ pkg/
4
+ test/tmp/
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
- Shake
2
- =====
3
-
4
- **Simple command runner.**
1
+ # Shake
2
+ #### Simple command runner.
5
3
 
6
4
  Goals:
7
5
 
@@ -19,21 +17,23 @@ Why not Rake or Thor?
19
17
  Shake was made with the idea of being easily-embeddable into your projects
20
18
  for your command line runners. It's a single ~4kb Ruby file.
21
19
 
22
- # Shakefile
23
- # Place this file in your project somewhere
24
- class Shake
25
- task(:start) {
26
- puts "Starting '#{params.join(' ')}'..."
27
- }
20
+ ``` ruby
21
+ # Shakefile
22
+ # Place this file in your project somewhere
23
+ class Shake
24
+ task(:start) {
25
+ puts "Starting '#{params.join(' ')}'..."
26
+ }
28
27
 
29
- task.description = "Starts something"
28
+ task.description = "Starts something"
30
29
 
31
- task(:stop) {
32
- puts "Stopping..."
33
- }
30
+ task(:stop) {
31
+ puts "Stopping..."
32
+ }
34
33
 
35
- task.description = "Stops it"
36
- end
34
+ task.description = "Stops it"
35
+ end
36
+ ```
37
37
 
38
38
  In your shell:
39
39
 
@@ -56,13 +56,15 @@ Usage
56
56
 
57
57
  Using the command `shake` will load your project's `Shakefile`.
58
58
 
59
- # ~/project/Shakefile
60
- class Shake
61
- task(:deploy) do
62
- puts "Deploying..."
63
- system "ssh admin@server.com git pull && thin restart"
64
- end
65
- end
59
+ ``` ruby
60
+ # ~/project/Shakefile
61
+ class Shake
62
+ task(:deploy) do
63
+ puts "Deploying..."
64
+ system "ssh admin@server.com git pull && thin restart"
65
+ end
66
+ end
67
+ ```
66
68
 
67
69
  And in your shell:
68
70
 
@@ -74,10 +76,12 @@ And in your shell:
74
76
 
75
77
  Get the parameters with `params` (an array). Verify parameters with `wrong_usage`.
76
78
 
77
- task(:init) do
78
- wrong_usage if params.empty?
79
- system "wget #{params.first}"
80
- end
79
+ ``` ruby
80
+ task(:init) do
81
+ wrong_usage if params.empty?
82
+ system "wget #{params.first}"
83
+ end
84
+ ```
81
85
 
82
86
  Example:
83
87
 
@@ -90,62 +94,74 @@ Example:
90
94
  You may get params from it with `params.extract` or `params.delete`. Doing `extract`
91
95
  will remove it from params.
92
96
 
93
- task(:create) do
94
- type = params.extract('-t') || 'default'
95
- quiet = params.delete('-q')
96
- file = params.shift
97
- wrong_usage if params.any?
97
+ ``` ruby
98
+ task(:create) do
99
+ type = params.extract('-t') || 'default'
100
+ quiet = params.delete('-q')
101
+ file = params.shift
102
+ wrong_usage if params.any?
98
103
 
99
- puts "Creating '#{file}' (quiet: #{!!quiet}, type: #{type})"
100
- end
104
+ puts "Creating '#{file}' (quiet: #{!!quiet}, type: #{type})"
105
+ end
106
+ ```
101
107
 
102
108
  Example:
103
109
 
104
- $ shake create #=> Invalid
105
- $ shake create foobar #=> Creating 'foobar' (quiet: false, type: default)
106
- $ shake create foobar -q #=> Creating 'foobar' (quiet: true, type: default)
107
- $ shake create foobar -t xyz #=> Creating 'foobar' (quiet: false, type: xyz)
110
+ ``` bash
111
+ $ shake create #=> Invalid
112
+ $ shake create foobar #=> Creating 'foobar' (quiet: false, type: default)
113
+ $ shake create foobar -q #=> Creating 'foobar' (quiet: true, type: default)
114
+ $ shake create foobar -t xyz #=> Creating 'foobar' (quiet: false, type: xyz)
115
+ ```
108
116
 
109
- # Common commands
117
+ ### Common commands
110
118
 
111
119
  Use `err` to print something to STDERR. Use `pass` to halt execution.
112
120
 
113
- task(:delete) do
114
- unless File.exists?(params.first)
115
- err 'You can't delete something that doesn't exist!'
116
- pass
117
- end
121
+ ``` ruby
122
+ task(:delete) do
123
+ unless File.exists?(params.first)
124
+ err 'You can't delete something that doesn't exist!'
125
+ pass
126
+ end
118
127
 
119
- FileUtils.rm_rf params.first
120
- end
128
+ FileUtils.rm_rf params.first
129
+ end
130
+ ```
121
131
 
122
132
  You may also pass parameters to `pass` to have it printed out before halting.
123
133
 
124
- pass 'The target already exists.' if File.exists?(target)
134
+ ``` ruby
135
+ pass 'The target already exists.' if File.exists?(target)
136
+ ```
125
137
 
126
138
  ### Default tasks
127
139
 
128
140
  Use `default` to specify a default task. (The default task is usually `help`)
129
141
 
130
- class Shake
131
- task(:test) do
132
- Dir['test/**/*_test.rb'].each { |f| load f }
133
- end
142
+ ``` ruby
143
+ class Shake
144
+ task(:test) do
145
+ Dir['test/**/*_test.rb'].each { |f| load f }
146
+ end
134
147
 
135
- default :test
136
- end
148
+ default :test
149
+ end
137
150
 
138
- # Typing `shake` will be the same as `shake test`
151
+ # Typing `shake` will be the same as `shake test`
152
+ ```
139
153
 
140
154
  ### Invalid commands
141
155
 
142
- Use `invalid` to define what happens when
156
+ Use `invalid` to define what happens when you invoke a wrong command.
143
157
 
144
- class Shake
145
- invalid {
146
- err "Invalid command. What's wrong with you?"
147
- }
148
- end
158
+ ``` ruby
159
+ class Shake
160
+ invalid {
161
+ err "Invalid command. What's wrong with you?"
162
+ }
163
+ end
164
+ ```
149
165
 
150
166
  In your shell:
151
167
 
@@ -156,35 +172,41 @@ In your shell:
156
172
 
157
173
  Tasks are executed in the class's context, so just define your helpers like so:
158
174
 
159
- module Helpers
160
- def say_status(what, str)
161
- puts "%15s %s" % [ what, str ]
162
- end
163
- end
175
+ ``` ruby
176
+ module Helpers
177
+ def say_status(what, str)
178
+ puts "%15s %s" % [ what, str ]
179
+ end
180
+ end
164
181
 
165
- class Shake
166
- extend Helpers
167
- end
182
+ class Shake
183
+ extend Helpers
184
+ end
185
+ ```
168
186
 
169
187
  Then use them in your tasks.
170
188
 
171
- class Shake
172
- task(:info) do
173
- say_status :info, "It's a fine day"
174
- end
175
- end
189
+ ``` ruby
190
+ class Shake
191
+ task(:info) do
192
+ say_status :info, "It's a fine day"
193
+ end
194
+ end
195
+ ```
176
196
 
177
197
  ### Manual invocation
178
198
 
179
199
  You can use shake in your projects without using the `shake` command. (recommended!)
180
200
 
181
- require 'shake'
201
+ ``` ruby
202
+ require 'shake'
182
203
 
183
- # If you want to load your own project file (optional)
184
- file = Shake.find_in_project('Projectfile') and load file
204
+ # If you want to load your own project file (optional)
205
+ file = Shake.find_in_project('Projectfile') and load file
185
206
 
186
- # Now define some tasks, and then:
187
- Shake.run!
207
+ # Now define some tasks, and then:
208
+ Shake.run!
209
+ ```
188
210
 
189
211
  ### Subclassing Shake
190
212
 
@@ -193,37 +215,44 @@ You may subclass shake for your own project.
193
215
  By default, it will not have any of the default tasks (that is, `shake help`, and
194
216
  the "invalid command" message). Use `include Defaults` if you want this behavior.
195
217
 
196
- require 'shake'
218
+ ``` ruby
219
+ require 'shake'
197
220
 
198
- class CLI < Shake
199
- include Defaults # optional, see above
221
+ class CLI < Shake
222
+ include Defaults # optional, see above
200
223
 
201
- task(:flip) do
202
- what = rand < 0.5 ? "heads" : "tails"
203
- puts "The coin says #{what}"
204
- end
205
- end
224
+ task(:flip) do
225
+ what = rand < 0.5 ? "heads" : "tails"
226
+ puts "The coin says #{what}"
227
+ end
228
+ end
206
229
 
207
- CLI.run!
230
+ CLI.run!
231
+ ```
208
232
 
209
233
  ### Defining tasks
210
234
 
211
- # In your Shakefile or something
212
- class Shake
213
- task(:reset) do
214
- # ...
215
- end
235
+ ``` ruby
236
+ # In your Shakefile or something
237
+ class Shake
238
+ task(:reset) do
239
+ # ...
240
+ end
216
241
 
217
- task.description = "Resets passwords."
218
- end
242
+ # These are optional
243
+ task.description = "Resets passwords."
244
+ task.usage = "reset USERNAME"
245
+ end
246
+ ```
219
247
 
220
248
  Alternatively:
221
249
 
222
- class Shake
223
- task(:reset) do
224
- # ...
225
- end
226
-
227
- task(:reset).description = "Resets passwords."
228
- end
250
+ ``` ruby
251
+ class Shake
252
+ task(:reset) do
253
+ # ...
254
+ end
229
255
 
256
+ task(:reset).description = "Resets passwords."
257
+ end
258
+ ```
data/Rakefile CHANGED
@@ -2,4 +2,13 @@ task :test do
2
2
  Dir['test/**/*_test.rb'].each { |f| load f }
3
3
  end
4
4
 
5
+ desc "Invokes the test suite in multiple RVM environments"
6
+ task :'test!' do
7
+ # Override this by adding RVM_TEST_ENVS=".." in .rvmrc
8
+ envs = ENV['RVM_TEST_ENVS'] || '1.9.2@shake,1.8.7@shake'
9
+ puts "* Testing in the following RVM environments: #{envs.gsub(',', ', ')}"
10
+ system "rvm #{envs} rake test"
11
+ end
12
+
13
+
5
14
  task :default => :test
@@ -1,7 +1,7 @@
1
1
  require 'ostruct'
2
2
 
3
3
  class Shake
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
 
6
6
  Abort = Class.new(StandardError)
7
7
 
@@ -164,14 +164,16 @@ class Shake
164
164
  err "Usage: #{executable} <command>"
165
165
  err
166
166
  err "Commands:"
167
- tasks.each { |name, task| err " %-20s %s" % [ name, task.description ] }
167
+ tasks.each { |name, task| err " %-20s %s" % [ task.usage || name, task.description ] }
168
168
  }
169
169
 
170
170
  to.task(:help).description = "Shows a list of commands"
171
171
 
172
172
  to.invalid {
173
173
  if task(command)
174
+ usage = task(command).usage
174
175
  err "Invalid usage."
176
+ err "Usage: `#{executable} #{usage}`\n" if usage
175
177
  err "See `#{executable} help` for more info."
176
178
  else
177
179
  err "Unknown command: #{command}"
@@ -0,0 +1,12 @@
1
+ require "./lib/shake"
2
+ Gem::Specification.new do |s|
3
+ s.name = "shake"
4
+ s.version = Shake::VERSION
5
+ s.summary = %{Simple command line runner.}
6
+ s.description = %Q{Shake is a simple replacement for Thor/Rake.}
7
+ s.authors = ["Rico Sta. Cruz"]
8
+ s.email = ["rico@sinefunc.com"]
9
+ s.homepage = "http://github.com/rstacruz/shake"
10
+ s.files = `git ls-files`.strip.split("\n")
11
+ s.executables = Dir["bin/*"].map { |f| File.basename(f) }
12
+ end
@@ -6,4 +6,8 @@ class Shake
6
6
  def self.err(str='')
7
7
  $err << "#{str}\n"
8
8
  end
9
+
10
+ def self.executable
11
+ "shake"
12
+ end
9
13
  end
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class HelpTest < Test::Unit::TestCase
4
+ class Bake < ::Shake
5
+ include Shake::Defaults
6
+
7
+ task :build do
8
+ wrong_usage
9
+ puts "work!"
10
+ end
11
+
12
+ task.usage = "build SOMETHING"
13
+ task.description = "Builds."
14
+
15
+ task :destroy do
16
+ wrong_usage
17
+ puts "die!"
18
+ end
19
+ end
20
+
21
+ test 'help' do
22
+ Bake.run 'help'
23
+ assert cout == ""
24
+ assert cerr.include? "build SOMETHING"
25
+ assert cerr.include? "Builds."
26
+ assert cerr.include? "destroy"
27
+ end
28
+
29
+ test 'wrong_usage' do
30
+ Bake.run 'build'
31
+
32
+ assert ! cout.include?("work!")
33
+ assert cerr.include?("Invalid usage")
34
+ assert cerr.include?("shake build SOMETHING")
35
+ end
36
+
37
+ test 'wrong_usage 2' do
38
+ Bake.run 'destroy'
39
+
40
+ assert ! cout.include?("die!")
41
+ assert cerr.include?("Invalid usage")
42
+ assert ! cerr.include?("shake destroy")
43
+ end
44
+ end
metadata CHANGED
@@ -1,69 +1,65 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: shake
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
4
5
  prerelease:
5
- version: 0.1.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Rico Sta. Cruz
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-02-20 00:00:00 +08:00
12
+ date: 2011-08-31 00:00:00.000000000 +08:00
14
13
  default_executable:
15
14
  dependencies: []
16
-
17
15
  description: Shake is a simple replacement for Thor/Rake.
18
- email:
16
+ email:
19
17
  - rico@sinefunc.com
20
- executables:
18
+ executables:
21
19
  - shake
22
20
  extensions: []
23
-
24
21
  extra_rdoc_files: []
25
-
26
- files:
22
+ files:
23
+ - .gems
24
+ - .gitignore
25
+ - HISTORY.md
26
+ - README.md
27
+ - Rakefile
28
+ - bin/shake
29
+ - examples/example
30
+ - examples/example2
27
31
  - lib/shake.rb
32
+ - shake.gemspec
28
33
  - test/mock.rb
29
34
  - test/test_helper.rb
35
+ - test/unit/help_test.rb
30
36
  - test/unit/params_test.rb
31
37
  - test/unit/shakefile_test.rb
32
38
  - test/unit/subclass_test.rb
33
39
  - test/unit/traverse_test.rb
34
- - examples/example
35
- - examples/example2
36
- - HISTORY.md
37
- - README.md
38
- - Rakefile
39
- - bin/shake
40
40
  has_rdoc: true
41
41
  homepage: http://github.com/rstacruz/shake
42
42
  licenses: []
43
-
44
43
  post_install_message:
45
44
  rdoc_options: []
46
-
47
- require_paths:
45
+ require_paths:
48
46
  - lib
49
- required_ruby_version: !ruby/object:Gem::Requirement
47
+ required_ruby_version: !ruby/object:Gem::Requirement
50
48
  none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: "0"
55
- required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
54
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: "0"
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
61
59
  requirements: []
62
-
63
60
  rubyforge_project:
64
- rubygems_version: 1.5.0
61
+ rubygems_version: 1.6.2
65
62
  signing_key:
66
63
  specification_version: 3
67
64
  summary: Simple command line runner.
68
65
  test_files: []
69
-