-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add a (slightly) better CLI #10
base: master
Are you sure you want to change the base?
Conversation
@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 } |
There was a problem hiding this comment.
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) } |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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]" |
There was a problem hiding this comment.
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.
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.