sickle 0.5.2 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1395831ed21bc25480ccea83d34c99251520e03a
4
- data.tar.gz: f7e7bb6cc6aed1be1818a988fb7ce75c1e297fbc
3
+ metadata.gz: c3206ca92bf2b085c6ad94ebdc2d15639d8b2f60
4
+ data.tar.gz: 0509497cf3267976fda8065c9a4d1a6ec39fd099
5
5
  SHA512:
6
- metadata.gz: 1285b1aefad50bd5902610370c3f0bb2fa873c46f54f4bf1f67e65b274394f629fc9fe690c18cc22db30b8dfb5a9a8fb266f25fd2f8716e036187e85d18296a8
7
- data.tar.gz: 4f1a96bfeb568e42358996e139d98c8b7f5952bded27d584aae459bc3643a28439754d807a9b4dab68627c6d8ecca148522fc083f9295487c6ba0b3c59b5c770
6
+ metadata.gz: a7fb3fbbd7b40bffac21c6167639ac126316a1750cb17d207a42ec1326fe0e5d2ce91f801c0e530b6ce44bb91aaec4f695b5d29435755fd8b2ab5010fd4e45a1
7
+ data.tar.gz: b84b297c4aac6003c5c4b1d4bd0e65b2274cac71cd3b5c28038e79105e2cecc5d0748cb51c05c94012b0a3b2022eb56eb5ca7dfa525f3600dea202350464eb62
data/README.md CHANGED
@@ -46,6 +46,11 @@ class App
46
46
  global_flag :verbose # global flag, defaults to false
47
47
  global_option :with_prefix # global option, defaults to nil
48
48
 
49
+ # optional before hook with access to global options
50
+ before do
51
+ $verbose = options[:verbose]
52
+ end
53
+
49
54
  desc "install one of the available apps" # command description
50
55
  flag :force # flag for `install` command
51
56
  option :host, :default => "localhost" # option
data/lib/sickle.rb CHANGED
@@ -190,6 +190,10 @@ module Sickle
190
190
  end
191
191
  end
192
192
 
193
+ def before(&block)
194
+ @__before_hook = block
195
+ end
196
+
193
197
  def desc(label)
194
198
  Sickle.push_desc(label)
195
199
  end
@@ -252,6 +256,11 @@ module Sickle
252
256
 
253
257
  obj = self.new
254
258
  obj.instance_variable_set(:@__options, results)
259
+
260
+ if @__before_hook
261
+ obj.instance_exec(&@__before_hook)
262
+ end
263
+
255
264
  command.meth.bind(obj).call(*args)
256
265
  else
257
266
  puts "\e[31mCommand '#{command_name}' not found\e[0m"
@@ -1,3 +1,3 @@
1
1
  module Sickle
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
data/spec/main_spec.rb CHANGED
@@ -83,4 +83,16 @@ describe Sickle do
83
83
  $?.wont_equal 127
84
84
  end
85
85
  end
86
+
87
+ describe "before block" do
88
+ it "should set $verbose to false" do
89
+ App.run (%w(test-option))
90
+ $verbose.must_equal false
91
+ end
92
+
93
+ it "should set $verbose to true" do
94
+ App.run(%w(test-option --verbose))
95
+ $verbose.must_equal true
96
+ end
97
+ end
86
98
  end
data/spec/test_app.rb CHANGED
@@ -48,6 +48,10 @@ class App
48
48
  global_flag :verbose
49
49
  global_option :debug
50
50
 
51
+ before do
52
+ $verbose = options[:verbose]
53
+ end
54
+
51
55
  desc "Run task 1"
52
56
  flag :quiet
53
57
  option :with_prefix
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sickle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tymon Tobolski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-23 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler