class Peacock::CLI

Public Class Methods

parse() click to toggle source
# File lib/peacock/cli.rb, line 5
def self.parse
  parser = CLI.new
  parser.check_if_help_text
  parser.parse_args
end

Public Instance Methods

check_if_help_text() click to toggle source
# File lib/peacock/cli.rb, line 34
def check_if_help_text
  if should_print_help?
    puts help_text
    exit 0
  end
end
determine_type(opt) click to toggle source
# File lib/peacock/cli.rb, line 22
def determine_type(opt)
  if File.directory?(opt)
    :dirs
  elsif File.file?(opt)
    :files
  elsif options.include?(opt)
    :opts
  else
    nil
  end
end
help_text() click to toggle source
# File lib/peacock/cli.rb, line 45
    def help_text
      <<-EOF.gsub /^ */, ''
        Usage: 
          \tpeacock [options] [files/directories]
        
        Options:
          \t-h, [--help]           # show this text
          \t-r, [--root]           # use root .gitignore
          \t-s, [--silent]         # surpress output
          \t-e, [--extract]        # extract file from .gitignore
      EOF
    end
options() click to toggle source
# File lib/peacock/cli.rb, line 58
def options
  %w(-r --root -e --extract -s --silent)
end
parse_args() click to toggle source
# File lib/peacock/cli.rb, line 11
def parse_args
  return_hash = Peacock::CLIHash.new
  
  ARGV.each do |arg|
    type = determine_type arg
    return_hash.push(type, arg) unless type.nil?
  end
  
  return_hash
end
should_print_help?() click to toggle source
# File lib/peacock/cli.rb, line 41
def should_print_help?
  ARGV.size == 0 || ARGV[0] == '-h' || ARGV[0] == '--help'
end