Class: GitTools::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/gitools/parse.rb

Constant Summary collapse

COMMANDS =
["update", "add", "setup"].freeze

Class Method Summary collapse

Class Method Details

.parse!(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gitools/parse.rb', line 6

def self.parse!(args)
  options           = OpenStruct.new
  options.command   = args.first
  options.library   = args.last if args.size > 1
  options.yaml      = Dir.pwd
  
  opts = OptionParser.new do |opts|
    
    opts.banner = "\nGit Tools Usage\n"
    opts.separator "You must be in your Application Root Directory when running this command."
    opts.separator "There are a few basic commands:"
    opts.separator ""
    opts.separator "gitools setup                         will init and update your git submodules."
    opts.separator "gitools update all                    will update all git submodules."
    opts.separator "gitools update submodule_name         will update just that given submodule."
    opts.separator "gitools install all                   will do git submodule add for all submodules declared in your config/submodules.yml file."
    opts.separator "gitools install submodule_name        will do a git submodule add just for that submodule."
    opts.separator ""
    
    opts.on_tail('-v', '--version', "Show GitTools' current version.") do
      puts "Git Tools is at version #{GitTools::Version}\n"
      exit(0)
    end
    
    opts.on_tail('-h', '--help', "Help Me!") do
      puts "#{opts}\n"
      exit(0)
    end
    

    opts.on_tail do
      if (options.library.nil? || options.library == '') && options.command != "setup"
        puts "\nYou need to tell me what you want library you want to add to git submodule."
        puts "#{opts}\n"
        exit(0)
      elsif !COMMANDS.include?(options.command)
        puts "\nOnly setup, update, and install are supported commands."
        puts "#{opts}\n"
        exit(0)
      end
    end
  end # OptionParser
  
  opts.parse!(args)
  options
end