Class: Awestruct::CLI::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/cli/options.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/awestruct/cli/options.rb', line 25

def initialize()
  @generate  = nil
  @server    = false
  @port      = 4242
  @bind_addr = '0.0.0.0'
  @auto      = false
  @force     = false
  @init      = false
  @framework = 'compass'
  @scaffold  = true
  @base_url  = nil
  @profile   = nil
  @deploy    = false
  @script    = nil
  @verbose   = false
end

Instance Attribute Details

#autoObject

Returns the value of attribute auto.



14
15
16
# File 'lib/awestruct/cli/options.rb', line 14

def auto
  @auto
end

#base_urlObject

Returns the value of attribute base_url.



19
20
21
# File 'lib/awestruct/cli/options.rb', line 19

def base_url
  @base_url
end

#bind_addrObject

Returns the value of attribute bind_addr.



13
14
15
# File 'lib/awestruct/cli/options.rb', line 13

def bind_addr
  @bind_addr
end

#deployObject

Returns the value of attribute deploy.



21
22
23
# File 'lib/awestruct/cli/options.rb', line 21

def deploy
  @deploy
end

#forceObject

Returns the value of attribute force.



15
16
17
# File 'lib/awestruct/cli/options.rb', line 15

def force
  @force
end

#frameworkObject

Returns the value of attribute framework.



17
18
19
# File 'lib/awestruct/cli/options.rb', line 17

def framework
  @framework
end

#generateObject

Returns the value of attribute generate.



10
11
12
# File 'lib/awestruct/cli/options.rb', line 10

def generate
  @generate
end

#initObject

Returns the value of attribute init.



16
17
18
# File 'lib/awestruct/cli/options.rb', line 16

def init
  @init
end

#portObject

Returns the value of attribute port.



12
13
14
# File 'lib/awestruct/cli/options.rb', line 12

def port
  @port
end

#profileObject

Returns the value of attribute profile.



20
21
22
# File 'lib/awestruct/cli/options.rb', line 20

def profile
  @profile
end

#scaffoldObject

Returns the value of attribute scaffold.



18
19
20
# File 'lib/awestruct/cli/options.rb', line 18

def scaffold
  @scaffold
end

#scriptObject

Returns the value of attribute script.



22
23
24
# File 'lib/awestruct/cli/options.rb', line 22

def script
  @script
end

#serverObject

Returns the value of attribute server.



11
12
13
# File 'lib/awestruct/cli/options.rb', line 11

def server
  @server
end

#verboseObject

Returns the value of attribute verbose.



23
24
25
# File 'lib/awestruct/cli/options.rb', line 23

def verbose
  @verbose
end

Class Method Details

.parse!(args) ⇒ Object



42
43
44
# File 'lib/awestruct/cli/options.rb', line 42

def self.parse!(args)
  Options.new.parse! args
end

Instance Method Details

#parse!(args) ⇒ Object



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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/awestruct/cli/options.rb', line 46

def parse!(args)
  opts = OptionParser.new do |opts|
    opts.on('-w', '--verbose', 'Enable verbose mode') do |verbose|
      self.verbose = true
    end
    opts.on( '-i', '--init', 'Initialize a new project in the current directory' ) do |init|
      self.init     = init
      self.generate = false
    end
    opts.on( '-f', '--framework FRAMEWORK', 'Specify a compass framework during initialization (bootstrap, blueprint, 960)' ) do |framework|
      self.framework = framework
    end
    opts.on( '--[no-]scaffold', 'Create scaffolding during initialization (default: true)' ) do |s|
      self.scaffold = s
    end
    opts.on( '--force', 'Force a regeneration' ) do |force|
      self.force = force
    end
    opts.on( '-s', '--server', 'Serve generated site' ) do |s|
      self.server = s
    end
    opts.on( '-u', '--url URL', 'Set site.base_url' ) do |url|
      self.base_url = url
    end
    opts.on( '-d', '--dev',     'Run site in development mode (--auto, --server, --port 4242 and --profile development)' ) do |url|
      self.server   = true
      self.auto     = true
      self.port     = 4242
      self.profile  = 'development'
    end

    opts.on( '-P', '--profile PROFILE', 'Activate a configuration profile' ) do |profile|
      self.profile = profile
    end

    opts.on( '--deploy', 'Deploy site' ) do |deploy|
      self.deploy = deploy
      self.generate = false if self.generate.nil?
    end

    opts.on( '-a', '--auto', 'Auto-generate when changes are noticed' ) do |a|
      self.auto = a
    end
    opts.on( '-p', '--port PORT', Integer, 'Server port (default: 4242)' ) do |port|
      self.port = port
    end
    opts.on( '-b', '--bind ADDR', 'Server address (default: 0.0.0.0)' ) do |bind_addr|
      self.bind_addr = bind_addr
    end
    opts.on( '-g', '--[no-]generate', 'Generate site' ) do |g|
      self.generate = g
    end
    #opts.on( '--run SCRIPT', 'Invoke a script after initialization' ) do |script|
    #  self.script = script
    #end

    opts.separator ''
    opts.separator "Common options:"

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  
    opts.on_tail("-v", "--version", "Display the version") do
      puts "Awestruct: #{Awestruct::VERSION}"
      puts "http://awestruct.org/"
      exit
    end
  end

  opts.parse!(args)
  self.generate = true if self.generate.nil?
  self
end