mixlib-cli 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mixlib/cli.rb +24 -21
- data/lib/mixlib/cli/version.rb +1 -1
- data/spec/mixlib/cli_spec.rb +5 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9f4e332532d344f5c62289e8d814c40b7dc1483
|
4
|
+
data.tar.gz: 8e1da896405b03061d5e3038e926173251adcb61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9530b5336675f3086ddc608eb467e96de001533f769d6f237ac1560668befce1bf4323486160faa2bc36dfdac6b9b28ca182bc51ee5d0aa944bc65984b5ef25b
|
7
|
+
data.tar.gz: 790307a0522b70171925d00cf47b7fdad02409505f18558fd5021e7edba38a583603fd0797620d0ff9837fcfc6b44405ba80bfcc769165594de74dcaa9e35bd9
|
data/lib/mixlib/cli.rb
CHANGED
@@ -135,12 +135,6 @@ module Mixlib
|
|
135
135
|
# `puts opt_parser`, this string will be used as the first line.
|
136
136
|
attr_accessor :banner
|
137
137
|
|
138
|
-
# The option parser generated from the mixlib-cli DSL. Set to nil on
|
139
|
-
# initialize; when #parse_options is called +opt_parser+ is set to an
|
140
|
-
# instance of OptionParser. +opt_parser+ can be used to print a help
|
141
|
-
# message including the banner and any CLI options via `puts opt_parser`.
|
142
|
-
attr_accessor :opt_parser
|
143
|
-
|
144
138
|
# Create a new Mixlib::CLI class. If you override this, make sure you call super!
|
145
139
|
#
|
146
140
|
# === Parameters
|
@@ -194,7 +188,30 @@ module Mixlib
|
|
194
188
|
# argv<Array>:: Returns any un-parsed elements.
|
195
189
|
def parse_options(argv=ARGV)
|
196
190
|
argv = argv.dup
|
197
|
-
|
191
|
+
opt_parser.parse!(argv)
|
192
|
+
|
193
|
+
# Deal with any required values
|
194
|
+
options.each do |opt_key, opt_value|
|
195
|
+
if opt_value[:required] && !config.has_key?(opt_key)
|
196
|
+
reqarg = opt_value[:short] || opt_value[:long]
|
197
|
+
puts "You must supply #{reqarg}!"
|
198
|
+
puts @opt_parser
|
199
|
+
exit 2
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
@cli_arguments = argv
|
204
|
+
argv
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
# The option parser generated from the mixlib-cli DSL. +opt_parser+ can be
|
209
|
+
# used to print a help message including the banner and any CLI options via
|
210
|
+
# `puts opt_parser`.
|
211
|
+
# === Returns
|
212
|
+
# opt_parser<OptionParser>:: The option parser object.
|
213
|
+
def opt_parser
|
214
|
+
@opt_parser ||= OptionParser.new do |opts|
|
198
215
|
# Set the banner
|
199
216
|
opts.banner = banner
|
200
217
|
|
@@ -226,20 +243,6 @@ module Mixlib
|
|
226
243
|
opts.send(*full_opt)
|
227
244
|
end
|
228
245
|
end
|
229
|
-
@opt_parser.parse!(argv)
|
230
|
-
|
231
|
-
# Deal with any required values
|
232
|
-
options.each do |opt_key, opt_value|
|
233
|
-
if opt_value[:required] && !config.has_key?(opt_key)
|
234
|
-
reqarg = opt_value[:short] || opt_value[:long]
|
235
|
-
puts "You must supply #{reqarg}!"
|
236
|
-
puts @opt_parser
|
237
|
-
exit 2
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
@cli_arguments = argv
|
242
|
-
argv
|
243
246
|
end
|
244
247
|
|
245
248
|
def build_option_arguments(opt_setting)
|
data/lib/mixlib/cli/version.rb
CHANGED
data/spec/mixlib/cli_spec.rb
CHANGED
@@ -91,16 +91,15 @@ describe Mixlib::CLI do
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
describe "
|
94
|
+
describe "opt_parser" do
|
95
|
+
|
95
96
|
it "should set the banner in opt_parse" do
|
96
|
-
@cli.parse_options([])
|
97
97
|
@cli.opt_parser.banner.should == @cli.banner
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should present the arguments in the banner" do
|
101
101
|
TestCLI.option(:config_file, :short => "-l LOG")
|
102
102
|
@cli = TestCLI.new
|
103
|
-
@cli.parse_options([])
|
104
103
|
@cli.opt_parser.to_s.should =~ /-l LOG/
|
105
104
|
end
|
106
105
|
|
@@ -108,7 +107,6 @@ describe Mixlib::CLI do
|
|
108
107
|
TestCLI.option(:config_file, :short => "-l LOG")
|
109
108
|
TestCLI.option(:help, :short => "-h", :boolean => true, :on => :tail)
|
110
109
|
@cli = TestCLI.new
|
111
|
-
@cli.parse_options([])
|
112
110
|
@cli.opt_parser.to_s.split("\n").last.should =~ /-h/
|
113
111
|
end
|
114
112
|
|
@@ -116,7 +114,6 @@ describe Mixlib::CLI do
|
|
116
114
|
TestCLI.option(:config_file, :short => "-l LOG")
|
117
115
|
TestCLI.option(:help, :short => "-h", :boolean => true, :on => :head)
|
118
116
|
@cli = TestCLI.new
|
119
|
-
@cli.parse_options([])
|
120
117
|
@cli.opt_parser.to_s.split("\n")[1].should =~ /-h/
|
121
118
|
end
|
122
119
|
|
@@ -125,13 +122,15 @@ describe Mixlib::CLI do
|
|
125
122
|
TestCLI.option(:beta, :short => "-b BETA")
|
126
123
|
TestCLI.option(:zeta, :short => "-z ZETA")
|
127
124
|
@cli = TestCLI.new
|
128
|
-
@cli.parse_options([])
|
129
125
|
output_lines = @cli.opt_parser.to_s.split("\n")
|
130
126
|
output_lines[1].should =~ /-a ALPHA/
|
131
127
|
output_lines[2].should =~ /-b BETA/
|
132
128
|
output_lines[3].should =~ /-z ZETA/
|
133
129
|
end
|
134
130
|
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "parse_options" do
|
135
134
|
it "should set the corresponding config value for non-boolean arguments" do
|
136
135
|
TestCLI.option(:config_file, :short => "-c CONFIG")
|
137
136
|
@cli = TestCLI.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixlib-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Opscode, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|