Class: CDQ::CreateAction

Inherits:
CommandLine show all
Defined in:
lib/cdq/cli.rb

Constant Summary collapse

HELP_TEXT =
%{
Usage:
cdq create [options] model <model>         # Create a CDQ model and associated test

Options:
}

Instance Attribute Summary

Attributes inherited from CommandLine

#singleton_options_passed

Instance Method Summary collapse

Methods inherited from CommandLine

run_all

Instance Method Details

#option_parserObject



121
122
123
124
125
126
127
128
129
# File 'lib/cdq/cli.rb', line 121

def option_parser
  super(HELP_TEXT).tap do |opts|
    opts.program_name = "cdq create"

    opts.on("-d", "--dry-run", "Do a Dry Run") do
      @dry_run = "dry_run"
    end
  end
end

#runObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/cdq/cli.rb', line 131

def run
  opts = option_parser
  opts.order!

  object = ARGV.shift

  unless singleton_options_passed
    case object
    when 'model'
      model_name = ARGV.shift
      if model_name

        #camelized = model_name.gsub(/[A-Z]/) { |m| "_#{m.downcase}" }.gsub
        CDQ::Generator.new(@dry_run).create('model', model_name)
      else
        puts "Please supply a model name"
        puts opts
      end
    else
      puts "Invalid object type: #{object}"
      puts opts
    end
  end
end