Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions spec/compiler/compiler_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ describe "Compiler" do
end
end
end

it "treats all arguments post-filename as program arguments" do
with_tempfile "args_test" do |path|
`bin/crystal '#{compiler_datapath}/args_test' -Dother_flag -- bar '#{path}'`

File.read(path).should eq(<<-FILE)
["-Dother_flag", "--", "bar"]
{other_flag: false}
FILE
end
end
end
7 changes: 7 additions & 0 deletions spec/compiler/data/args_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Last argument is file path to write
test_path = ARGV.pop
File.open(test_path, "w") do |f|
ARGV.inspect(f)
f.puts
{other_flag: {{flag?(:other_flag)}}}.inspect(f)
end
7 changes: 7 additions & 0 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ class Crystal::Command
filenames << stdin_filename
end

if single_file
opts.before_each do |arg|
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it distinguish flags that have a separate value?

E.g. would it understand --exclude-warnings foo.cr bar.cr?

Maybe worth a test.

opts.stop if !arg.starts_with?('-') && arg.ends_with?(".cr")
opts.stop if File.file?(arg)
end
end

opts.unknown_args do |before, after|
opt_filenames = before
opt_arguments = after
Expand Down