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

Add a (slightly) better CLI #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

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.

None yet

3 participants