Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of double dashes -- in crystal eval command #15477

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 10 additions & 11 deletions src/compiler/crystal/command/eval.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
class Crystal::Command
private def eval
compiler = new_compiler
opt_program_source = nil
program_args = [] of String

parse_with_crystal_opts do |opts|
opts.banner = "Usage: crystal eval [options] [source]\n\nOptions:"
setup_simple_compiler_options compiler, opts

opts.unknown_args do |before_dash, after_dash|
opt_program_source = before_dash.join " "
program_args = after_dash
end
end

if options.empty?
program_source = opt_program_source
if program_source.nil?
program_source = STDIN.gets_to_end
program_args = [] of String
else
double_dash_index = options.index("--")
if double_dash_index
program_source = options[0...double_dash_index].join " "
program_args = options[double_dash_index + 1..-1]
else
program_source = options.join " "
program_args = [] of String
end
end

sources = [Compiler::Source.new("eval", program_source)]
Expand Down