Skip to content

Commit

Permalink
Support multiple files from the CLI command
Browse files Browse the repository at this point in the history
Close #109

This change allows multiple files to be passed into the CLI with one call:

```
$ ./exe/dead_end **/*.rb
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
```
  • Loading branch information
schneems committed Nov 9, 2021
1 parent d8cb3f3 commit f0621a7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
40 changes: 21 additions & 19 deletions lib/dead_end/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 23 additions & 1 deletion spec/unit/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -52,7 +75,6 @@ def called?
argv: [file.to_s],
exit_obj: exit_obj
).call

out = io.string
debug_display(out)

Expand Down

0 comments on commit f0621a7

Please sign in to comment.