kerplutz 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.md +6 -0
- data/Rakefile +4 -0
- data/kerplutz.gemspec +1 -1
- data/lib/kerplutz/command_map.rb +4 -0
- data/lib/kerplutz/executable.rb +22 -26
- data/spec/kerplutz/executable_spec.rb +29 -2
- metadata +4 -3
data/History.txt
ADDED
data/README.md
CHANGED
@@ -11,8 +11,14 @@ generally a pretty slick library, even if its interface is a bit wonky.
|
|
11
11
|
It seemed like a shame to let it go to waste, when getting from it what
|
12
12
|
I needed requires only a small amount of code.
|
13
13
|
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Real documentation will be forthcoming, but for now see
|
17
|
+
`features/kerplutz.feature`.
|
18
|
+
|
14
19
|
## Todo
|
15
20
|
|
21
|
+
* README docs for builder and option types
|
16
22
|
* Read defaults from a config file
|
17
23
|
* Argument type-casts
|
18
24
|
* List arguments
|
data/Rakefile
CHANGED
data/kerplutz.gemspec
CHANGED
data/lib/kerplutz/command_map.rb
CHANGED
data/lib/kerplutz/executable.rb
CHANGED
@@ -23,26 +23,32 @@ module Kerplutz
|
|
23
23
|
top.add_option(option, false)
|
24
24
|
end
|
25
25
|
|
26
|
+
# TODO: Extract this method into separate class that gives all
|
27
|
+
# the involved parties the chance to parse all of the args
|
26
28
|
def parse(args)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
29
|
+
if args[0] =~ /^(--help|help)$/
|
30
|
+
first, *rest = args
|
31
|
+
if rest.empty?
|
32
|
+
puts banner
|
33
|
+
else
|
34
|
+
puts commands[rest.first].help
|
35
|
+
end
|
36
|
+
elsif cmd = args.find { |el| commands.has_command?(el) }
|
37
|
+
cmd_idx = args.index(cmd)
|
38
|
+
top_args, cmd_args = args.partition.with_index do |_arg, idx|
|
39
|
+
idx < cmd_idx
|
40
|
+
end
|
41
|
+
top.parse(top_args)
|
42
|
+
remainder = commands[cmd].parse(cmd_args[1..-1])
|
41
43
|
else
|
42
|
-
|
44
|
+
if args.empty?
|
45
|
+
puts banner
|
46
|
+
else
|
47
|
+
remainder = top.parse(args)
|
48
|
+
end
|
43
49
|
end
|
44
50
|
|
45
|
-
[arguments, remainder]
|
51
|
+
[arguments, remainder || []]
|
46
52
|
end
|
47
53
|
|
48
54
|
def banner
|
@@ -51,15 +57,5 @@ module Kerplutz
|
|
51
57
|
help << " Commands:\n" << commands.summary << "\n"
|
52
58
|
help << "Type '#{name} help COMMAND' for help with a specific command.\n"
|
53
59
|
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def help
|
58
|
-
/^(--help|help)$/
|
59
|
-
end
|
60
|
-
|
61
|
-
def option
|
62
|
-
/^(--|-)[\w-]+$/
|
63
|
-
end
|
64
60
|
end
|
65
61
|
end
|
@@ -2,12 +2,39 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Kerplutz
|
4
4
|
describe Executable do
|
5
|
-
|
5
|
+
let(:option) { Flag.new(:foo, '', :bar) }
|
6
|
+
let(:command) { Command.new(:foo, '') }
|
7
|
+
|
8
|
+
subject do
|
9
|
+
exec = Executable.new("test")
|
10
|
+
exec.add_option(option)
|
11
|
+
exec.add_command(command)
|
12
|
+
exec
|
13
|
+
end
|
6
14
|
|
7
15
|
describe "#parse" do
|
8
16
|
it "extracts the options from the arguments" do
|
9
|
-
subject.add_option(Switch.new(:foo, ''))
|
10
17
|
subject.parse(["--foo"]).should == [{ :foo => true }, []]
|
18
|
+
subject.parse(["--foo", "bar"]).should == [{ :foo => "bar" }, []]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "parses an unambiguous flag argument" do
|
22
|
+
subject.top.should_receive(:parse).with(["--foo", "bar"])
|
23
|
+
subject.parse(["--foo", "bar"])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "parses an ambiguous flag argument" do
|
27
|
+
subject.top.should_receive(:parse).with(["--foo"])
|
28
|
+
command.should_receive(:parse).with([])
|
29
|
+
subject.parse(["--foo", "foo"])
|
30
|
+
|
31
|
+
subject.top.should_receive(:parse).with(["--foo"])
|
32
|
+
command.should_receive(:parse).with(["-x"])
|
33
|
+
subject.parse(["--foo", "foo", "-x"])
|
34
|
+
|
35
|
+
subject.top.should_receive(:parse).with(["--foo"])
|
36
|
+
command.should_receive(:parse).with(["foo", "-x"])
|
37
|
+
subject.parse(["--foo", "foo", "foo", "-x"])
|
11
38
|
end
|
12
39
|
end
|
13
40
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mike Sassak
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- .rvmrc
|
72
72
|
- Gemfile
|
73
73
|
- Gemfile.lock
|
74
|
+
- History.txt
|
74
75
|
- LICENSE
|
75
76
|
- README.md
|
76
77
|
- Rakefile
|
@@ -120,7 +121,7 @@ rubyforge_project:
|
|
120
121
|
rubygems_version: 1.3.7
|
121
122
|
signing_key:
|
122
123
|
specification_version: 3
|
123
|
-
summary: kerplutz 0.1.
|
124
|
+
summary: kerplutz 0.1.1
|
124
125
|
test_files:
|
125
126
|
- features/kerplutz.feature
|
126
127
|
- features/step_definitions/kerplutz_steps.rb
|