Hello community,
here is the log from the commit of package rubygem-mixlib-cli for
openSUSE:Factory checked in at 2016-05-29 03:11:17
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/rubygem-mixlib-cli (Old)
and /work/SRC/openSUSE:Factory/.rubygem-mixlib-cli.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-mixlib-cli"
Changes:
--------
--- /work/SRC/openSUSE:Factory/rubygem-mixlib-cli/rubygem-mixlib-cli.changes
2014-10-14 07:13:18.000000000 +0200
+++
/work/SRC/openSUSE:Factory/.rubygem-mixlib-cli.new/rubygem-mixlib-cli.changes
2016-05-29 03:12:39.000000000 +0200
@@ -1,0 +2,6 @@
+Fri May 6 04:40:27 UTC 2016 - [email protected]
+
+- updated to version 1.6.0
+ no changelog found
+
+-------------------------------------------------------------------
Old:
----
mixlib-cli-1.5.0.gem
New:
----
mixlib-cli-1.6.0.gem
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ rubygem-mixlib-cli.spec ++++++
--- /var/tmp/diff_new_pack.ZNUwFs/_old 2016-05-29 03:12:41.000000000 +0200
+++ /var/tmp/diff_new_pack.ZNUwFs/_new 2016-05-29 03:12:41.000000000 +0200
@@ -1,7 +1,7 @@
#
# spec file for package rubygem-mixlib-cli
#
-# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -16,8 +16,15 @@
#
+#
+# This file was generated with a gem2rpm.yml and not just plain gem2rpm.
+# All sections marked as MANUAL, license headers, summaries and descriptions
+# can be maintained in that file. Please consult this file before editing any
+# of those fields
+#
+
Name: rubygem-mixlib-cli
-Version: 1.5.0
+Version: 1.6.0
Release: 0
%define mod_name mixlib-cli
%define mod_full_name %{mod_name}-%{version}
@@ -25,7 +32,7 @@
BuildRequires: %{rubygem gem2rpm}
BuildRequires: %{ruby}
BuildRequires: ruby-macros >= 5
-Url: http://www.opscode.com
+Url: https://www.chef.io
Source: http://rubygems.org/gems/%{mod_full_name}.gem
Source1: gem2rpm.yml
Summary: A simple mixin for CLI interfaces, including option parsing
@@ -41,7 +48,7 @@
%install
%gem_install \
- --doc-files="LICENSE README.rdoc" \
+ --doc-files="LICENSE README.md" \
-f
%gem_packages
++++++ mixlib-cli-1.5.0.gem -> mixlib-cli-1.6.0.gem ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Gemfile new/Gemfile
--- old/Gemfile 1970-01-01 01:00:00.000000000 +0100
+++ new/Gemfile 2016-05-05 12:34:03.000000000 +0200
@@ -0,0 +1,3 @@
+source "https://rubygems.org"
+
+gemspec
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/NOTICE new/NOTICE
--- old/NOTICE 1970-01-01 01:00:00.000000000 +0100
+++ new/NOTICE 2016-05-05 12:34:03.000000000 +0200
@@ -1,27 +1,26 @@
Mixin::CLI NOTICE
=================
-Developed at Opscode (http://www.opscode.com).
+Developed at Chef (http://www.chef.io).
- * Copyright 2009, Opscode, Inc. <[email protected]>
+
+ * Copyright 2009-2016, Chef Software, Inc. <[email protected]>
Mixin::CLI incorporates code from Chef. The Chef notice file follows:
Chef NOTICE
===========
-Developed at Opscode (http://www.opscode.com).
+Developed at Chef (http://www.chef.io).
Contributors and Copyright holders:
- * Copyright 2008, Adam Jacob <[email protected]>
+ * Copyright 2008, Adam Jacob <[email protected]>
* Copyright 2008, Arjuna Christensen <[email protected]>
* Copyright 2008, Bryan McLellan <[email protected]>
* Copyright 2008, Ezra Zygmuntowicz <[email protected]>
* Copyright 2009, Sean Cribbs <[email protected]>
- * Copyright 2009, Christopher Brown <[email protected]>
+ * Copyright 2009, Christopher Brown <[email protected]>
* Copyright 2009, Thom May <[email protected]>
Chef incorporates code modified from Open4
(http://www.codeforpeople.com/lib/ruby/open4/), which was written by Ara T.
Howard.
-
-Chef incorporates code modified from Merb (http://www.merbivore.com), which is
Copyright (c) 2008 Engine Yard.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/README.md new/README.md
--- old/README.md 1970-01-01 01:00:00.000000000 +0100
+++ new/README.md 2016-05-05 12:34:03.000000000 +0200
@@ -0,0 +1,109 @@
+# Mixlib::CLI
+
+[](https://travis-ci.org/chef/mixlib-cli)
[](https://badge.fury.io/rb/mixlib-cli)
+
+Mixlib::CLI provides a class-based command line option parsing object, like
the one used in Chef, Ohai and Relish. To use in your project:
+
+```ruby
+require 'rubygems'
+require 'mixlib/cli'
+
+class MyCLI
+ include Mixlib::CLI
+
+ option :config_file,
+ :short => "-c CONFIG",
+ :long => "--config CONFIG",
+ :default => 'config.rb',
+ :description => "The configuration file to use"
+
+ option :log_level,
+ :short => "-l LEVEL",
+ :long => "--log_level LEVEL",
+ :description => "Set the log level (debug, info, warn, error, fatal)",
+ :required => true,
+ :in => ['debug', 'info', 'warn', 'error', 'fatal'],
+ :proc => Proc.new { |l| l.to_sym }
+
+ option :help,
+ :short => "-h",
+ :long => "--help",
+ :description => "Show this message",
+ :on => :tail,
+ :boolean => true,
+ :show_options => true,
+ :exit => 0
+
+end
+
+# ARGV = [ '-c', 'foo.rb', '-l', 'debug' ]
+cli = MyCLI.new
+cli.parse_options
+cli.config[:config_file] # 'foo.rb'
+cli.config[:log_level] # :debug
+```
+
+If you are using this in conjunction with Mixlib::Config, you can do something
like this (building on the above definition):
+
+```ruby
+class MyConfig
+ extend(Mixlib::Config)
+
+ log_level :info
+ config_file "default.rb"
+end
+
+class MyCLI
+ def run(argv=ARGV)
+ parse_options(argv)
+ MyConfig.merge!(config)
+ end
+end
+
+c = MyCLI.new
+# ARGV = [ '-l', 'debug' ]
+c.run
+MyConfig[:log_level] # :debug
+```
+
+Available arguments to 'option':
+
+- `:short`: The short option, just like from optparse. Example: "-l LEVEL"
+- `:long`: The long option, just like from optparse. Example: "--level LEVEL"
+- `:description`: The description for this item, just like from optparse.
+- `:default`: A default value for this option
+- `:required`: Prints a message informing the user of the missing requirement,
and exits. Default is false.
+- `:on`: Set to :tail to appear at the end, or `:head`: to appear at the top.
+- `:boolean:`: If this option takes no arguments, set this to true.
+- `:show_options`: If you want the option list printed when this option is
called, set this to true.
+- `:exit`: Exit your program with the exit code when this option is specified.
Example: 0
+- `:proc`: If set, the configuration value will be set to the return value of
this proc.
+- `:in`: An array containing the list of accepted values
+
+If you need access to the leftover options that aren't captured in the config,
you can get at them through +cli_arguments+ (referring to the above definition
of MyCLI).
+
+```ruby
+# ARGV = [ '-c', 'foo.rb', '-l', 'debug', 'file1', 'file2', 'file3' ]
+cli = MyCLI.new
+cli.parse_options
+cli.cli_arguments # [ 'file1', 'file2', 'file3' ]
+```
+
+## LICENSE:
+
+- Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
+- License:: Apache License, Version 2.0
+
+```text
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+```
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/README.rdoc new/README.rdoc
--- old/README.rdoc 1970-01-01 01:00:00.000000000 +0100
+++ new/README.rdoc 1970-01-01 01:00:00.000000000 +0100
@@ -1,84 +0,0 @@
-== Mixlib::CLI
-
-Mixlib::CLI provides a class-based command line option parsing object, like
the one used in Chef, Ohai and Relish. To use in your project:
-
- require 'rubygems'
- require 'mixlib/cli'
-
- class MyCLI
- include Mixlib::CLI
-
- option :config_file,
- :short => "-c CONFIG",
- :long => "--config CONFIG",
- :default => 'config.rb',
- :description => "The configuration file to use"
-
- option :log_level,
- :short => "-l LEVEL",
- :long => "--log_level LEVEL",
- :description => "Set the log level (debug, info, warn, error, fatal)",
- :required => true,
- :proc => Proc.new { |l| l.to_sym }
-
- option :help,
- :short => "-h",
- :long => "--help",
- :description => "Show this message",
- :on => :tail,
- :boolean => true,
- :show_options => true,
- :exit => 0
-
- end
-
- # ARGV = [ '-c', 'foo.rb', '-l', 'debug' ]
- cli = MyCLI.new
- cli.parse_options
- cli.config[:config_file] # 'foo.rb'
- cli.config[:log_level] # :debug
-
-If you are using this in conjunction with Mixlib::Config, you can do something
like this (building on the above definition):
-
- class MyConfig
- extend(Mixlib::Config)
-
- log_level :info
- config_file "default.rb"
- end
-
- class MyCLI
- def run(argv=ARGV)
- parse_options(argv)
- MyConfig.merge!(config)
- end
- end
-
- c = MyCLI.new
- # ARGV = [ '-l', 'debug' ]
- c.run
- MyConfig[:log_level] # :debug
-
-Available arguments to 'option':
-
-:short:: The short option, just like from optparse. Example: "-l LEVEL"
-:long:: The long option, just like from optparse. Example: "--level LEVEL"
-:description:: The description for this item, just like from optparse.
-:default:: A default value for this option
-:required:: Prints a message informing the user of the missing requirement,
and exits. Default is false.
-:on:: Set to :tail to appear at the end, or :head to appear at the top.
-:boolean:: If this option takes no arguments, set this to true.
-:show_options:: If you want the option list printed when this option is
called, set this to true.
-:exit:: Exit your program with the exit code when this option is specified.
Example: 0
-:proc:: If set, the configuration value will be set to the return value of
this proc.
-
-=== New in 1.2.2
-
-:required works, and we now support Ruby-style boolean option negation
-(e.g. '--no-cookie' will set 'cookie' to false if the option is boolean)
-
-=== New in 1.2.0
-
-We no longer destructively manipulate ARGV.
-
-Have fun!
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Rakefile new/Rakefile
--- old/Rakefile 1970-01-01 01:00:00.000000000 +0100
+++ new/Rakefile 2016-05-05 12:34:03.000000000 +0200
@@ -1,8 +1,8 @@
-require 'bundler'
-require 'rubygems'
-require 'rubygems/package_task'
-require 'rdoc/task'
-require 'rspec/core/rake_task'
+require "bundler"
+require "rubygems"
+require "rubygems/package_task"
+require "rdoc/task"
+require "rspec/core/rake_task"
Bundler::GemHelper.install_tasks
@@ -10,14 +10,24 @@
desc "Run specs"
RSpec::Core::RakeTask.new(:spec) do |spec|
- spec.pattern = 'spec/**/*_spec.rb'
+ spec.pattern = "spec/**/*_spec.rb"
end
gem_spec = eval(File.read("mixlib-cli.gemspec"))
RDoc::Task.new do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
+ rdoc.rdoc_dir = "rdoc"
rdoc.title = "mixlib-cli #{gem_spec.version}"
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_files.include("README*")
+ rdoc.rdoc_files.include("lib/**/*.rb")
+end
+
+begin
+ require "chefstyle"
+ require "rubocop/rake_task"
+ RuboCop::RakeTask.new(:style) do |task|
+ task.options += ["--display-cop-names", "--no-color"]
+ end
+rescue LoadError
+ puts "chefstyle/rubocop is not available. gem install chefstyle to do style
checking."
end
Files old/checksums.yaml.gz and new/checksums.yaml.gz differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/mixlib/cli/version.rb
new/lib/mixlib/cli/version.rb
--- old/lib/mixlib/cli/version.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/lib/mixlib/cli/version.rb 2016-05-05 12:34:03.000000000 +0200
@@ -1,6 +1,5 @@
module Mixlib
module CLI
- VERSION = "1.5.0"
+ VERSION = "1.6.0"
end
end
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/mixlib/cli.rb new/lib/mixlib/cli.rb
--- old/lib/mixlib/cli.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/lib/mixlib/cli.rb 2016-05-05 12:34:03.000000000 +0200
@@ -16,7 +16,7 @@
# limitations under the License.
#
-require 'optparse'
+require "optparse"
module Mixlib
@@ -38,8 +38,46 @@
# #parse_options. After calling this method, the attribute #config will
# contain a hash of `:option_name => value` pairs.
module CLI
- module ClassMethods
+ module InheritMethods
+ def inherited(receiver)
+ receiver.options = deep_dup(self.options)
+ receiver.extend(Mixlib::CLI::InheritMethods)
+ end
+
+ # object:: Instance to clone
+ # This method will return a "deep clone" of the provided
+ # `object`. If the provided `object` is an enumerable type the
+ # contents will be iterated and cloned as well.
+ def deep_dup(object)
+ cloned_object = object.respond_to?(:dup) ? object.dup : object
+ if cloned_object.kind_of?(Enumerable)
+ if cloned_object.kind_of?(Hash)
+ new_hash = cloned_object.class.new
+ cloned_object.each do |key, value|
+ cloned_key = deep_dup(key)
+ cloned_value = deep_dup(value)
+ new_hash[cloned_key] = cloned_value
+ end
+ cloned_object.replace(new_hash)
+ else
+ cloned_object.map! do |shallow_instance|
+ deep_dup(shallow_instance)
+ end
+ end
+ end
+ cloned_object
+ rescue TypeError
+ # Symbol will happily provide a `#dup` method even though
+ # attempts to clone it will result in an exception (atoms!).
+ # So if we run into an issue of TypeErrors, just return the
+ # original object as we gave our "best effort"
+ object
+ end
+
+ end
+
+ module ClassMethods
# When this setting is set to +true+, default values supplied to the
# mixlib-cli DSL will be stored in a separate Hash
def use_separate_default_options(true_or_false)
@@ -47,7 +85,7 @@
end
def use_separate_defaults?
- @separate_default_options || false
+ @separate_default_options ||= false
end
# Add a command line option.
@@ -92,7 +130,7 @@
#
# === Returns
# @banner<String>:: The current banner
- def banner(bstring=nil)
+ def banner(bstring = nil)
if bstring
@banner = bstring
else
@@ -149,7 +187,7 @@
@opt_parser = nil
# Set the banner
- @banner = self.class.banner
+ @banner = self.class.banner
# Dupe the class options for this instance
klass_options = self.class.options
@@ -170,6 +208,7 @@
config_opts[:proc] ||= nil
config_opts[:show_options] ||= false
config_opts[:exit] ||= nil
+ config_opts[:in] ||= nil
if config_opts.has_key?(:default)
defaults_container[config_key] = config_opts[:default]
@@ -186,7 +225,7 @@
#
# === Returns
# argv<Array>:: Returns any un-parsed elements.
- def parse_options(argv=ARGV)
+ def parse_options(argv = ARGV)
argv = argv.dup
opt_parser.parse!(argv)
@@ -198,13 +237,23 @@
puts @opt_parser
exit 2
end
+ if opt_value[:in]
+ unless opt_value[:in].kind_of?(Array)
+ raise(ArgumentError, "Options config key :in must receive an
Array")
+ end
+ if !opt_value[:in].include?(config[opt_key])
+ reqarg = opt_value[:short] || opt_value[:long]
+ puts "#{reqarg}: #{config[opt_key]} is not included in the list
['#{opt_value[:in].join("', '")}'] "
+ puts @opt_parser
+ exit 2
+ end
+ end
end
@cli_arguments = argv
argv
end
-
# The option parser generated from the mixlib-cli DSL. +opt_parser+ can be
# used to print a help message including the banner and any CLI options via
# `puts opt_parser`.
@@ -220,15 +269,15 @@
opt_args = build_option_arguments(opt_val)
opt_method = case opt_val[:on]
- when :on
- :on
- when :tail
- :on_tail
- when :head
- :on_head
- else
- raise ArgumentError, "You must pass :on, :tail, or :head to :on"
- end
+ when :on
+ :on
+ when :tail
+ :on_tail
+ when :head
+ :on_head
+ else
+ raise ArgumentError, "You must pass :on, :tail, or
:head to :on"
+ end
parse_block =
Proc.new() do |c|
@@ -250,10 +299,10 @@
arguments << opt_setting[:short] if opt_setting.has_key?(:short)
arguments << opt_setting[:long] if opt_setting.has_key?(:long)
-
if opt_setting.has_key?(:description)
description = opt_setting[:description]
description << " (required)" if opt_setting[:required]
+ description << " (included in ['#{opt_setting[:in].join("', '")}'])"
if opt_setting[:in]
arguments << description
end
@@ -262,6 +311,7 @@
def self.included(receiver)
receiver.extend(Mixlib::CLI::ClassMethods)
+ receiver.extend(Mixlib::CLI::InheritMethods)
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/metadata new/metadata
--- old/metadata 1970-01-01 01:00:00.000000000 +0100
+++ new/metadata 2016-05-05 12:34:03.000000000 +0200
@@ -1,76 +1,93 @@
--- !ruby/object:Gem::Specification
name: mixlib-cli
version: !ruby/object:Gem::Version
- version: 1.5.0
+ version: 1.6.0
platform: ruby
authors:
-- Opscode, Inc.
+- Chef Software, Inc.
autorequire:
bindir: bin
cert_chain: []
-date: 2014-04-25 00:00:00.000000000 Z
+date: 2016-05-05 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: rake
requirement: !ruby/object:Gem::Requirement
requirements:
- - - '>='
+ - - "<"
- !ruby/object:Gem::Version
- version: '0'
+ version: '11.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - - '>='
+ - - "<"
- !ruby/object:Gem::Version
- version: '0'
+ version: '11.0'
- !ruby/object:Gem::Dependency
name: rspec
requirement: !ruby/object:Gem::Requirement
requirements:
- - - '>='
+ - - "~>"
- !ruby/object:Gem::Version
- version: '0'
+ version: '2.14'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - - '>='
+ - - "~>"
- !ruby/object:Gem::Version
- version: '0'
+ version: '2.14'
- !ruby/object:Gem::Dependency
name: rdoc
requirement: !ruby/object:Gem::Requirement
requirements:
- - - '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - - '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
+- !ruby/object:Gem::Dependency
+ name: chefstyle
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '0.3'
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '0.3'
description: A simple mixin for CLI interfaces, including option parsing
-email: [email protected]
+email: [email protected]
executables: []
extensions: []
extra_rdoc_files:
-- README.rdoc
+- README.md
- LICENSE
- NOTICE
files:
+- Gemfile
- LICENSE
-- README.rdoc
-- Rakefile
- NOTICE
-- lib/mixlib/cli/version.rb
+- README.md
+- Rakefile
- lib/mixlib/cli.rb
+- lib/mixlib/cli/version.rb
+- mixlib-cli.gemspec
- spec/mixlib/cli_spec.rb
- spec/spec_helper.rb
-homepage: http://www.opscode.com
-licenses: []
+homepage: https://www.chef.io
+licenses:
+- Apache-2.0
metadata: {}
post_install_message:
rdoc_options: []
@@ -78,19 +95,18 @@
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - - '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - - '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project:
-rubygems_version: 2.0.3
+rubygems_version: 2.4.5.1
signing_key:
specification_version: 4
summary: A simple mixin for CLI interfaces, including option parsing
test_files: []
-has_rdoc: true
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/mixlib-cli.gemspec new/mixlib-cli.gemspec
--- old/mixlib-cli.gemspec 1970-01-01 01:00:00.000000000 +0100
+++ new/mixlib-cli.gemspec 2016-05-05 12:34:03.000000000 +0200
@@ -0,0 +1,27 @@
+$:.unshift(File.dirname(__FILE__) + "/lib")
+require "mixlib/cli/version"
+
+Gem::Specification.new do |s|
+ s.name = "mixlib-cli"
+ s.version = Mixlib::CLI::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README.md", "LICENSE", "NOTICE"]
+ s.summary = "A simple mixin for CLI interfaces, including option parsing"
+ s.description = s.summary
+ s.author = "Chef Software, Inc."
+ s.email = "[email protected]"
+ s.homepage = "https://www.chef.io"
+ s.license = "Apache-2.0"
+
+ # Uncomment this to add a dependency
+ #s.add_dependency "mixlib-log"
+ s.add_development_dependency "rake", "< 11.0"
+ s.add_development_dependency "rspec", "~> 2.14"
+ s.add_development_dependency "rdoc"
+ s.add_development_dependency "chefstyle", "~> 0.3"
+
+ s.require_path = "lib"
+ s.files = %w{LICENSE README.md Gemfile Rakefile NOTICE} +
Dir.glob("*.gemspec") +
+ Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject { |f|
File.directory?(f) }
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/mixlib/cli_spec.rb new/spec/mixlib/cli_spec.rb
--- old/spec/mixlib/cli_spec.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/mixlib/cli_spec.rb 2016-05-05 12:34:03.000000000 +0200
@@ -27,21 +27,21 @@
describe "class method" do
describe "option" do
it "should allow you to set a config option with a hash" do
- TestCLI.option(:config_file, :short => '-c CONFIG').should == { :short
=> '-c CONFIG' }
+ TestCLI.option(:config_file, :short => "-c CONFIG").should == { :short
=> "-c CONFIG" }
end
end
describe "options" do
it "should return the current options hash" do
- TestCLI.option(:config_file, :short => '-c CONFIG')
- TestCLI.options.should == { :config_file => { :short => '-c CONFIG' } }
+ TestCLI.option(:config_file, :short => "-c CONFIG")
+ TestCLI.options.should == { :config_file => { :short => "-c CONFIG" } }
end
end
describe "options=" do
it "should allow you to set the full options with a single hash" do
- TestCLI.options = { :config_file => { :short => '-c CONFIG' } }
- TestCLI.options.should == { :config_file => { :short => '-c CONFIG' } }
+ TestCLI.options = { :config_file => { :short => "-c CONFIG" } }
+ TestCLI.options.should == { :config_file => { :short => "-c CONFIG" } }
end
end
@@ -79,8 +79,9 @@
:required => false,
:proc => nil,
:show_options => false,
- :exit => nil
- }
+ :exit => nil,
+ :in => nil,
+ },
}
end
@@ -134,8 +135,8 @@
it "should set the corresponding config value for non-boolean arguments"
do
TestCLI.option(:config_file, :short => "-c CONFIG")
@cli = TestCLI.new
- @cli.parse_options([ '-c', 'foo.rb' ])
- @cli.config[:config_file].should == 'foo.rb'
+ @cli.parse_options([ "-c", "foo.rb" ])
+ @cli.config[:config_file].should == "foo.rb"
end
it "should set the corresponding config value according to a supplied
proc" do
@@ -151,14 +152,14 @@
it "should set the corresponding config value to true for boolean
arguments" do
TestCLI.option(:i_am_boolean, :short => "-i", :boolean => true)
@cli = TestCLI.new
- @cli.parse_options([ '-i' ])
+ @cli.parse_options([ "-i" ])
@cli.config[:i_am_boolean].should == true
end
it "should set the corresponding config value to false when a boolean is
prefixed with --no" do
TestCLI.option(:i_am_boolean, :long => "--[no-]bool", :boolean => true)
@cli = TestCLI.new
- @cli.parse_options([ '--no-bool' ])
+ @cli.parse_options([ "--no-bool" ])
@cli.config[:i_am_boolean].should == false
end
@@ -174,6 +175,32 @@
lambda { @cli.parse_options([]) }.should raise_error(SystemExit)
end
+ it "should exit if option is not included in the list" do
+ TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two})
+ @cli = TestCLI.new
+ lambda { @cli.parse_options(["-i", "three"]) }.should
raise_error(SystemExit)
+ end
+
+ it "should raise ArgumentError if options key :in is not an array" do
+ TestCLI.option(:inclusion, :short => "-i val", :in => "foo")
+ @cli = TestCLI.new
+ lambda { @cli.parse_options(["-i", "three"]) }.should
raise_error(ArgumentError)
+ end
+
+ it "should not exit if option is included in the list" do
+ TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two})
+ @cli = TestCLI.new
+ @cli.parse_options(["-i", "one"])
+ @cli.config[:inclusion].should == "one"
+ end
+
+ it "should change description if :in key is specified" do
+ TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two},
:description => "desc")
+ @cli = TestCLI.new
+ @cli.parse_options(["-i", "one"])
+ @cli.options[:inclusion][:description].should == "desc (included in
['one', 'two'])"
+ end
+
it "should not exit if a required option is specified" do
TestCLI.option(:require_me, :short => "-r", :boolean => true,
:required => true)
@cli = TestCLI.new
@@ -199,17 +226,17 @@
TestCLI.option(:config_file, :short => "-c CONFIG")
@cli = TestCLI.new
argv_old = ARGV.dup
- ARGV.replace ['-c','foo.rb']
+ ARGV.replace ["-c", "foo.rb"]
@cli.parse_options()
- ARGV.should == ['-c','foo.rb']
+ ARGV.should == ["-c", "foo.rb"]
ARGV.replace argv_old
end
it "should preserve and return any un-parsed elements" do
TestCLI.option(:party, :short => "-p LOCATION")
@cli = TestCLI.new
- @cli.parse_options([ 'easy', '-p', 'opscode', 'hard' ]).should ==
['easy', 'hard']
- @cli.cli_arguments.should == ['easy', 'hard']
+ @cli.parse_options([ "easy", "-p", "opscode", "hard" ]).should ==
%w{easy hard}
+ @cli.cli_arguments.should == %w{easy hard}
end
end
end
@@ -228,15 +255,62 @@
end
it "sets parsed values on the `config` hash" do
- @cli.parse_options(%w[-D not-default])
+ @cli.parse_options(%w{-D not-default})
@cli.default_config[:defaulter].should == "this is the default"
@cli.config[:defaulter].should == "not-default"
end
end
-end
+ context "when subclassed" do
+ before do
+ TestCLI.options = { :arg1 => { :boolean => true } }
+ end
+
+ it "should retain previously defined options from parent" do
+ class T1 < TestCLI
+ option :arg2, :boolean => true
+ end
+ T1.options[:arg1].should be_a(Hash)
+ T1.options[:arg2].should be_a(Hash)
+ TestCLI.options[:arg2].should be_nil
+ end
+
+ it "should not be able to modify parent classes options" do
+ class T2 < TestCLI
+ option :arg2, :boolean => true
+ end
+ T2.options[:arg1][:boolean] = false
+ T2.options[:arg1][:boolean].should be_false
+ TestCLI.options[:arg1][:boolean].should be_true
+ end
+
+ it "should pass its options onto child" do
+ class T3 < TestCLI
+ option :arg2, :boolean => true
+ end
+ class T4 < T3
+ option :arg3, :boolean => true
+ end
+ 3.times do |i|
+ T4.options["arg#{i + 1}".to_sym].should be_a(Hash)
+ end
+ end
+ it "should also work with an option that's an array" do
+ class T5 < TestCLI
+ option :arg2, :default => []
+ end
+
+ class T6 < T5
+ end
+
+ T6.options[:arg2].should be_a(Hash)
+ end
+
+ end
+
+end
# option :config_file,
# :short => "-c CONFIG",
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/spec_helper.rb new/spec/spec_helper.rb
--- old/spec/spec_helper.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/spec_helper.rb 2016-05-05 12:34:03.000000000 +0200
@@ -1,9 +1,15 @@
-$TESTING=true
-$:.push File.join(File.dirname(__FILE__), '..', 'lib')
+$TESTING = true
+$:.push File.join(File.dirname(__FILE__), "..", "lib")
-require 'mixlib/cli'
+require "mixlib/cli"
class TestCLI
include Mixlib::CLI
end
+RSpec.configure do |config|
+ config.filter_run :focus => true
+ config.run_all_when_everything_filtered = true
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.warnings = true
+end