#!/usr/bin/env ruby STDOUT.sync = true $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib }) require 'commander/import' require 'monad' Monad::Deprecator.process(ARGV) program :name, 'monad' program :version, Monad::VERSION program :description, 'Monad is a blog-aware, static site generator in Ruby based on jekyll' default_command :help global_option '-s', '--source [DIR]', 'Source directory (defaults to ./)' global_option '-d', '--destination [DIR]', 'Destination directory (defaults to ./_site)' global_option '--safe', 'Safe mode (defaults to false)' global_option '--plugins PLUGINS_DIR1[,PLUGINS_DIR2[,...]]', Array, 'Plugins directory (defaults to ./_plugins)' global_option '--layouts', 'Layouts directory (defaults to ./_layouts)' # Option names don't always directly match the configuration value we'd like. # This method will rename options to match what Monad configuration expects. # # options - The Hash of options from Commander. # # Returns the normalized Hash. def normalize_options(options) if drafts_state = options.delete(:drafts) options[:show_drafts] = drafts_state end options end command :new do |c| c.syntax = 'monad new PATH' c.description = 'Creates a new Monad site scaffold in PATH' c.action do |args, options| Monad::Commands::New.process(args) end end command :build do |c| c.syntax = 'monad build [options]' c.description = 'Build your site' c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file' c.option '--future', 'Publishes posts with a future date' c.option '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish' c.option '-w', '--watch', 'Watch for changes and rebuild' c.option '--lsi', 'Use LSI for improved related posts' c.option '--drafts', 'Render posts in the _drafts folder' c.action do |args, options| options = normalize_options(options.__hash__) options = Monad.configuration(options) Monad::Commands::Build.process(options) end end command :serve do |c| c.syntax = 'monad serve [options]' c.description = 'Serve your site locally' c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file' c.option '--future', 'Publishes posts with a future date' c.option '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish' c.option '-w', '--watch', 'Watch for changes and rebuild' c.option '--lsi', 'Use LSI for improved related posts' c.option '--drafts', 'Render posts in the _drafts folder' c.option '-p', '--port [PORT]', 'Port to listen on' c.option '-h', '--host [HOST]', 'Host to bind to' c.option '-b', '--baseurl [URL]', 'Base URL' c.action do |args, options| options.default :serving => true options = normalize_options(options.__hash__) options = Monad.configuration(options) Monad::Commands::Build.process(options) Monad::Commands::Serve.process(options) end end alias_command :server, :serve command :doctor do |c| c.syntax = 'monad doctor' c.description = 'Search site and print specific deprecation warnings' c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file' c.action do |args, options| options = normalize_options(options.__hash__) options = Monad.configuration(options) Monad::Commands::Doctor.process(options) end end alias_command :hyde, :doctor