From bf7dd11678857699b2c7559db999e9d44dbc6370 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Fri, 12 Feb 2016 09:18:08 -0800 Subject: chefstyle fixes --- Rakefile | 18 ++++++++--------- features/support/env.rb | 8 ++++---- lib/mixlib/cli.rb | 9 ++++----- lib/mixlib/cli/version.rb | 1 - mixlib-cli.gemspec | 23 ++++++++++----------- spec/mixlib/cli_spec.rb | 51 +++++++++++++++++++++++------------------------ spec/spec_helper.rb | 7 +++---- 7 files changed, 56 insertions(+), 61 deletions(-) diff --git a/Rakefile b/Rakefile index b6b1f55..7877752 100644 --- a/Rakefile +++ b/Rakefile @@ -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,14 @@ task :default => :spec 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 diff --git a/features/support/env.rb b/features/support/env.rb index e62e6ea..3855024 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,9 +1,9 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib') -require 'mixlib_cli' +$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../../lib") +require "mixlib_cli" -require 'spec/expectations' +require "spec/expectations" World do |world| - + world end diff --git a/lib/mixlib/cli.rb b/lib/mixlib/cli.rb index e24d5b5..b3f108e 100644 --- a/lib/mixlib/cli.rb +++ b/lib/mixlib/cli.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'optparse' +require "optparse" module Mixlib @@ -92,7 +92,7 @@ module Mixlib # # === Returns # @banner:: The current banner - def banner(bstring=nil) + def banner(bstring = nil) if bstring @banner = bstring else @@ -149,7 +149,7 @@ module Mixlib @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 @@ -187,7 +187,7 @@ module Mixlib # # === Returns # argv:: Returns any un-parsed elements. - def parse_options(argv=ARGV) + def parse_options(argv = ARGV) argv = argv.dup opt_parser.parse!(argv) @@ -216,7 +216,6 @@ module Mixlib 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`. diff --git a/lib/mixlib/cli/version.rb b/lib/mixlib/cli/version.rb index 21cac2e..7d74289 100644 --- a/lib/mixlib/cli/version.rb +++ b/lib/mixlib/cli/version.rb @@ -3,4 +3,3 @@ module Mixlib VERSION = "1.5.0" end end - diff --git a/mixlib-cli.gemspec b/mixlib-cli.gemspec index 71e1a24..049d88c 100644 --- a/mixlib-cli.gemspec +++ b/mixlib-cli.gemspec @@ -1,26 +1,25 @@ -$:.unshift(File.dirname(__FILE__) + '/lib') -require 'mixlib/cli/version' +$:.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.rdoc", "LICENSE", 'NOTICE'] + s.extra_rdoc_files = ["README.rdoc", "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" - + # Uncomment this to add a dependency #s.add_dependency "mixlib-log" - s.add_development_dependency 'rake' - s.add_development_dependency 'rspec', '~> 2.14' - s.add_development_dependency 'rdoc' - - 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) } -end + s.add_development_dependency "rake" + s.add_development_dependency "rspec", "~> 2.14" + s.add_development_dependency "rdoc" + 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) } +end diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb index e5a248e..cd07435 100644 --- a/spec/mixlib/cli_spec.rb +++ b/spec/mixlib/cli_spec.rb @@ -27,21 +27,21 @@ describe Mixlib::CLI do 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 @@ -80,7 +80,7 @@ describe Mixlib::CLI do :proc => nil, :show_options => false, :exit => nil, - :in => nil + :in => nil, } } end @@ -135,14 +135,14 @@ describe Mixlib::CLI do 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 TestCLI.option(:number, :short => "-n NUMBER", - :proc => Proc.new { |config| config.to_i + 2 } + :proc => Proc.new { |config| config.to_i + 2 }, ) @cli = TestCLI.new @cli.parse_options([ "-n", "2" ]) @@ -152,14 +152,14 @@ describe Mixlib::CLI do 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 @@ -176,28 +176,28 @@ describe Mixlib::CLI do end it "should exit if option is not included in the list" do - TestCLI.option(:inclusion, :short => "-i val", :in => ['one', 'two']) + TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}) @cli = TestCLI.new - lambda { @cli.parse_options(['-i', 'three']) }.should raise_error(SystemExit) + 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') + TestCLI.option(:inclusion, :short => "-i val", :in => "foo") @cli = TestCLI.new - lambda { @cli.parse_options(['-i', 'three']) }.should raise_error(ArgumentError) + 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 => ['one', 'two']) + TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}) @cli = TestCLI.new - @cli.parse_options(['-i', 'one']) - @cli.config[:inclusion].should == 'one' + @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 => ['one', 'two'], :description => 'desc') + TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :description => "desc") @cli = TestCLI.new - @cli.parse_options(['-i', 'one']) + @cli.parse_options(["-i", "one"]) @cli.options[:inclusion][:description].should == "desc (included in ['one', 'two'])" end @@ -226,17 +226,17 @@ describe Mixlib::CLI do 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 @@ -255,7 +255,7 @@ describe Mixlib::CLI do 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 @@ -264,7 +264,6 @@ describe Mixlib::CLI do end - # option :config_file, # :short => "-c CONFIG", # :long => "--config CONFIG", diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 23f4c2d..5256e76 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ -$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 @@ -13,4 +13,3 @@ RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.warnings = true end - -- cgit v1.2.1