diff --git a/CHANGELOG.md b/CHANGELOG.md index ea926a6..454e16f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## HEAD (unreleased) +- Support checking multiple files from the CLI at once (https://github.com/zombocom/dead_end/pull/110) - Update links on readme and code of conduct (https://github.com/zombocom/dead_end/pull/107) ## 3.0.1 diff --git a/lib/dead_end/cli.rb b/lib/dead_end/cli.rb index 6ea3aba..58c9363 100644 --- a/lib/dead_end/cli.rb +++ b/lib/dead_end/cli.rb @@ -40,34 +40,36 @@ def call return if options[:exit] end - file_name = @argv.first - if file_name.nil? + if @argv.empty? @io.puts "No file given" @exit_obj.exit(1) return end - file = Pathname(file_name) - if !file.exist? - @io.puts "file not found: #{file.expand_path} " - @exit_obj.exit(1) - return - end + display_array = [] + while (file_name = @argv.pop) + file = Pathname(file_name) + if !file.exist? + @io.puts "file not found: #{file.expand_path} " + @exit_obj.exit(1) + return + end - @io.puts "Record dir: #{options[:record_dir]}" if options[:record_dir] + @io.puts "Record dir: #{options[:record_dir]}" if options[:record_dir] - display = DeadEnd.call( - io: @io, - source: file.read, - filename: file.expand_path, - terminal: options.fetch(:terminal, DeadEnd::DEFAULT_VALUE), - record_dir: options[:record_dir] - ) + display_array << DeadEnd.call( + io: @io, + source: file.read, + filename: file.expand_path, + terminal: options.fetch(:terminal, DeadEnd::DEFAULT_VALUE), + record_dir: options[:record_dir] + ) + end - if display.document_ok? - @exit_obj.exit(0) - else + if display_array.empty? || display_array.detect { |d| !d.document_ok? } @exit_obj.exit(1) + else + @exit_obj.exit(0) end end diff --git a/spec/unit/cli_spec.rb b/spec/unit/cli_spec.rb index 8925eb4..a25fa15 100644 --- a/spec/unit/cli_spec.rb +++ b/spec/unit/cli_spec.rb @@ -42,6 +42,29 @@ def called? end end + it "works on multiple files" do + Dir.mktmpdir do |dir| + dir = Pathname(dir) + file_one = dir.join("script_one.rb") + file_one.write("puts 'lol'") + + file_two = dir.join("script_two.rb") + file_two.write("puts 'lol'") + + io = StringIO.new + exit_obj = FakeExit.new + Cli.new( + io: io, + argv: [file_one.to_s, file_two.to_s], + exit_obj: exit_obj + ).call + + expect(exit_obj.called?).to be_truthy + expect(exit_obj.value).to eq(0) + expect(io.string.strip).to eq("Syntax OK\nSyntax OK") + end + end + it "parses invalid code" do file = fixtures_dir.join("this_project_extra_def.rb.txt") @@ -52,7 +75,6 @@ def called? argv: [file.to_s], exit_obj: exit_obj ).call - out = io.string debug_display(out)