From 54c14423f65c25fc7b252445255ff74fbfa2c045 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Tue, 1 Nov 2016 21:21:46 -0400 Subject: [PATCH] Do not require that the filename 'metadata.json' be passed. This tool is built to lint metadata.json, so the argument for the filename should not be mandatory. --- lib/metadata_json_lint.rb | 16 ++++++++++++---- tests/test.sh | 9 +++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/metadata_json_lint.rb b/lib/metadata_json_lint.rb index 9e72dcb..7b6c586 100644 --- a/lib/metadata_json_lint.rb +++ b/lib/metadata_json_lint.rb @@ -15,7 +15,7 @@ def options def run OptionParser.new do |opts| - opts.banner = 'Usage: metadata-json-lint [options] metadata.json' + opts.banner = 'Usage: metadata-json-lint [options] [metadata.json]' opts.on('--[no-]strict-dependencies', 'Fail on open-ended module version dependencies') do |v| options[:strict_dependencies] = v @@ -30,9 +30,17 @@ def run end end.parse! - abort('Error: Must provide a metadata.json file to parse') if ARGV[0].nil? - - MetadataJsonLint.parse(ARGV.first) + mj = if ARGV[0].nil? + if File.readable?('metadata.json') + 'metadata.json' + else + abort('Error: metadata.json is not readable or does not exist.') + end + else + ARGV[0] + end + + MetadataJsonLint.parse(mj) end module_function :run diff --git a/tests/test.sh b/tests/test.sh index bf0af07..9d4fb8d 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -85,4 +85,13 @@ test "proprietary" $SUCCESS # Run without a metadata.json or Rakefile, expect FAILURE test "no_files" $FAILURE +# Test running without specifying file to parse +cd perfect +bundle exec metadata-json-lint +if [ $? -ne 0 ]; then + fail "Failing Test 'running without specifying metadata.json' (bin)" +else + echo "Successful Test 'running without specifying metadata.json' (bin)" +fi + exit $STATUS