Skip to content

Conversation

samis
Copy link

@samis samis commented Dec 5, 2015

This adds a minimal, but still working CLI allowing to specify both the input and the output files on the command line. While it's very basic and does not support reading from stdin or outputting to stdout, it does work.

@asterite
Copy link
Member

@samis Thanks! Could you squash the commits?

output_file = ""
OptionParser.parse! do |parser|
parser.banner = "Usage: crystal_lib [arguments]"
parser.on("-o FILE", "--output=FILE", "The file to output the generated code to.") { |filename| output_file = filename }

Choose a reason for hiding this comment

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

Clarify the default if it's not specified (for example: "defaults to output.cr"). Actually, it'd be nice if the default took the same name as the input file, except with the cr extension.

OptionParser.parse! do |parser|
parser.banner = "Usage: crystal_lib [arguments]"
parser.on("-o FILE", "--output=FILE", "The file to output the generated code to.") { |filename| output_file = filename }
parser.on("-h", "--help", "Show this help") { puts parser; Process.exit(0) }

Choose a reason for hiding this comment

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

We should provide an option to print to the console, as it works currently.

output_file = "output.cr"
end

node = Crystal::Parser.parse(ARGF.gets_to_end)

Choose a reason for hiding this comment

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

This breaks when the user doesn't provide an input file. It should show usage instead.

require "option_parser"
output_file = ""
OptionParser.parse! do |parser|
parser.banner = "Usage: crystal_lib [arguments]"

Choose a reason for hiding this comment

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

Some sort of clarification that the last argument should be the input file is missing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants