lib/hyde/cli.rb in hydeweb-0.1.1 vs lib/hyde/cli.rb in hydeweb-0.1.2

- old
+ new

@@ -5,14 +5,20 @@ 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 @@ -34,10 +40,11 @@ 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 @@ -54,10 +61,11 @@ 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 @@ -67,15 +75,61 @@ 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} <command>" + + 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']