module Bhook class ArgsParser Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme) def initialize(argv) @args = Options.new(nil, nil, false, false, nil, nil) @argv = argv.clone @opt_parser = build_opt_parser end def parse begin @opt_parser.parse(@argv) rescue OptionParser::ParseError => e puts puts "Error! #{e.message}" puts puts @opt_parser exit end if source_or_output_paths_missing? && generate_theme_missing? puts @opt_parser exit end @args end private def source_or_output_paths_missing? !@args.source || !@args.output end def generate_theme_missing? !@args.generate_theme end 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 |source_path| @args.source = source_path end opts.on("-oOUTPUT", "--output=OUTPUT", String, "Path to directory where output files are to be generated") do |out_path| @args.output = out_path end opts.on("-w", "--watch", FalseClass, "Continuously watch the source directory for changes and generate output") do @args.watch = true end opts.on("-v", "--verbose", FalseClass, "Print detailed information about files as they are processed") do @args.verbose = true end opts.on("-tPATH", "--theme=PATH", String, "Path to directory containing theme files to use when generating html") do |path| @args.theme = path end opts.on("--generate-theme=PATH", String, "Generate a baseline theme that you can then modify to your needs") do |path| @args.generate_theme = path end opts.on("-h", "--help", "Prints this help") do puts opts exit end end end end end