ppl 1.17.2 → 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f013c471444b4ddf23abbcdff7ba445c44dcecd9
4
- data.tar.gz: 9455d8d1e984d55adb0f4e711309c4e74ea8765d
3
+ metadata.gz: 6a9d02380f3d44f146c22dd0e466d98ae56ac97d
4
+ data.tar.gz: e85bf61f41a01927c72450f761563ad9669c5fdd
5
5
  SHA512:
6
- metadata.gz: 3622e85128d613fd52f9c931ff631f63c77dfca590780d554865f206730b39b88b3168980603b47d257e2ba225d5cf4f62e10688413584cf6bf31b4a1520df90
7
- data.tar.gz: 3b73edb07693aa19e74ab8066c8a16846a82cb61bda2bbc3585935c7a5b358f35fecccebbf7c6cc2cccfc823bc0a7fc423abdcb7d1fefbf56034354bd7e86ddc
6
+ metadata.gz: 0f325d2c01e00c070edac9f3c6066185bf13bb20c7c25f1c659534485a833e28b7b5b6c7a25b42fe016f33b417800df2567a7ae591b8736a49027cc1cdada069
7
+ data.tar.gz: a388cc2f1f2af9c50afa01da54ac54994c9d2b25f290a75e07bc041b8f9c4051c27697fc997bdaec46d2739c920d7d610eeb814261610c90525ac1e30b1c9cca
@@ -27,6 +27,14 @@ class Ppl::Application::Bootstrap
27
27
  bday
28
28
  end
29
29
 
30
+ register :command_completion do
31
+ completion = Ppl::Command::Completion.new
32
+ directory = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__))))
33
+ directory = File.join(directory, "completions")
34
+ completion.completions_directory = Dir.new(directory)
35
+ completion
36
+ end
37
+
30
38
  register :command_email do
31
39
  email = Ppl::Command::Email.new
32
40
  email.storage = storage_adapter
@@ -162,6 +170,7 @@ class Ppl::Application::Bootstrap
162
170
  suite.add_command command_add
163
171
  suite.add_command command_age
164
172
  suite.add_command command_bday
173
+ suite.add_command command_completion
165
174
  suite.add_command command_email
166
175
  suite.add_command command_help
167
176
  suite.add_command command_init
@@ -11,6 +11,8 @@ class Ppl::Application::Shell
11
11
  command = select_command(input)
12
12
  prepare_command(command, input)
13
13
  outcome = execute_command(command, input, output)
14
+ rescue Ppl::Error::CompletionNotFound
15
+ output.error("ppl: No completion function available for '#{$!}'")
14
16
  rescue Ppl::Error::ContactNotFound
15
17
  output.error("ppl: Contact '#{$!}' not found")
16
18
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument, Ppl::Error::IncorrectUsage
@@ -0,0 +1,37 @@
1
+
2
+ class Ppl::Command::Completion < Ppl::Application::Command
3
+
4
+ name "completion"
5
+ description "Output shell completion function"
6
+
7
+ attr_writer :completions_directory
8
+
9
+ def options(parser, options)
10
+ parser.banner = "usage: ppl completion <shell>"
11
+ end
12
+
13
+ def execute(input, output)
14
+ shell_name = require_shell_name(input)
15
+ location = require_completion_existence(shell_name)
16
+ output.line(File.read(location))
17
+ end
18
+
19
+ private
20
+
21
+ def require_shell_name(input)
22
+ if input.arguments.first.nil?
23
+ raise Ppl::Error::IncorrectUsage, "No shell specified"
24
+ end
25
+ input.arguments.shift
26
+ end
27
+
28
+ def require_completion_existence(shell_name)
29
+ path = File.join(@completions_directory.path, shell_name)
30
+ if !File.exists? path
31
+ raise Ppl::Error::CompletionNotFound, shell_name
32
+ end
33
+ path
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,4 @@
1
+
2
+ class Ppl::Error::CompletionNotFound < StandardError
3
+ end
4
+
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "1.17.2"
4
+ Version = "1.18.0"
5
5
 
6
6
  module Adapter
7
7
  end
@@ -63,11 +63,13 @@ require "ppl/command/shell"
63
63
  require "ppl/command/url"
64
64
  require "ppl/command/version"
65
65
  require "ppl/command/external"
66
+ require "ppl/command/completion"
66
67
 
67
68
  require "ppl/entity/address_book"
68
69
  require "ppl/entity/contact"
69
70
  require "ppl/entity/postal_address"
70
71
 
72
+ require "ppl/error/completion_not_found"
71
73
  require "ppl/error/contact_not_found"
72
74
  require "ppl/error/incorrect_usage"
73
75
 
data/ppl.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
  Gem::Specification.new do |spec|
3
3
 
4
4
  spec.name = "ppl"
5
- spec.version = "1.17.2"
6
- spec.date = "2013-04-14"
5
+ spec.version = "1.18.0"
6
+ spec.date = "2013-04-16"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
9
9
 
