tcollier-commando 0.2.1 → 1.0.0

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: 5325137899697d0e9166e6cbe578ac16be28753e
4
- data.tar.gz: b27473af548a18cc382444b85d20574a7b1a1e58
3
+ metadata.gz: 616c0c39dc6ef5e239dd4b357b735cab2c1361a5
4
+ data.tar.gz: 38905d35b013e6c7905429d3d6cf999f8f2cfe82
5
5
  SHA512:
6
- metadata.gz: 2068d9b73e94d36a392f7be87bcef00df62bc6d18a089ea319ac565ab06f3b7ab40b5508767457af5cd00c4c43da15605cc03764fdfc02f5e1ef3e6836bf07f1
7
- data.tar.gz: e87b4c3b616b2342cb016bc5837489dbc54727c1be30b054a401442099e8bac64ae18825a35058ef11db6914b80c1e846e3ffcb1a20f1f48c13e3f9c0900e917
6
+ metadata.gz: 65e223e84795fa85613a8928ff1243a2f614d70a87b47f2b6062584b2c98eceb440938358c486843045a5127f7480897ab7ba990043e27b2997559c1d86835d0
7
+ data.tar.gz: b19ca353543f8e878320e963d75574735d0bf5723f7fa1bf5c759124a6ab0ddc6c7028a542518c1e5a8bb83710bea3ef5a03b07a048c700213f8af149ba42c75
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Commando
2
2
 
3
- A command line interface builder with Readline support
3
+ Boxers? Briefs? Commando!
4
+
5
+ _A command line interface builder with Readline support_
4
6
 
5
7
  ## Versions
6
8
 
@@ -9,13 +11,14 @@ A command line interface builder with Readline support
9
11
  * `0.1.2` - Remove empty lines from history
10
12
  * `0.2.0` - Persist history across CLI sessions
11
13
  * `0.2.1` - Fix bug when history file doesn't exist
14
+ * `1.0.0` - Use `ArgumentError` instead of custom error for bad args
12
15
 
13
16
  ## Installation
14
17
 
15
18
  Add this line to your application's Gemfile:
16
19
 
17
20
  ```ruby
18
- gem 'commando'
21
+ gem 'tcollier-commando'
19
22
  ```
20
23
 
21
24
  And then execute:
@@ -24,7 +27,7 @@ And then execute:
24
27
 
25
28
  Or install it yourself as:
26
29
 
27
- $ gem install commando
30
+ $ gem install tcollier-commando
28
31
 
29
32
  ## Configuration
30
33
 
@@ -57,14 +60,14 @@ To support a new command, you must register it with
57
60
 
58
61
  #### Action role
59
62
 
60
- The `Action role` responds to `perform(args, output:)`, where
63
+ The `Action` role responds to `perform(args, output:)`, where
61
64
 
62
65
  * `args` [`Array<String>`] - the list of the extra words that follow the command
63
66
  (e.g. if the user types `addfriend mary jane`, then the args are `['mary', 'jane']`).
64
67
  * `output` [`IO`] - the IO instance that any messages should be written to.
65
68
 
66
69
  If the arguments are not formatted correctly (e.g. the user missed an argument),
67
- then method should raise a `Commando::ValidationError` with a descriptive message.
70
+ then method should raise an `ArgumentError` with a descriptive message.
68
71
 
69
72
  #### Default actions
70
73
 
@@ -1,16 +1,17 @@
1
1
  module Commando
2
2
  # Interpret a single command from the user.
3
3
  class Interpreter
4
- # @param input [String] the entire command line string.
5
4
  # @param output [IO] the stream any actions should write messages to.
6
- def initialize(input:, output: $stdout)
7
- @args = input.split(' ')
8
- @command = @args.shift
5
+ def initialize(output: $stdout)
9
6
  @output = output
10
7
  end
11
8
 
12
9
  # Performs the action (if valid) for the given input command line
13
- def interpret
10
+ #
11
+ # @param line [String] the entire command line string.
12
+ def interpret(line)
13
+ args = line.split(' ')
14
+ command = args.shift
14
15
  action = Commando.config.lookup(command)
15
16
 
16
17
  if action.nil?
@@ -22,7 +23,7 @@ module Commando
22
23
 
23
24
  private
24
25
 
25
- attr_reader :command, :args, :output
26
+ attr_reader :output
26
27
  end
27
28
 
28
29
  private_constant :Interpreter
@@ -1,3 +1,3 @@
1
1
  module Commando
2
- VERSION = '0.2.1'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/commando.rb CHANGED
@@ -2,7 +2,6 @@ require_relative 'commando/config'
2
2
  require_relative 'commando/interpreter'
3
3
  require_relative 'commando/io_handler'
4
4
  require_relative 'commando/quit_exception'
5
- require_relative 'commando/validation_error'
6
5
  require_relative 'commando/version'
7
6
 
8
7
  # Entry point for the Command Line Interface (CLI).
@@ -26,16 +25,16 @@ module Commando
26
25
  output.puts config.greeting
27
26
 
28
27
  io = IOHandler.new(output: output)
28
+ interpreter = Interpreter.new(output: output)
29
29
 
30
30
  loop do
31
31
  begin
32
32
  if line = io.readline
33
33
  # When the user enters a non-empty string, pass the line to the
34
34
  # interpreter and handle the command.
35
- interpreter = Interpreter.new(input: line, output: output)
36
- interpreter.interpret
35
+ interpreter.interpret(line)
37
36
  end
38
- rescue ValidationError => error
37
+ rescue ArgumentError => error
39
38
  output.puts "Error: #{error}"
40
39
  rescue QuitException
41
40
  break
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcollier-commando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Collier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-07 00:00:00.000000000 Z
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,7 +78,6 @@ files:
78
78
  - lib/commando/interpreter.rb
79
79
  - lib/commando/io_handler.rb
80
80
  - lib/commando/quit_exception.rb
81
- - lib/commando/validation_error.rb
82
81
  - lib/commando/version.rb
83
82
  homepage: https://github.com/tcollier/commando
84
83
  licenses:
@@ -1,4 +0,0 @@
1
- module Commando
2
- class ValidationError < StandardError
3
- end
4
- end