Class: Awestruct::CLI::Options
- Inherits:
-
Object
- Object
- Awestruct::CLI::Options
- Defined in:
- lib/awestruct/cli/options.rb
Constant Summary collapse
- LOCAL_HOSTS =
{ 'localhost' => 'localhost', '0.0.0.0' => 'localhost', '127.0.0.1' => 'localhost', '::1' => '[::1]', 'localhost6' => 'localhost6' }
- DEFAULT_BIND_ADDR =
'0.0.0.0'- DEFAULT_PORT =
4242- DEFAULT_BASE_URL =
%(http://#{LOCAL_HOSTS[DEFAULT_BIND_ADDR] || DEFAULT_BIND_ADDR}:#{DEFAULT_PORT})- DEFAULT_GENERATE_ON_ACCESS =
false
Instance Attribute Summary collapse
-
#auto ⇒ Object
Returns the value of attribute auto.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#bind_addr ⇒ Object
Returns the value of attribute bind_addr.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#deploy ⇒ Object
Returns the value of attribute deploy.
-
#force ⇒ Object
Returns the value of attribute force.
-
#framework ⇒ Object
Returns the value of attribute framework.
-
#generate ⇒ Object
Returns the value of attribute generate.
-
#generate_on_access ⇒ Object
Returns the value of attribute generate_on_access.
-
#init ⇒ Object
Returns the value of attribute init.
-
#livereload ⇒ Object
Returns the value of attribute livereload.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
-
#port ⇒ Object
Returns the value of attribute port.
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#quiet ⇒ Object
Returns the value of attribute quiet.
-
#scaffold ⇒ Object
Returns the value of attribute scaffold.
-
#script ⇒ Object
Returns the value of attribute script.
-
#server ⇒ Object
Returns the value of attribute server.
-
#source_dir ⇒ Object
Returns the value of attribute source_dir.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #parse!(args) ⇒ Object
Constructor Details
#initialize ⇒ Options
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/awestruct/cli/options.rb', line 42 def initialize() @generate = nil @server = false @port = DEFAULT_PORT @bind_addr = DEFAULT_BIND_ADDR @auto = false @force = false @init = false @framework = 'compass' @scaffold = true @base_url = DEFAULT_BASE_URL @profile = nil @deploy = false @script = nil @verbose = false @quiet = false @livereload = false @source_dir = Dir.pwd @output_dir = File. '_site' @generate_on_access = DEFAULT_GENERATE_ON_ACCESS end |
Instance Attribute Details
#auto ⇒ Object
Returns the value of attribute auto.
25 26 27 |
# File 'lib/awestruct/cli/options.rb', line 25 def auto @auto end |
#base_url ⇒ Object
Returns the value of attribute base_url.
30 31 32 |
# File 'lib/awestruct/cli/options.rb', line 30 def base_url @base_url end |
#bind_addr ⇒ Object
Returns the value of attribute bind_addr.
24 25 26 |
# File 'lib/awestruct/cli/options.rb', line 24 def bind_addr @bind_addr end |
#debug ⇒ Object
Returns the value of attribute debug.
39 40 41 |
# File 'lib/awestruct/cli/options.rb', line 39 def debug @debug end |
#deploy ⇒ Object
Returns the value of attribute deploy.
32 33 34 |
# File 'lib/awestruct/cli/options.rb', line 32 def deploy @deploy end |
#force ⇒ Object
Returns the value of attribute force.
26 27 28 |
# File 'lib/awestruct/cli/options.rb', line 26 def force @force end |
#framework ⇒ Object
Returns the value of attribute framework.
28 29 30 |
# File 'lib/awestruct/cli/options.rb', line 28 def framework @framework end |
#generate ⇒ Object
Returns the value of attribute generate.
21 22 23 |
# File 'lib/awestruct/cli/options.rb', line 21 def generate @generate end |
#generate_on_access ⇒ Object
Returns the value of attribute generate_on_access.
40 41 42 |
# File 'lib/awestruct/cli/options.rb', line 40 def generate_on_access @generate_on_access end |
#init ⇒ Object
Returns the value of attribute init.
27 28 29 |
# File 'lib/awestruct/cli/options.rb', line 27 def init @init end |
#livereload ⇒ Object
Returns the value of attribute livereload.
38 39 40 |
# File 'lib/awestruct/cli/options.rb', line 38 def livereload @livereload end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
37 38 39 |
# File 'lib/awestruct/cli/options.rb', line 37 def output_dir @output_dir end |
#port ⇒ Object
Returns the value of attribute port.
23 24 25 |
# File 'lib/awestruct/cli/options.rb', line 23 def port @port end |
#profile ⇒ Object
Returns the value of attribute profile.
31 32 33 |
# File 'lib/awestruct/cli/options.rb', line 31 def profile @profile end |
#quiet ⇒ Object
Returns the value of attribute quiet.
35 36 37 |
# File 'lib/awestruct/cli/options.rb', line 35 def quiet @quiet end |
#scaffold ⇒ Object
Returns the value of attribute scaffold.
29 30 31 |
# File 'lib/awestruct/cli/options.rb', line 29 def scaffold @scaffold end |
#script ⇒ Object
Returns the value of attribute script.
33 34 35 |
# File 'lib/awestruct/cli/options.rb', line 33 def script @script end |
#server ⇒ Object
Returns the value of attribute server.
22 23 24 |
# File 'lib/awestruct/cli/options.rb', line 22 def server @server end |
#source_dir ⇒ Object
Returns the value of attribute source_dir.
36 37 38 |
# File 'lib/awestruct/cli/options.rb', line 36 def source_dir @source_dir end |
#verbose ⇒ Object
Returns the value of attribute verbose.
34 35 36 |
# File 'lib/awestruct/cli/options.rb', line 34 def verbose @verbose end |
Class Method Details
.parse!(args) ⇒ Object
64 65 66 |
# File 'lib/awestruct/cli/options.rb', line 64 def self.parse!(args) Options.new.parse! args end |
Instance Method Details
#parse!(args) ⇒ Object
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/awestruct/cli/options.rb', line 68 def parse!(args) opts = OptionParser.new do |opts| opts.on('-D', '--debug', 'Enable debug logging') do |verbose| self.debug = true end opts.on('-w', '--verbose', 'Enable verbose mode') do |verbose| self.verbose = true end opts.on('-q', '--quiet', 'Only display warnings and errors') do |quiet| self.quiet = 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, foundation, 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 #{DEFAULT_PORT}, --profile development, --livereload and --generate_on_access)" ) do |url| self.server = true self.auto = true self.port = DEFAULT_PORT self.profile = 'development' self.livereload = true self.generate_on_access = true end opts.on( '-a', '--auto', 'Auto-generate when changes are noticed' ) do |a| self.auto = a self.livereload = true end opts.on( '--[no-]livereload', 'Support for browser livereload' ) do |livereload| self.livereload = livereload self.generate_on_access = true if self.livereload end opts.on( '--[no-]generate-on-access', 'Support for calling generate on HTTP access' ) do |generate_on_access| self.generate_on_access = generate_on_access 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( '-p', '--port PORT', Integer, "Server port (default: #{DEFAULT_PORT})" ) do |port| self.port = port end opts.on( '-b', '--bind ADDR', "Server address (default: #{DEFAULT_BIND_ADDR})" ) 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.on( '--source-dir DIR', 'Location of sources (default: .' ) do |source_dir| self.source_dir = File. source_dir self.output_dir = File. File.join(self.source_dir, '_site') end opts.on( '--output-dir DIR', 'Location to output generated site (default: _site' ) do |output_dir| self.output_dir = File. output_dir 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.port ||= DEFAULT_PORT self.bind_addr = LOCAL_HOSTS[DEFAULT_BIND_ADDR] if self.bind_addr === DEFAULT_BIND_ADDR self.base_url = %(http://#{self.bind_addr}:#{self.port}) if self.base_url === DEFAULT_BASE_URL self.generate = true if self.generate.nil? self end |