@@ -23,6 +23,20 @@ describe Ppl::Application::Bootstrap do
23
23
  end
24
24
  end
25
25
 
26
+ describe "#command_completion" do
27
+ it "should return a Ppl::Command::Completion" do
28
+ @bootstrap.command_completion.should be_a(Ppl::Command::Completion)
29
+ end
30
+ it "should inject a completions directory" do
31
+ Ppl::Command::Completion.stub(:new) do
32
+ completion = double(Ppl::Command::Completion)
33
+ completion.should_receive(:completions_directory=)
34
+ completion
35
+ end
36
+ @bootstrap.command_completion
37
+ end
38
+ end
39
+
26
40
  describe "#command_email" do
27
41
  it "should return a Ppl::Command::Email" do
28
42
  @bootstrap.command_email.should be_a(Ppl::Command::Email)
@@ -405,6 +419,9 @@ describe Ppl::Application::Bootstrap do
405
419
  it "should contain the 'bday' command" do
406
420
  @bootstrap.command_suite.find_command("bday").should_not be nil
407
421
  end
422
+ it "should contain the 'completion' command" do
423
+ @bootstrap.command_suite.find_command("completion").should_not be nil
424
+ end
408
425
  it "should contain the 'email' command" do
409
426
  @bootstrap.command_suite.find_command("email").should_not be nil
410
427
  end
@@ -91,6 +91,14 @@ describe Ppl::Application::Shell do
91
91
  @shell.run(@input, @output)
92
92
  end
93
93
 
94
+ it "should handle CompletionNotFound errors nicely" do
95
+ @command.stub(:options)
96
+ @command.should_receive(:execute) { raise Ppl::Error::CompletionNotFound, "example" }
97
+ @router.should_receive(:route).and_return(@command)
98
+ @output.should_receive(:error).with("ppl: No completion function available for 'example'")
99
+ @shell.run(@input, @output)
100
+ end
101
+
94
102
  end
95
103
 
96
104
  end
@@ -0,0 +1,47 @@
1
+
2
+ describe Ppl::Command::Completion do
3
+
4
+ before(:each) do
5
+ @command = Ppl::Command::Completion.new
6
+ @input = Ppl::Application::Input.new
7
+ @output = double(Ppl::Application::Output)
8
+ @directory = double(Dir)
9
+ @command.completions_directory = @directory
10
+ end
11
+
12
+ describe "#name" do
13
+ it "should be 'completion'" do
14
+ @command.name.should eq "completion"
15
+ end
16
+ end
17
+
18
+ describe "#execute" do
19
+
20
+ before(:each) do
21
+ @directory.stub(:path).and_return("")
22
+ File.stub(:exists?).and_return(true)
23
+ File.stub(:read)
24
+ end
25
+
26
+ it "should raise an error if no shell is specified" do
27
+ @input.arguments = []
28
+ expect{@command.execute(@input, @output)}.to raise_error(Ppl::Error::IncorrectUsage)
29
+ end
30
+
31
+ it "should raise an error if the shell is not recognised" do
32
+ @input.arguments = ["invalidshell"]
33
+ File.should_receive(:exists?).with("/invalidshell").and_return(false)
34
+ expect{@command.execute(@input, @output)}.to raise_error(Ppl::Error::CompletionNotFound)
35
+ end
36
+
37
+ it "should read the function from disk and print it to stdout" do
38
+ @input.arguments = ["zsh"]
39
+ File.should_receive(:read).and_return("completion function")
40
+ @output.should_receive(:line).with("completion function")
41
+ @command.execute(@input, @output)
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.2
4
+ version: 1.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-14 00:00:00.000000000 Z
11
+ date: 2013-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -177,6 +177,7 @@ files:
177
177
  - lib/ppl/command/age.rb
178
178
  - lib/ppl/command/attribute.rb
179
179
  - lib/ppl/command/bday.rb
180
+ - lib/ppl/command/completion.rb
180
181
  - lib/ppl/command/email.rb
181
182
  - lib/ppl/command/external.rb
182
183
  - lib/ppl/command/help.rb
@@ -197,6 +198,7 @@ files:
197
198
  - lib/ppl/entity/address_book.rb
198
199
  - lib/ppl/entity/contact.rb
199
200
  - lib/ppl/entity/postal_address.rb
201
+ - lib/ppl/error/completion_not_found.rb
200
202
  - lib/ppl/error/contact_not_found.rb
201
203
  - lib/ppl/error/incorrect_usage.rb
202
204
  - lib/ppl/format/address_book.rb
@@ -246,6 +248,7 @@ files:
246
248
  - spec/ppl/command/age_spec.rb
247
249
  - spec/ppl/command/attribute_spec.rb
248
250
  - spec/ppl/command/bday_spec.rb
251
+ - spec/ppl/command/completion_spec.rb
249
252
  - spec/ppl/command/email_spec.rb
250
253
  - spec/ppl/command/external_spec.rb
251
254
  - spec/ppl/command/help_spec.rb