lib/bhook/args_parser.rb in bhook-0.1.0 vs lib/bhook/args_parser.rb in bhook-0.1.1

- old
+ new

@@ -1,49 +1,72 @@ module Bhook class ArgsParser - Options = Struct.new(:source, :output, :watch) + Options = Struct.new(:source, :output, :watch, :typechecking, :theme, :generate_theme) def initialize(argv) - @args = Options.new(nil, nil, false) + @args = Options.new(nil, nil, false, false, nil, nil) @argv = argv.clone @opt_parser = build_opt_parser end - def parse! + def parse begin - @opt_parser.parse!(@argv) - rescue OptionParser::InvalidOption => e + @opt_parser.parse(@argv) + rescue OptionParser::ParseError => e puts puts "Error! #{e.message}" puts + puts @opt_parser + exit end - - if !@argv.empty? || (!@args.source || !@args.output) + + 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 |s| - @args.source = s + 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 |o| - @args.output = o + 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 |w| + "Continuously watch the source directory for changes and generate output") do @args.watch = 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