class Hyde class CLI < Shake autoload :Helpers, "#{PREFIX}/hyde/cli/helpers" extend Helpers include Defaults task(:create) do wrong_usage unless params.size == 1 template = File.expand_path('../../../data/new_site', __FILE__) target = params.first if target == '.' pass "This is already a Hyde project." if @hydefile FileUtils.cp_r File.join(template, 'hyde.conf'), target say_status :create, 'hyde.conf' pass end pass "Error: target directory already exists." if File.directory?(target) puts "Creating files in #{target}:" puts FileUtils.cp_r template, target Dir[File.join(target, '**', '*')].sort.each do |f| say_status :create, f if File.file?(f) end puts "" puts "Done! You've created a new project in #{target}." puts "Get started now:" puts "" puts " $ cd #{target}" puts " $ #{executable} start" puts "" puts "Or build the HTML files:" puts "" puts " $ #{executable} build" puts "" end task.description = "Starts a new Hyde project" task.usage = "create NAME" task.category = :create task(:build) do pre = project.config.output_path begin project.build { |page| handler = '' handler = "(#{page.tilt_engine_name})" if page.tilt? puts ("\033[0;33m*\033[0;32m #{pre}\033[0;m%-50s%s" % [ page.path, handler ]).strip } rescue NoGemError => e err "Error: #{e.message}" rescue Error => e err "Error: #{e.message}" ensure project.send :build_cleanup end end task.description = "Builds the current project" task.category = :project task(:start) do project port = (params.extract('-p') || 4833).to_i host = (params.extract('-o') || '0.0.0.0') require 'hyde/server' Hyde::Server.run! :Host => host, :Port => port end task.description = "Starts the server" task.category = :project task(:version) do puts "Hyde #{Hyde::VERSION}" end task.description = "Shows the current version" task.category = :misc task(:help) do show_help_for(params.first) and pass if params.any? show_task = Proc.new { |name, t| err " %-20s %s" % [ t.usage || name, t.description ] } err "Usage: #{executable} " err "\nCommands:" tasks_for(:create).each &show_task err "\nProject commands:" tasks_for(:project).each &show_task if other_tasks.any? err "\nOthers:" other_tasks.each &show_task end err "\nMisc commands:" tasks_for(:misc).each &show_task unless project? err err "Get started by typing:" err " $ #{executable} create my_project" err err "Type `#{executable} help COMMAND` for additional help on a command." end end task.description = "Shows help for a given command" task.usage = "help [COMMAND]" task.category = :misc invalid do task = task(command) if task err "Invalid usage." err "Try: #{executable} #{task.usage}" err err "Type `#{executable} help` for more info." else err "Invalid command: #{command}" err "Type `#{executable} help` for more info." end end def self.run!(options={}) @hydefile = options[:file] return invoke(:version) if ARGV == ['-v'] return invoke(:version) if ARGV == ['--version'] begin super *[] end end end end