mixlib-cli 1.2.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -0
- data/Rakefile +26 -40
- data/lib/mixlib/cli.rb +6 -14
- data/lib/mixlib/cli/version.rb +6 -0
- data/spec/mixlib/cli_spec.rb +30 -2
- metadata +19 -19
- data/.gitignore +0 -6
- data/VERSION.yml +0 -4
- data/features/mixlib_cli.feature +0 -9
- data/features/step_definitions/mixlib_cli_steps.rb +0 -0
- data/features/support/env.rb +0 -9
- data/spec/spec.opts +0 -4
data/README.rdoc
CHANGED
@@ -72,6 +72,11 @@ Available arguments to 'option':
|
|
72
72
|
:exit:: Exit your program with the exit code when this option is specified. Example: 0
|
73
73
|
:proc:: If set, the configuration value will be set to the return value of this proc.
|
74
74
|
|
75
|
+
=== New in 1.2.2
|
76
|
+
|
77
|
+
:required works, and we now support Ruby-style boolean option negation
|
78
|
+
(e.g. '--no-cookie' will set 'cookie' to false if the option is boolean)
|
79
|
+
|
75
80
|
=== New in 1.2.0
|
76
81
|
|
77
82
|
We no longer destructively manipulate ARGV.
|
data/Rakefile
CHANGED
@@ -1,55 +1,41 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "mixlib-cli"
|
8
|
-
gem.summary = "A simple mixin for CLI interfaces, including option parsing"
|
9
|
-
gem.email = "info@opscode.com"
|
10
|
-
gem.homepage = "http://www.opscode.com"
|
11
|
-
gem.authors = ["Opscode, Inc."]
|
12
|
-
end
|
13
|
-
Jeweler::GemcutterTasks.new
|
14
|
-
rescue LoadError
|
15
|
-
puts "Jeweler (or a dependency) not available. Install from gemcutter with: sudo gem install gemcutter jeweler"
|
16
|
-
end
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'rdoc/task'
|
17
5
|
|
18
|
-
|
19
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
20
|
-
spec.libs << 'lib' << 'spec'
|
21
|
-
spec.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
|
22
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
-
end
|
6
|
+
task :default => :spec
|
24
7
|
|
25
|
-
|
26
|
-
|
8
|
+
desc "Run specs"
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
27
10
|
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
-
spec.rcov = true
|
29
11
|
end
|
30
12
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
task :features do
|
36
|
-
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
37
|
-
end
|
13
|
+
gem_spec = eval(File.read("mixlib-cli.gemspec"))
|
14
|
+
|
15
|
+
Rake::GemPackageTask.new(gem_spec) do |pkg|
|
16
|
+
pkg.gem_spec = gem_spec
|
38
17
|
end
|
39
18
|
|
40
|
-
|
19
|
+
desc "install the gem locally"
|
20
|
+
task :install => [:package] do
|
21
|
+
sh %{gem install pkg/#{gem_spec.name}-#{gem_spec.version}}
|
22
|
+
end
|
41
23
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
-
else
|
48
|
-
version = ""
|
24
|
+
desc "create a gemspec file"
|
25
|
+
task :make_spec do
|
26
|
+
File.open("#{gem_spec.name}.gemspec", "w") do |file|
|
27
|
+
file.puts spec.to_ruby
|
49
28
|
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "remove build files"
|
32
|
+
task :clean do
|
33
|
+
sh %Q{ rm -f pkg/*.gem }
|
34
|
+
end
|
50
35
|
|
36
|
+
RDoc::Task.new do |rdoc|
|
51
37
|
rdoc.rdoc_dir = 'rdoc'
|
52
|
-
rdoc.title = "mixlib-cli #{version}"
|
38
|
+
rdoc.title = "mixlib-cli #{gem_spec.version}"
|
53
39
|
rdoc.rdoc_files.include('README*')
|
54
40
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
41
|
end
|
data/lib/mixlib/cli.rb
CHANGED
@@ -138,19 +138,11 @@ module Mixlib
|
|
138
138
|
raise ArgumentError, "You must pass :on, :tail, or :head to :on"
|
139
139
|
end
|
140
140
|
|
141
|
-
parse_block =
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
exit opt_val[:exit] if opt_val[:exit]
|
147
|
-
end
|
148
|
-
when false
|
149
|
-
Proc.new() do |c|
|
150
|
-
config[opt_key] = (opt_val[:proc] && opt_val[:proc].call(c)) || c
|
151
|
-
puts opts if opt_val[:show_options]
|
152
|
-
exit opt_val[:exit] if opt_val[:exit]
|
153
|
-
end
|
141
|
+
parse_block =
|
142
|
+
Proc.new() do |c|
|
143
|
+
config[opt_key] = (opt_val[:proc] && opt_val[:proc].call(c)) || c
|
144
|
+
puts opts if opt_val[:show_options]
|
145
|
+
exit opt_val[:exit] if opt_val[:exit]
|
154
146
|
end
|
155
147
|
|
156
148
|
full_opt = [ opt_method ]
|
@@ -163,7 +155,7 @@ module Mixlib
|
|
163
155
|
|
164
156
|
# Deal with any required values
|
165
157
|
options.each do |opt_key, opt_value|
|
166
|
-
if opt_value[:required]
|
158
|
+
if opt_value[:required] && !config.has_key?(opt_key)
|
167
159
|
reqarg = opt_value[:short] || opt_value[:long]
|
168
160
|
puts "You must supply #{reqarg}!"
|
169
161
|
puts @opt_parser
|
data/spec/mixlib/cli_spec.rb
CHANGED
@@ -156,18 +156,46 @@ describe Mixlib::CLI do
|
|
156
156
|
@cli.config[:i_am_boolean].should == true
|
157
157
|
end
|
158
158
|
|
159
|
+
it "should set the corresponding config value to false when a boolean is prefixed with --no" do
|
160
|
+
TestCLI.option(:i_am_boolean, :long => "--[no-]bool", :boolean => true)
|
161
|
+
@cli = TestCLI.new
|
162
|
+
@cli.parse_options([ '--no-bool' ])
|
163
|
+
@cli.config[:i_am_boolean].should == false
|
164
|
+
end
|
165
|
+
|
159
166
|
it "should exit if a config option has :exit set" do
|
160
167
|
TestCLI.option(:i_am_exit, :short => "-x", :boolean => true, :exit => 0)
|
161
168
|
@cli = TestCLI.new
|
162
169
|
lambda { @cli.parse_options(["-x"]) }.should raise_error(SystemExit)
|
163
170
|
end
|
164
|
-
|
171
|
+
|
165
172
|
it "should exit if a required option is missing" do
|
166
173
|
TestCLI.option(:require_me, :short => "-r", :boolean => true, :required => true)
|
167
174
|
@cli = TestCLI.new
|
168
175
|
lambda { @cli.parse_options([]) }.should raise_error(SystemExit)
|
169
176
|
end
|
170
|
-
|
177
|
+
|
178
|
+
it "should not exit if a required option is specified" do
|
179
|
+
TestCLI.option(:require_me, :short => "-r", :boolean => true, :required => true)
|
180
|
+
@cli = TestCLI.new
|
181
|
+
@cli.parse_options(["-r"])
|
182
|
+
@cli.config[:require_me].should == true
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should not exit if a required boolean option is specified and false" do
|
186
|
+
TestCLI.option(:require_me, :long => "--[no-]req", :boolean => true, :required => true)
|
187
|
+
@cli = TestCLI.new
|
188
|
+
@cli.parse_options(["--no-req"])
|
189
|
+
@cli.config[:require_me].should == false
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should not exit if a required option is specified and empty" do
|
193
|
+
TestCLI.option(:require_me, :short => "-r VALUE", :required => true)
|
194
|
+
@cli = TestCLI.new
|
195
|
+
@cli.parse_options(["-r", ""])
|
196
|
+
@cli.config[:require_me].should == ""
|
197
|
+
end
|
198
|
+
|
171
199
|
it "should preserve all of the commandline arguments, ARGV" do
|
172
200
|
TestCLI.option(:config_file, :short => "-c CONFIG")
|
173
201
|
@cli = TestCLI.new
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixlib-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 1.2.
|
9
|
+
- 2
|
10
|
+
version: 1.2.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Opscode, Inc.
|
@@ -14,63 +15,62 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-09-08 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
21
|
-
description:
|
22
|
+
description: A simple mixin for CLI interfaces, including option parsing
|
22
23
|
email: info@opscode.com
|
23
24
|
executables: []
|
24
25
|
|
25
26
|
extensions: []
|
26
27
|
|
27
28
|
extra_rdoc_files:
|
28
|
-
- LICENSE
|
29
29
|
- README.rdoc
|
30
|
-
files:
|
31
|
-
- .gitignore
|
32
30
|
- LICENSE
|
33
31
|
- NOTICE
|
32
|
+
files:
|
33
|
+
- LICENSE
|
34
34
|
- README.rdoc
|
35
35
|
- Rakefile
|
36
|
-
-
|
37
|
-
-
|
38
|
-
- features/step_definitions/mixlib_cli_steps.rb
|
39
|
-
- features/support/env.rb
|
36
|
+
- NOTICE
|
37
|
+
- lib/mixlib/cli/version.rb
|
40
38
|
- lib/mixlib/cli.rb
|
41
39
|
- spec/mixlib/cli_spec.rb
|
42
|
-
- spec/spec.opts
|
43
40
|
- spec/spec_helper.rb
|
44
41
|
has_rdoc: true
|
45
42
|
homepage: http://www.opscode.com
|
46
43
|
licenses: []
|
47
44
|
|
48
45
|
post_install_message:
|
49
|
-
rdoc_options:
|
50
|
-
|
46
|
+
rdoc_options: []
|
47
|
+
|
51
48
|
require_paths:
|
52
49
|
- lib
|
53
50
|
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
54
52
|
requirements:
|
55
53
|
- - ">="
|
56
54
|
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
57
56
|
segments:
|
58
57
|
- 0
|
59
58
|
version: "0"
|
60
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
61
|
requirements:
|
62
62
|
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
64
65
|
segments:
|
65
66
|
- 0
|
66
67
|
version: "0"
|
67
68
|
requirements: []
|
68
69
|
|
69
70
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.6.2
|
71
72
|
signing_key:
|
72
73
|
specification_version: 3
|
73
74
|
summary: A simple mixin for CLI interfaces, including option parsing
|
74
|
-
test_files:
|
75
|
-
|
76
|
-
- spec/spec_helper.rb
|
75
|
+
test_files: []
|
76
|
+
|
data/.gitignore
DELETED
data/VERSION.yml
DELETED
data/features/mixlib_cli.feature
DELETED
File without changes
|
data/features/support/env.rb
DELETED
data/spec/spec.opts
DELETED