diff options
author | Thom May <thom@may.lt> | 2016-03-17 09:48:41 +0000 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-03-17 09:48:41 +0000 |
commit | aca1514f14c4dcc06e612f34b1b6852675962824 (patch) | |
tree | ef1160c145c2449a618805727da7851de9f1269e | |
parent | cbf7707a454da2ed573c5f56b0f1ec46cf9b2982 (diff) | |
parent | d9a328424693885ed6437e2068c7d3296a96699c (diff) | |
download | mixlib-cli-aca1514f14c4dcc06e612f34b1b6852675962824.tar.gz |
Merge pull request #25 from chef/tas50/cleanup
Various updates
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | .rspec | 4 | ||||
-rw-r--r-- | .travis.yml | 24 | ||||
-rw-r--r-- | CHANGELOG.md | 41 | ||||
-rw-r--r-- | NOTICE | 13 | ||||
-rw-r--r-- | README.md | 109 | ||||
-rw-r--r-- | README.rdoc | 93 | ||||
-rw-r--r-- | lib/mixlib/cli.rb | 18 | ||||
-rw-r--r-- | mixlib-cli.gemspec | 16 |
9 files changed, 192 insertions, 129 deletions
@@ -3,4 +3,7 @@ coverage rdoc pkg +.rake_tasks~ +.bundle Gemfile.lock +vendor @@ -1,2 +1,2 @@ --c --f doc +--colour +--format documentation diff --git a/.travis.yml b/.travis.yml index f019556..34f5449 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,21 @@ -rvm: - - 1.8.7 - - 1.9.3 - - 2.0.0 +language: ruby +cache: bundler + +sudo: false -script: bundle exec rake spec +branches: + only: + - master + +before_install: + - bundle --version + - gem --version +rvm: + - 2.0 + - 2.1 + - 2.2 + - 2.3.0 +script: + - bundle exec chefstyle + - bundle exec rake spec diff --git a/CHANGELOG.md b/CHANGELOG.md index db855dd..6ba618b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,39 @@ # mixlib-cli Changelog -## Unreleased +## UNRELEASED -* [**C Chamblin**:](https://github.com/chamblin) - Documented CLI arguments. -* [**Kenichi Kamiya**:](https://github.com/kachick) - Fixed ruby-warning "instance variable @{ivar} not initialized". +- Added option key ':in' to specify that option value should be included in the given list +- Fixed ruby-warning "instance variable @{ivar} not initialized". - [Kenichi Kamiya](https://github.com/kachick) +- Documented CLI arguments. - [C Chamblin](https://github.com/chamblin) +- Added rake, rdoc, and rspec and development dependencies +- Removed the contributions.md document and merged it with the changelog +- Updated code to comply with chefstyle style guidelines +- Fixed a missing comma from an example in the readme +- Ship the Gemfile so that tests can run from the Gem -## Last Release: 1.4.0 (12/05/2013) +## 1.5.0 + +- Added an API to access option parser without parsing options +- Added this changelog and a contributions document +- Documented how to use cli_arguments + +## 1.4.0 + +- Added cli_arguments--remaining arguments after stripping CLI options +- Add Travis and Bundler support + +## 1.3.0 + +- Added the ability to optionally store default values separately +- Added comments documenting the primary interfaces +- Fix mixlib-cli to work with bundler in Ruby 1.9.2 + +## 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) +- The repo now includes a Gemspec file +- Jeweler is no longer a dependency + +## 1.2.0 + +We no longer destructively manipulate ARGV. @@ -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. <legal@opscode.com> + + * Copyright 2009-2016, Chef Software, Inc. <legal@chef.io> 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 <adam@opscode.com> + * Copyright 2008, Adam Jacob <adam@chef.io> * Copyright 2008, Arjuna Christensen <aj@hjksolutions.com> * Copyright 2008, Bryan McLellan <btm@loftninjas.org> * Copyright 2008, Ezra Zygmuntowicz <ezra@engineyard.com> * Copyright 2009, Sean Cribbs <seancribbs@gmail.com> - * Copyright 2009, Christopher Brown <cb@opscode.com> + * Copyright 2009, Christopher Brown <cb@chef.io> * Copyright 2009, Thom May <thom@clearairturbulence.org> 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 --git a/README.md b/README.md new file mode 100644 index 0000000..6a4d8f9 --- /dev/null +++ b/README.md @@ -0,0 +1,109 @@ +# Mixlib::CLI + +[![Build Status Master](https://travis-ci.org/chef/mixlib-cli.svg?branch=master)](https://travis-ci.org/chef/mixlib-cli) [![Gem Version](https://badge.fury.io/rb/mixlib-cli.svg)](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. +```
\ No newline at end of file diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index aba158d..0000000 --- a/README.rdoc +++ /dev/null @@ -1,93 +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, - :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): - - 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). - - # ARGV = [ '-c', 'foo.rb', '-l', 'debug', 'file1', 'file2', 'file3' ] - cli = MyCLI.new - cli.parse_options - cli.cli_arguments # [ 'file1', 'file2', 'file3' ] - -=== 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 --git a/lib/mixlib/cli.rb b/lib/mixlib/cli.rb index b3f108e..887d05f 100644 --- a/lib/mixlib/cli.rb +++ b/lib/mixlib/cli.rb @@ -231,15 +231,15 @@ module Mixlib 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| diff --git a/mixlib-cli.gemspec b/mixlib-cli.gemspec index 049d88c..a1e1b2f 100644 --- a/mixlib-cli.gemspec +++ b/mixlib-cli.gemspec @@ -6,20 +6,22 @@ Gem::Specification.new do |s| s.version = Mixlib::CLI::VERSION s.platform = Gem::Platform::RUBY s.has_rdoc = true - s.extra_rdoc_files = ["README.rdoc", "LICENSE", "NOTICE"] + 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 = "Opscode, Inc." - s.email = "info@opscode.com" - s.homepage = "http://www.opscode.com" + s.author = "Chef Software, Inc." + s.email = "info@chef.io" + 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" + 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.rdoc Gemfile Rakefile NOTICE} + Dir.glob("*.gemspec") + - Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } + 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 |