Skip to content

Commit

Permalink
Fix handling of double dashes -- in crystal eval command
Browse files Browse the repository at this point in the history
  • Loading branch information
kojix2 committed Feb 14, 2025
1 parent 1cf95a8 commit a5c4141
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/compiler/crystal/command/eval.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
class Crystal::Command
private def eval
compiler = new_compiler
program_source = ""
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|
program_source = before_dash.join " "
program_args = after_dash
end
end

if options.empty?
if program_source.empty?
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

0 comments on commit a5c4141

Please sign in to comment.