Skip to content

Commit

Permalink
Compiler: add command line options to crystal eval. Fixes #3196. Cl…
Browse files Browse the repository at this point in the history
…oses #3224
Ary Borenszweig committed Sep 27, 2016

Verified

This commit was signed with the committer’s verified signature.
wyattjoh Wyatt Johnson
1 parent a84078a commit df63f69
Showing 3 changed files with 30 additions and 21 deletions.
23 changes: 23 additions & 0 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
@@ -422,6 +422,29 @@ class Crystal::Command
end
end

private def setup_simple_compiler_options(compiler, opts)
opts.on("-d", "--debug", "Add symbolic debug info") do
compiler.debug = true
end
opts.on("-D FLAG", "--define FLAG", "Define a compile-time flag") do |flag|
compiler.flags << flag
end
opts.on("--error-trace", "Show full error trace") do
compiler.show_error_trace = true
end
opts.on("--release", "Compile in release mode") do
compiler.release = true
end
opts.on("-s", "--stats", "Enable statistics output") do
compiler.stats = true
end
opts.on("-h", "--help", "Show this message") do
puts opts
exit
end
opts.invalid_option { }
end

private def validate_emit_values(values)
values.each do |value|
unless VALID_EMIT_VALUES.includes?(value)
7 changes: 6 additions & 1 deletion src/compiler/crystal/command/eval.cr
Original file line number Diff line number Diff line change
@@ -2,6 +2,12 @@

class Crystal::Command
private def eval
compiler = Compiler.new
OptionParser.parse(options) do |opts|
opts.banner = "Usage: crystal eval [options] [source]\n\nOptions:"
setup_simple_compiler_options compiler, opts
end

if options.empty?
program_source = STDIN.gets_to_end
program_args = [] of String
@@ -16,7 +22,6 @@ class Crystal::Command
end
end

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

output_filename = Crystal.tempfile "eval"
21 changes: 1 addition & 20 deletions src/compiler/crystal/command/spec.cr
Original file line number Diff line number Diff line change
@@ -13,26 +13,7 @@ class Crystal::Command
compiler = Compiler.new
OptionParser.parse(options) do |opts|
opts.banner = "Usage: crystal spec [options] [files]\n\nOptions:"
opts.on("-d", "--debug", "Add symbolic debug info") do
compiler.debug = true
end
opts.on("-D FLAG", "--define FLAG", "Define a compile-time flag") do |flag|
compiler.flags << flag
end
opts.on("--error-trace", "Show full error trace") do
compiler.show_error_trace = true
end
opts.on("--release", "Compile in release mode") do
compiler.release = true
end
opts.on("-s", "--stats", "Enable statistics output") do
compiler.stats = true
end
opts.on("-h", "--help", "Show this message") do
puts opts
exit
end
opts.invalid_option { }
setup_simple_compiler_options compiler, opts
end

# Assume spec files end with ".cr" and optionally with a colon and a number

0 comments on commit df63f69

Please sign in to comment.