wojtekmach-cli 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cli/app.rb CHANGED
@@ -10,6 +10,7 @@ module CLI
10
10
  @binary = binary
11
11
  @name = binary
12
12
  @actions = {}
13
+ @use_actions = false
13
14
  @proxy = Proxy.new(self)
14
15
  @args = []
15
16
  @opts = OptionParser.new
@@ -24,6 +25,8 @@ module CLI
24
25
 
25
26
  # Defines an action
26
27
  def action(name, &block)
28
+ @use_actions = true if name != "default"
29
+
27
30
  @actions[name] = block
28
31
  end
29
32
 
@@ -32,6 +35,10 @@ module CLI
32
35
  block = @actions[action_name]
33
36
 
34
37
  unless block
38
+ if action_name == "default"
39
+ raise RuntimeError, "Error: you have to define 'default' action"
40
+ end
41
+
35
42
  raise ArgumentError, "action '#{action_name}' not found"
36
43
  end
37
44
 
@@ -45,7 +52,7 @@ module CLI
45
52
  @args = args
46
53
 
47
54
  begin
48
- if args == []
55
+ if args == [] || @use_actions == false
49
56
  run "default"
50
57
  else
51
58
  run args[0]
data/lib/cli/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module CLI
2
2
  # Current CLI version
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
data/spec/cli/app_spec.rb CHANGED
@@ -79,4 +79,34 @@ module CLI
79
79
  end
80
80
  end
81
81
  end
82
+
83
+ describe App, "a simple app" do
84
+ before do
85
+ @app = App.new("hello") do
86
+ default do
87
+ puts args[0]
88
+ end
89
+ end
90
+ end
91
+
92
+ it "always runs the default action" do
93
+ $stdout.should_receive(:puts).with("Hello, World!")
94
+ @app.run!(["Hello, World!"])
95
+
96
+ $stdout.should_receive(:puts).with("1")
97
+ @app.run!(%w(1 2 3))
98
+ end
99
+ end
100
+
101
+ describe App, "blank app" do
102
+ describe "run!" do
103
+ it "should fail" do
104
+ @app = App.new("blank") do
105
+ end
106
+
107
+ $stdout.should_receive(:puts).with("Error: you have to define 'default' action")
108
+ @app.run!([])
109
+ end
110
+ end
111
+ end
82
112
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: wojtekmach-cli
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Wojciech Mach
@@ -87,6 +87,6 @@ rubyforge_project: cli
87
87
  rubygems_version: 1.3.9.1
88
88
  signing_key:
89
89
  specification_version: 3
90
- summary: cli-0.1.3
90
+ summary: cli-0.2.0
91
91
  test_files: []
92
92