ppl 1.13.0 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ppl/application/bootstrap.rb +7 -0
- data/lib/ppl/application/router.rb +19 -1
- data/lib/ppl/command/execute.rb +2 -0
- data/lib/ppl.rb +1 -1
- data/ppl.gemspec +1 -1
- data/spec/ppl/application/router_spec.rb +10 -0
- metadata +1 -1
@@ -44,6 +44,12 @@ class Ppl::Application::Bootstrap
|
|
44
44
|
return config
|
45
45
|
end
|
46
46
|
|
47
|
+
def execute_command
|
48
|
+
command = Ppl::Command::Execute.new(nil, nil, nil)
|
49
|
+
command.storage = storage_adapter
|
50
|
+
command
|
51
|
+
end
|
52
|
+
|
47
53
|
def git_commands
|
48
54
|
[
|
49
55
|
Ppl::Command::Execute.new("pull", "git pull", "Execute 'git pull' in the address book directory"),
|
@@ -66,6 +72,7 @@ class Ppl::Application::Bootstrap
|
|
66
72
|
router = Ppl::Application::Router.new(command_suite)
|
67
73
|
router.aliases = configuration.aliases
|
68
74
|
router.default = "help"
|
75
|
+
router.execute_command = execute_command
|
69
76
|
return router
|
70
77
|
end
|
71
78
|
|
@@ -3,6 +3,7 @@ class Ppl::Application::Router
|
|
3
3
|
|
4
4
|
attr_accessor :aliases
|
5
5
|
attr_accessor :default
|
6
|
+
attr_accessor :execute_command
|
6
7
|
|
7
8
|
def initialize(command_suite)
|
8
9
|
@command_suite = command_suite
|
@@ -12,7 +13,11 @@ class Ppl::Application::Router
|
|
12
13
|
def route(argument)
|
13
14
|
command = @command_suite.find_command(argument)
|
14
15
|
if command.nil? && @aliases.has_key?(argument)
|
15
|
-
|
16
|
+
if is_bang_alias?(argument)
|
17
|
+
command = create_execute_command(argument)
|
18
|
+
else
|
19
|
+
command = @command_suite.find_command(@aliases[argument])
|
20
|
+
end
|
16
21
|
end
|
17
22
|
if command.nil? && !@default.nil?
|
18
23
|
command = @command_suite.find_command(@default)
|
@@ -20,5 +25,18 @@ class Ppl::Application::Router
|
|
20
25
|
return command
|
21
26
|
end
|
22
27
|
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def is_bang_alias?(key)
|
32
|
+
@aliases[key].match(/^!/)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_execute_command(key)
|
36
|
+
@execute_command.name = key
|
37
|
+
@execute_command.command = @aliases[key][1..-1]
|
38
|
+
@execute_command
|
39
|
+
end
|
40
|
+
|
23
41
|
end
|
24
42
|
|
data/lib/ppl/command/execute.rb
CHANGED
data/lib/ppl.rb
CHANGED
data/ppl.gemspec
CHANGED
@@ -5,6 +5,9 @@ describe Ppl::Application::Router do
|
|
5
5
|
@suite = Ppl::Application::CommandSuite.new
|
6
6
|
@router = Ppl::Application::Router.new(@suite)
|
7
7
|
|
8
|
+
@execute = double(Ppl::Command::Execute)
|
9
|
+
@router.execute_command = @execute
|
10
|
+
|
8
11
|
@cmd_one = Ppl::Application::Command.new
|
9
12
|
@cmd_one.name = "one"
|
10
13
|
|
@@ -42,6 +45,13 @@ describe Ppl::Application::Router do
|
|
42
45
|
@router.route("t").should be @cmd_two
|
43
46
|
end
|
44
47
|
|
48
|
+
it "should return a Ppl::Command::Execute if the input matches a bang alias" do
|
49
|
+
@execute.should_receive(:name=).with("t")
|
50
|
+
@execute.should_receive(:command=).with("two")
|
51
|
+
@router.aliases = {"t" => "!two"}
|
52
|
+
@router.route("t").should be @execute
|
53
|
+
end
|
54
|
+
|
45
55
|
end
|
46
56
|
|
47
57
|
end
|