Sha256: cf10c40414d975eb028479783276732d09c91763f111fb3dbae0c282420575a3

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module Troy
  class Cli < Thor
    check_unknown_options!

    def self.exit_on_failure?
      true
    end

    def initialize(args = [], options = {}, config = {})
      if (config[:current_task] || config[:current_command]).name == "new" && args.empty?
        raise Error, "The site path is required. For details run: troy help new"
      end

      super
    end

    desc "new SITE", "Generate a new site structure"
    def new(path)
      generator = Generator.new
      generator.destination_root = path
      generator.invoke_all
    end

    desc "export", "Generate static files"
    def export
      Troy::Site.new(Dir.pwd).export
    end

    desc "watch", "Watch and auto export site"
    def watch
      Troy::Site.new(Dir.pwd).export
    end

    desc "version", "Display Troy version"
    map %w(-v --version) => :version
    def version
      say "Troy #{Troy::VERSION}"
    end

    desc "server", "Start a server"
    option :port, :type => :numeric, :default => 9292, :aliases => "-p"
    def server
      handler = Rack::Handler::Thin rescue Rack::Handler::WEBrick
      handler.run Troy::Server.new(File.join(Dir.pwd, "public")), :Port => options[:port]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
troy-0.0.18 lib/troy/cli.rb
troy-0.0.17 lib/troy/cli.rb
troy-0.0.16 lib/troy/cli.rb