class Thicket::OptionParser

Attributes

options[R]

Public Class Methods

new() click to toggle source
# File lib/thicket/option_parser.rb, line 11
def initialize
  @options = {}
  parse ARGV
end

Private Instance Methods

parse(options) click to toggle source
# File lib/thicket/option_parser.rb, line 18
def parse(options)
  args = Options.new("world")

  opt_parser = ::OptionParser.new do |opts|
    opts.banner = "Usage: thicket [options]"

    opts.on("-v", "--version", "Print the version number") do |v|
      args.name = v
      puts Thicket::VERSION
      exit
    end

    opts.on("-h", "--help", "Prints this help") do
      puts opts
      exit
    end

    opts.on("-d", "--directory DIRECTORY", String, "Path to the project directory") do |project_directory|
      args.name = project_directory
      @options[:project_directory] = File.expand_path(project_directory)
    end

    opts.on("-n", "--commit-limit LIMIT", Integer, "Number of commits to parse before stopping") do |limit|
      args.name = limit
      @options[:limit] = limit
    end

    opts.on("-a", "--all", TrueClass, "Displays all branches on all remotes") do |all|
      args.name = all
      @options[:all] = all
    end

    opts.on("-r", "--refs", TrueClass, "Consolidate the refs list") do |refs|
      args.name = refs
      @options[:consolidate_refs] = refs
    end

    opts.on("--main-remote=MAIN_REMOTE", String, "The name of the primary remote, defaults to 'origin'") do |main_remote|
      args.name = main_remote
      @options[:main_remote] = main_remote
    end

    opts.on("-p", "--color-prefixes", TrueClass, "Adds coloring to commit message prefixes.") do |prefixes|
      args.name = prefixes
      @options[:color_prefixes] = prefixes
    end

    opts.on("--git-binary BINARY", String, "Path to a git executable") do |git_binary|
      args.name = git_binary
      @options[:git_binary] = File.expand_path(git_binary)
    end
  end

  opt_parser.parse!(options)
rescue ::OptionParser::ParseError => e
  puts e.message
  exit
end