#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/nanoc.rb' require 'getoptlong' try_require 'rubygems' # Define some texts version_text = "nanoc #{Nanoc::VERSION} (c) 2007 Denis Defreyne." usage_text = "Usage: nanoc [options] [command] [parameters]" help_text = < nanoc create_page [-t template] nanoc create_template nanoc compile Options: -h, --help Show this help message and quit. -v, --version Show the nanoc version number and quit. -t, --template Template that should be used when creating a page. (can only be used with create_page) Description: The 'nanoc' command is used for creating nanoc-powered sites, as well as managing them: creating pages and templates and compiling the site. Read more about nanoc on the site: EOT # Parse options opts = GetoptLong.new( [ '--help', '-h', GetoptLong::NO_ARGUMENT ], [ '--template', '-t', GetoptLong::REQUIRED_ARGUMENT ], [ '--version', '-v', GetoptLong::NO_ARGUMENT ] ) unprocessed_opts = {} begin opts.each do |opt, arg| case opt when '--help' $stderr.puts help_text exit when '--version' puts version_text exit else unprocessed_opts[opt] = arg end end rescue GetoptLong::InvalidOption $stderr.puts usage_text exit end # Make sure we have at least one argument if ARGV.size == 0 $stderr.puts usage_text exit end # Handle command command = ARGV[0] case command # Create site when 'create_site', 'cs' if ARGV.size != 2 $stderr.puts 'Usage: nanoc create_site [site_name]' exit end $nanoc_creator.create_site(ARGV[1]) # Create page when 'create_page', 'cp' if ARGV.size != 2 $stderr.puts 'Usage: nanoc create_page [page_name]' exit end $nanoc_creator.create_page(ARGV[1], :template => unprocessed_opts['--template']) # Create template when 'create_template', 'ct' if ARGV.size != 2 $stderr.puts 'Usage: nanoc create_template [template_name]' exit end $nanoc_creator.create_template(ARGV[1]) # Process site and generate output when 'compile', 'compile_site', 'co' if ARGV.size != 1 $stderr.puts 'Usage: nanoc compile' exit end $nanoc_compiler.run else puts 'Unrecognised command \'' + command + '\'' end