clive 1.2.0 → 1.2.1
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 +7 -0
- data/lib/clive/parser.rb +31 -6
- data/lib/clive/version.rb +1 -1
- data/spec/clive/a_cli_spec.rb +14 -0
- data/spec/clive/parser_spec.rb +9 -9
- metadata +52 -57
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91b3667e70d3210280746c68a18588e387e1ecf2
|
4
|
+
data.tar.gz: a253732d58c0b2cd45f8b8f715418938a489cef8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67f7ae4f03fe3531cebe93da7e9c0527d450e1c290c7cdec3603821505577ee655367676a611ff7c17dcd5d2fe6313f6cf0379365b527f0fb1408b0c16afa679
|
7
|
+
data.tar.gz: 6348de02dacec424fb5fabcbc55cc893b2b2a26fff74d965a03231de1e25222ed80b96267935b0a456dd5e13d544eae4e180c4d62f7e299d5188b6b8b59af56c
|
data/lib/clive/parser.rb
CHANGED
@@ -24,18 +24,18 @@ class Clive
|
|
24
24
|
@config = DEFAULTS.merge(config)
|
25
25
|
end
|
26
26
|
|
27
|
-
# The parser should work how you expect. It allows you to put global options
|
28
|
-
# before and after a command section (if it exists, which it doesn't), so
|
27
|
+
# The parser should work how you expect. It allows you to put global options
|
28
|
+
# before and after a command section (if it exists, which it doesn't), so
|
29
29
|
# you have something like.
|
30
30
|
#
|
31
31
|
# app [global] [command] [global]
|
32
32
|
#
|
33
|
-
# Where the [global] sections are made of options and arguments and
|
33
|
+
# Where the [global] sections are made of options and arguments and
|
34
34
|
# [command] is made of
|
35
35
|
#
|
36
36
|
# [command] [options/args]
|
37
37
|
#
|
38
|
-
# Only one command can be run, if you attempt to use two the other will be
|
38
|
+
# Only one command can be run, if you attempt to use two the other will be
|
39
39
|
# caught as an argument.
|
40
40
|
#
|
41
41
|
# @param argv [Array]
|
@@ -82,8 +82,33 @@ class Clive
|
|
82
82
|
args = []
|
83
83
|
|
84
84
|
until ended?
|
85
|
-
|
85
|
+
# it's a no- option
|
86
|
+
if curr[0..4] == '--no-' && found.has?("--#{curr[5..-1]}") && found.find("--#{curr[5..-1]}").config[:boolean] == true
|
87
|
+
found.find("--#{curr[5..-1]}").run @state, [false], found
|
88
|
+
|
89
|
+
# it's one (or more) short options
|
90
|
+
elsif curr[0..0] == '-' && curr.size > 2 && found.has?("-#{curr[1..1]}")
|
91
|
+
currs = curr[1..-1].split('').map {|i| "-#{i}" }
|
92
|
+
|
93
|
+
currs.each do |c|
|
94
|
+
opt = found.find(c)
|
95
|
+
raise MissingOptionError.new(c) unless opt
|
96
|
+
|
97
|
+
if c == currs.last
|
98
|
+
run_option opt, found
|
99
|
+
else
|
100
|
+
# can't take any arguments as an option is next to it
|
101
|
+
if opt.args.min > 0
|
102
|
+
raise MissingArgumentError.new(opt, [], opt.args)
|
103
|
+
else
|
104
|
+
opt.run @state, [true], found
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
elsif found.has?(curr)
|
86
110
|
run_option found.find(curr), found
|
111
|
+
|
87
112
|
else
|
88
113
|
break unless found.args.possible?(args + [curr])
|
89
114
|
args << curr
|
@@ -100,7 +125,7 @@ class Clive
|
|
100
125
|
end
|
101
126
|
|
102
127
|
# it's a no- option
|
103
|
-
elsif curr[0..4] == '--no-' && @base.find("--#{curr[5..-1]}").config[:boolean] == true
|
128
|
+
elsif curr[0..4] == '--no-' && @base.has?("--#{curr[5..-1]}") && @base.find("--#{curr[5..-1]}").config[:boolean] == true
|
104
129
|
@base.find("--#{curr[5..-1]}").run @state, [false]
|
105
130
|
|
106
131
|
# it's one (or more) short options
|
data/lib/clive/version.rb
CHANGED
data/spec/clive/a_cli_spec.rb
CHANGED
@@ -43,6 +43,8 @@ describe 'A CLI' do
|
|
43
43
|
# implicit arg as "<choice>", also added default
|
44
44
|
opt :T, :type, :in => %w(post page blog), :default => :page, :as => Symbol
|
45
45
|
|
46
|
+
bool :a, :all
|
47
|
+
|
46
48
|
action do |dir|
|
47
49
|
puts "Creating #{get :type} in #{dir}" if dir
|
48
50
|
end
|
@@ -244,4 +246,16 @@ describe 'A CLI' do
|
|
244
246
|
subject.run %w(-vsa 2.45)
|
245
247
|
}.must_raise Clive::Parser::MissingArgumentError
|
246
248
|
end
|
249
|
+
|
250
|
+
it 'should be able to do combined short switches in a command' do
|
251
|
+
r = subject.run s 'new -aT blog'
|
252
|
+
|
253
|
+
r[:new].to_h.must_equal :all => true, :type => :blog, :something => []
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'should be able to do --no switches in a command' do
|
257
|
+
r = subject.run s 'new --no-all'
|
258
|
+
|
259
|
+
r[:new].to_h.must_equal :all => false, :something => []
|
260
|
+
end
|
247
261
|
end
|
data/spec/clive/parser_spec.rb
CHANGED
@@ -16,10 +16,10 @@ Usage: ... [command] [options]
|
|
16
16
|
|
17
17
|
Commands:
|
18
18
|
new
|
19
|
-
help [<command>]
|
19
|
+
help [<command>] \e[90m# \e[0m\e[90mDisplay help\e[0m
|
20
20
|
|
21
21
|
Options:
|
22
|
-
-h, --help
|
22
|
+
-h, --help \e[90m# \e[0m\e[90mDisplay this help message\e[0m
|
23
23
|
EOS
|
24
24
|
end
|
25
25
|
end
|
@@ -34,7 +34,7 @@ Usage: ... new [options]
|
|
34
34
|
|
35
35
|
Options:
|
36
36
|
-f, --force
|
37
|
-
-h, --help
|
37
|
+
-h, --help \e[90m# \e[0m\e[90mDisplay this help message\e[0m
|
38
38
|
EOS
|
39
39
|
end
|
40
40
|
|
@@ -143,33 +143,33 @@ EOS
|
|
143
143
|
r.must_have :auto
|
144
144
|
end
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
describe 'Infinite arguments' do
|
148
148
|
subject {
|
149
149
|
Clive.new { opt :items, :arg => '<item>...' }
|
150
150
|
}
|
151
|
-
|
151
|
+
|
152
152
|
it 'requires at least one argument' do
|
153
153
|
this {
|
154
154
|
subject.run s '--items'
|
155
155
|
}.must_raise Clive::Parser::MissingArgumentError
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
it 'takes infinite arguments' do
|
159
159
|
r = subject.run s '--items a b c d e f g h'
|
160
160
|
r.items.must_equal %w(a b c d e f g h)
|
161
161
|
end
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
describe 'Optional infinite arguments' do
|
165
165
|
subject {
|
166
166
|
Clive.new { opt :items, :arg => '[<item>...]' }
|
167
167
|
}
|
168
|
-
|
168
|
+
|
169
169
|
it 'does not require an argument' do
|
170
170
|
subject.run s '--items'
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
it 'takes infinite arguments' do
|
174
174
|
r = subject.run s '--items a b c d e f g h'
|
175
175
|
r.items.must_equal %w(a b c d e f g h)
|
metadata
CHANGED
@@ -1,51 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Joshua Hawxwell
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: minitest
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '2.6'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '2.6'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: mocha
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0.10'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0.10'
|
46
|
-
description:
|
47
|
-
|
48
|
-
|
41
|
+
description: " Clive provides a DSL for building command line interfaces. It allows
|
42
|
+
\n you to define commands and options, which can also take arguments, \n and
|
43
|
+
then runs the correct stuff!\n"
|
49
44
|
email: m@hawx.me
|
50
45
|
executables: []
|
51
46
|
extensions: []
|
@@ -53,83 +48,83 @@ extra_rdoc_files: []
|
|
53
48
|
files:
|
54
49
|
- README.md
|
55
50
|
- LICENSE
|
56
|
-
- lib/clive/
|
51
|
+
- lib/clive/type/definitions.rb
|
52
|
+
- lib/clive/type/lookup.rb
|
53
|
+
- lib/clive/parser.rb
|
54
|
+
- lib/clive/type.rb
|
55
|
+
- lib/clive/command.rb
|
56
|
+
- lib/clive/struct_hash.rb
|
57
|
+
- lib/clive/option.rb
|
57
58
|
- lib/clive/arguments/parser.rb
|
59
|
+
- lib/clive/argument.rb
|
60
|
+
- lib/clive/output.rb
|
61
|
+
- lib/clive/option/runner.rb
|
62
|
+
- lib/clive/version.rb
|
63
|
+
- lib/clive/formatter/colour.rb
|
64
|
+
- lib/clive/formatter/plain.rb
|
58
65
|
- lib/clive/arguments.rb
|
59
66
|
- lib/clive/base.rb
|
60
|
-
- lib/clive/command.rb
|
61
67
|
- lib/clive/error.rb
|
62
|
-
- lib/clive/formatter/colour.rb
|
63
|
-
- lib/clive/formatter/plain.rb
|
64
68
|
- lib/clive/formatter.rb
|
65
|
-
- lib/clive/option/runner.rb
|
66
|
-
- lib/clive/option.rb
|
67
|
-
- lib/clive/output.rb
|
68
|
-
- lib/clive/parser.rb
|
69
|
-
- lib/clive/struct_hash.rb
|
70
|
-
- lib/clive/type/definitions.rb
|
71
|
-
- lib/clive/type/lookup.rb
|
72
|
-
- lib/clive/type.rb
|
73
|
-
- lib/clive/version.rb
|
74
69
|
- lib/clive.rb
|
75
|
-
- spec/
|
76
|
-
- spec/
|
70
|
+
- spec/helper.rb
|
71
|
+
- spec/clive_spec.rb
|
72
|
+
- spec/extras/focus.rb
|
73
|
+
- spec/extras/expectations.rb
|
74
|
+
- spec/clive/type/definitions_spec.rb
|
75
|
+
- spec/clive/output_spec.rb
|
76
|
+
- spec/clive/type_spec.rb
|
77
77
|
- spec/clive/arguments/parser_spec.rb
|
78
|
+
- spec/clive/argument_spec.rb
|
78
79
|
- spec/clive/arguments_spec.rb
|
79
|
-
- spec/clive/
|
80
|
+
- spec/clive/struct_hash_spec.rb
|
81
|
+
- spec/clive/option/runner_spec.rb
|
80
82
|
- spec/clive/formatter/colour_spec.rb
|
81
83
|
- spec/clive/formatter/plain_spec.rb
|
82
|
-
- spec/clive/
|
84
|
+
- spec/clive/command_spec.rb
|
83
85
|
- spec/clive/option_spec.rb
|
84
|
-
- spec/clive/output_spec.rb
|
85
86
|
- spec/clive/parser_spec.rb
|
86
|
-
- spec/clive/
|
87
|
-
- spec/clive/type/definitions_spec.rb
|
88
|
-
- spec/clive/type_spec.rb
|
89
|
-
- spec/clive_spec.rb
|
90
|
-
- spec/extras/expectations.rb
|
91
|
-
- spec/extras/focus.rb
|
92
|
-
- spec/helper.rb
|
87
|
+
- spec/clive/a_cli_spec.rb
|
93
88
|
homepage: http://github.com/hawx/clive
|
94
89
|
licenses: []
|
90
|
+
metadata: {}
|
95
91
|
post_install_message:
|
96
92
|
rdoc_options: []
|
97
93
|
require_paths:
|
98
94
|
- lib
|
99
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
96
|
requirements:
|
102
|
-
- -
|
97
|
+
- - ">="
|
103
98
|
- !ruby/object:Gem::Version
|
104
99
|
version: '0'
|
105
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
101
|
requirements:
|
108
|
-
- -
|
102
|
+
- - ">="
|
109
103
|
- !ruby/object:Gem::Version
|
110
104
|
version: '0'
|
111
105
|
requirements: []
|
112
106
|
rubyforge_project:
|
113
|
-
rubygems_version:
|
107
|
+
rubygems_version: 2.0.14
|
114
108
|
signing_key:
|
115
|
-
specification_version:
|
109
|
+
specification_version: 4
|
116
110
|
summary: A DSL for building command line interfaces.
|
117
111
|
test_files:
|
118
|
-
- spec/
|
119
|
-
- spec/
|
112
|
+
- spec/helper.rb
|
113
|
+
- spec/clive_spec.rb
|
114
|
+
- spec/extras/focus.rb
|
115
|
+
- spec/extras/expectations.rb
|
116
|
+
- spec/clive/type/definitions_spec.rb
|
117
|
+
- spec/clive/output_spec.rb
|
118
|
+
- spec/clive/type_spec.rb
|
120
119
|
- spec/clive/arguments/parser_spec.rb
|
120
|
+
- spec/clive/argument_spec.rb
|
121
121
|
- spec/clive/arguments_spec.rb
|
122
|
-
- spec/clive/
|
122
|
+
- spec/clive/struct_hash_spec.rb
|
123
|
+
- spec/clive/option/runner_spec.rb
|
123
124
|
- spec/clive/formatter/colour_spec.rb
|
124
125
|
- spec/clive/formatter/plain_spec.rb
|
125
|
-
- spec/clive/
|
126
|
+
- spec/clive/command_spec.rb
|
126
127
|
- spec/clive/option_spec.rb
|
127
|
-
- spec/clive/output_spec.rb
|
128
128
|
- spec/clive/parser_spec.rb
|
129
|
-
- spec/clive/
|
130
|
-
|
131
|
-
- spec/clive/type_spec.rb
|
132
|
-
- spec/clive_spec.rb
|
133
|
-
- spec/extras/expectations.rb
|
134
|
-
- spec/extras/focus.rb
|
135
|
-
- spec/helper.rb
|
129
|
+
- spec/clive/a_cli_spec.rb
|
130
|
+
has_rdoc:
|