Class: Anvil::Console

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

Constant Summary collapse

@@anvil_opts =
{}

Class Method Summary collapse

Class Method Details

.parse_opts(argv = ARGV) ⇒ Object



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
# File 'lib/console.rb', line 26

def parse_opts(argv = ARGV)
  options = {}
  
  options[:start_anvil] = true
  
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: anvil [gih] [argument]"
    opts.define_head "Anvil GUI framework."
    opts.separator '*'*80
    opts.separator 'If no flags are given, Anvil starts in the foreground'
    opts.separator '*'*80
    
    opts.on("-i", "--irb-console", "This flag will start Anvil in irb console. Your application models and classes will be loaded and available through console.") do |console|
      options[:console] = true
      options[:start_anvil] = false
      puts "Coming Soon!"
    end
    
    opts.on("-g", "--generate-app PATH", "Generate a fresh Anvil application at PATH") do |path|
      options[:generate] = path || Dir.pwd
      options[:start_anvil] = false
    end
    
    opts.on("-?", "-h", "--help", "Show this help message") do
      puts opts
      exit
    end
  end
  
  opts.parse!(argv)
  
  # anvil <argument> is the same as anvil -g <argument>
  if argv.size == 1
    options[:generate] = File.expand_path(argv.last)
    options[:start_anvil] = false
  end
  
  @@anvil_opts = options
end

.runObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/console.rb', line 13

def run
  parse_opts
  
  # Start Anvil when option is set
  Anvil::Initializer.run if @@anvil_opts[:start_anvil]
  
  # Generate fresh Anvil Application if option is set
  if @@anvil_opts[:generate]
    Anvil::AppGenerator.run @@anvil_opts[:generate]
    exit!
  end
end