From 75a104904022d4b059a2f0cdc9bb18138d0a8d9a Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 1 May 2021 08:16:09 -0400 Subject: [PATCH] Parse command-line options --- lib/imbecile/cli.rb | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/imbecile/cli.rb b/lib/imbecile/cli.rb index 752eaf4..444f9f1 100644 --- a/lib/imbecile/cli.rb +++ b/lib/imbecile/cli.rb @@ -1,10 +1,41 @@ module Imbecile module CLI + USAGE = < +Options: + --version Show program version and exit + -h, --help Show this usage and exit +EOF + class << self def run(args) - p args + input_file = nil + args.each do |arg| + case arg + when "--version" + puts "imbecile v#{VERSION}" + return 0 + when "-h", "--help" + puts USAGE + return 0 + when /^-/ + $stderr.puts "Error: unknown option #{arg}" + return 1 + else + if input_file + $stderr.puts "Error: only one input file supported" + return 1 + else + input_file = arg + end + end + end + if input_file.nil? + $stderr.puts "Error: must specify input file" + return 1 + end end end