From 0137d42fce9bebde075740ea97efa2287dc4693b Mon Sep 17 00:00:00 2001 From: Jacob Maine Date: Fri, 4 Apr 2014 23:56:57 +0300 Subject: [PATCH] Better error message when calling 'license_finder approve' with no args Show a similar error message when calling 'license_finder whitelist add' --- lib/license_finder/cli.rb | 21 ++++++++++----------- spec/lib/license_finder/cli_spec.rb | 4 +--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/license_finder/cli.rb b/lib/license_finder/cli.rb index abf427806..1527ef82e 100644 --- a/lib/license_finder/cli.rb +++ b/lib/license_finder/cli.rb @@ -90,7 +90,8 @@ def list end desc "add LICENSE...", "Add one or more licenses to the whitelist" - def add(*licenses) + def add(license, *other_licenses) + licenses = other_licenses.unshift license modifying { licenses.each do |license| LicenseFinder.config.whitelist.push(license) @@ -100,7 +101,8 @@ def add(*licenses) end desc "remove LICENSE...", "Remove one or more licenses from the whitelist" - def remove(*licenses) + def remove(license, *other_licenses) + licenses = other_licenses.unshift license modifying { licenses.each do |license| LicenseFinder.config.whitelist.delete(license) @@ -165,16 +167,13 @@ def rescan method_option :approver, desc: "The person granting the approval" method_option :message, desc: "The reason for the approval" desc "approve DEPENDENCY_NAME... [--approver APPROVER_NAME] [--message APPROVAL_MESSAGE]", "Approve one or more dependencies by name, optionally storing who approved the dependency and why" - def approve(*names) - if(names.count < 1) - say "Warning: Must specify dependencies to approve.", :red - else - die_on_error { - names.each { |name| DependencyManager.approve!(name, options[:approver], options[:message]) } - } + def approve(name, *other_names) + names = other_names.unshift name + die_on_error { + names.each { |name| DependencyManager.approve!(name, options[:approver], options[:message]) } + } - say "The #{names.join(", ")} dependency has been approved!", :green - end + say "The #{names.join(", ")} dependency has been approved!", :green end desc "license LICENSE DEPENDENCY_NAME", "Update a dependency's license" diff --git a/spec/lib/license_finder/cli_spec.rb b/spec/lib/license_finder/cli_spec.rb index ff7f4bc78..9ea2e78f4 100644 --- a/spec/lib/license_finder/cli_spec.rb +++ b/spec/lib/license_finder/cli_spec.rb @@ -211,9 +211,7 @@ module CLI DependencyManager.should_not_receive(:approve!) silence_stdout do - subject.should_receive(:say).with(/Warning/, :red) - subject.should_not_receive(:say).with(/dependency has been approved/, anything) - subject.approve + expect { subject.approve }.to raise_error(ArgumentError) end end