Method: Webby::Apps::Generator#parse
- Defined in:
- lib/webby/apps/generator.rb
#parse(args) ⇒ Object
Parse out the command line options found in the args array.
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 121 122 123 124 125 126 127 |
# File 'lib/webby/apps/generator.rb', line 67 def parse( args ) opts = OptionParser.new opts. = 'Usage: webby-gen [options] template site' opts.separator '' opts.separator 'The webby-gen command is used to generate a site from a standard template.' opts.separator 'A new site can be created, or an existing site can be added to or updated.' opts.separator '' opts.on('-f', '--force', 'overwrite files that already exist') {[:collision] = :force} opts.on('-s', '--skip', 'skip files that already exist') {[:collision] = :skip} opts.on('-u', '--update', 'update rake tasks for the site') {[:update] = true} opts.on('-p', '--pretend', 'run but do not make any changes') {[:pretend] = true} opts.separator '' opts.on('-t', '--templates', 'list available templates') { ary = templates.map {|t| ::File.basename(t)} ary.delete 'webby' puts "\nAvailable Templates" puts " #{ary.join(', ')}" puts exit } opts.separator '' opts.separator 'common options:' opts.on( '-h', '--help', 'show this message' ) {puts opts; exit} opts.on( '--version', 'show version' ) do puts "Webby #{::Webby::VERSION}" exit end # parse the command line arguments opts.parse! args tmpl, @site = args # if no site was given, see if there is a Sitefile in the current # directory if site.nil? self.site = '.' if test(?f, 'Sitefile') end # exit if comand line args are missing if site.nil? or tmpl.nil? puts opts exit 1 end templates.each {|t| self.template = t if t =~ %r/\/#{tmpl}$/} if template.nil? puts opts abort "Could not find template '#{tmpl}'" end nil end |