Module: Zing::CommandParser

Defined in:
lib/zing/command_parser.rb

Class Method Summary collapse

Class Method Details

.parse(args, options) ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/zing/command_parser.rb', line 10

def self.parse(args, options)

  # prepare parsing of command line arguments
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: zing [options]"

    opts.separator " "
    opts.separator "Specific options:"

    opts.on("-b", "--base",
            "Zing base CMS") do |lib|
      options.base = true
    end

    opts.on("-p", "--push",
            "Zing push module on top of base CMS") do |lib|
      options.push = true
    end

    opts.on("-m", "--model MODEL_NAME",
            "Zing CRUD for individual MODEL_NAME, use commas for multiple models") do |ver|
      if ver.split(",").class == Array
        options.model = ver.split(",").map(&:strip)
      elsif ver.class == String
        options.model = var
      else
        options.model = nil
      end
    end

    # No argument, shows at tail. This will print an options summary.
    # Try it and see!
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      raise
    end

  end

  opts.parse!(args)

  # NOTE: 
  # We assume that zing is run at the root app folder
  #
  # set current dir as project absolute dir
  options.project_absolute_dir = FileUtils.pwd

  # set app name as the project folder
  options.project_name = FileUtils.pwd.split("/").last
  options.app_name = options.project_name

rescue Exception => e
  if e.message.match(/invalid option/i) or e.message.match(/missing argument/i)
    puts "ERROR: #{e.message}".red
    puts ""
    puts opts
  end
  raise
end