tcollier-commando 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/lib/commando/interpreter.rb +7 -6
- data/lib/commando/version.rb +1 -1
- data/lib/commando.rb +3 -4
- metadata +2 -3
- data/lib/commando/validation_error.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 616c0c39dc6ef5e239dd4b357b735cab2c1361a5
|
4
|
+
data.tar.gz: 38905d35b013e6c7905429d3d6cf999f8f2cfe82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e223e84795fa85613a8928ff1243a2f614d70a87b47f2b6062584b2c98eceb440938358c486843045a5127f7480897ab7ba990043e27b2997559c1d86835d0
|
7
|
+
data.tar.gz: b19ca353543f8e878320e963d75574735d0bf5723f7fa1bf5c759124a6ab0ddc6c7028a542518c1e5a8bb83710bea3ef5a03b07a048c700213f8af149ba42c75
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Commando
|
2
2
|
|
3
|
-
|
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
|
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
|
70
|
+
then method should raise an `ArgumentError` with a descriptive message.
|
68
71
|
|
69
72
|
#### Default actions
|
70
73
|
|
data/lib/commando/interpreter.rb
CHANGED
@@ -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(
|
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
|
-
|
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 :
|
26
|
+
attr_reader :output
|
26
27
|
end
|
27
28
|
|
28
29
|
private_constant :Interpreter
|
data/lib/commando/version.rb
CHANGED
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
|
36
|
-
interpreter.interpret
|
35
|
+
interpreter.interpret(line)
|
37
36
|
end
|
38
|
-
rescue
|
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.
|
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-
|
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:
|