module Bhook class ArgsParser Options = Struct.new(:source, :output, :watch) def initialize(argv) @args = Options.new(nil, nil, false) @argv = argv.clone @opt_parser = build_opt_parser end def parse! begin @opt_parser.parse!(@argv) rescue OptionParser::InvalidOption => e puts puts "Error! #{e.message}" puts end if !@argv.empty? || (!@args.source || !@args.output) puts @opt_parser exit end @args end private def build_opt_parser OptionParser.new do |opts| opts.banner = "Usage: bhook --source /source/path --output /output/path" opts.on("-sSOURCE", "--source=SOURCE", String, "Path to version controlled directory containing source md files") do |s| @args.source = s end opts.on("-oOUTPUT", "--output=OUTPUT", String, "Path to directory where output files are to be generated") do |o| @args.output = o end opts.on("-w", "--watch", FalseClass, "Continuously watch the source directory for changes and generate output") do |w| @args.watch = true end opts.on("-h", "--help", "Prints this help") do puts opts exit end end end end end