Class: Ubiquo::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/ubiquo/options.rb

Overview

TODO: Improve banner to inform of UBIQUO_OPTS env var merging TODO: Add git needed params for repo creation on github

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ubiquo/options.rb', line 8

def initialize(args)
  @orig_args = args.clone

  self[:template] = :stable
  self[:profile]  = :complete
  self[:locale] = :en
  self[:devel]    = false
  self[:database] = :sqlite
  self[:exception_recipient] = "[email protected]"
  self[:sender_address] = "[email protected]"


  @opts = OptionParser.new do |o|
    o.banner = """Usage: #{File.basename($0)} [options] application_name"
    o.separator "\nSelect a database (defaults to sqlite if not specified):"

    suported_databases.each do |db,msg|
      o.on("--#{db.to_s}", msg) { self[:database] = db }
    end

    o.separator "\nSelect a template (defaults to stable if not specified):"

    suported_templates.each do |tpl, msg|
      o.on("--#{tpl.to_s}", msg) { self[:template] = tpl }
    end

    o.separator "\nSelect a profile (defaults to complete if not specified):"

    suported_profiles.each do |profile, msg|
      o.on("--#{profile.to_s}", msg) { self[:profile] = profile }
    end
    o.on(
      "--custom [PLUGINS]",
      "Includes minimal template, but you can add extra plugins"
    ) do |plugins|
      self[:profile] = :custom
      self[:plugins] = plugins.split(",")
    end

    o.separator "\nSelects ubiquo default locale (defaults to english): "

    suported_locales.each do |locale, msg|
      o.on("--#{locale.to_s}", msg) { self[:locale] = locale }
    end

    o.separator "\nException notification options: "

    o.on("--recipient [EMAIL]", "E-mail for exception notifications.") do |recipient|
      self[:exception_recipient] = recipient
    end

    o.on("--sender [EMAIL]", "E-mail to use in from.") do |sender|
      self[:sender_address] = sender
    end

    o.separator "\nExtra options:"

    o.on("--devel", 'For ubiquo developers (ssh acces to github repos)') do
      self[:devel] = true
    end

    o.on("-v", '--version', "Displays this gem version.") do
      self[:version] = File.read(File.dirname(__FILE__) + "/../../VERSION").strip
    end

    o.on_tail('-h', '--help', 'displays this help and exit') do
      self[:show_help] = true
    end

  end

  begin
    @opts.parse!(args)
    self[:app_name] = args.shift
  rescue OptionParser::InvalidOption => e
    self[:invalid_argument] = e.message
  end
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/ubiquo/options.rb', line 6

def opts
  @opts
end

#orig_argsObject (readonly)

Returns the value of attribute orig_args.



6
7
8
# File 'lib/ubiquo/options.rb', line 6

def orig_args
  @orig_args
end

Instance Method Details

#merge(other) ⇒ Object



87
88
89
# File 'lib/ubiquo/options.rb', line 87

def merge(other)
  self.class.new(@orig_args + other.orig_args)
end