Class: Peacock::CLI
- Inherits:
-
Object
- Object
- Peacock::CLI
- Defined in:
- lib/peacock/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_if_help_text ⇒ Object
- #determine_type(opt) ⇒ Object
- #help_text ⇒ Object
- #options ⇒ Object
- #parse_args ⇒ Object
- #should_print_help? ⇒ Boolean
Class Method Details
.parse ⇒ Object
5 6 7 8 9 |
# File 'lib/peacock/cli.rb', line 5 def self.parse parser = CLI.new parser.check_if_help_text parser.parse_args end |
Instance Method Details
#check_if_help_text ⇒ Object
34 35 36 37 38 39 |
# 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) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/peacock/cli.rb', line 22 def determine_type(opt) if File.directory?(opt) :dirs elsif File.file?(opt) :files elsif .include?(opt) :opts else nil end end |
#help_text ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/peacock/cli.rb', line 45 def help_text " Usage: \n \\tpeacock [options] [files/directories]\n \n Options:\n \\t-h, [--help] # show this text\n \\t-r, [--root] # use root .gitignore\n \\t-s, [--silent] # surpress output\n \\t-e, [--extract] # extract file from .gitignore\n EOF\nend\n".gsub /^ */, '' |
#options ⇒ Object
58 59 60 |
# File 'lib/peacock/cli.rb', line 58 def %w(-r --root -e --extract -s --silent) end |
#parse_args ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# 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? ⇒ Boolean
41 42 43 |
# File 'lib/peacock/cli.rb', line 41 def should_print_help? ARGV.size == 0 || ARGV[0] == '-h' || ARGV[0] == '--help' end |