Sha256: c8438efc1b5e71e015fadbdc624aa2cc71e599b59b388fc5f0b0407c33d49d35

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require "thor"

module Munge
  class CLI < Thor
    include Thor::Actions

    def self.source_root
      File.expand_path("../../../seeds", __FILE__)
    end

    desc "init PATH", "Create new site at PATH"
    def init(path)
      directory ".", path
    end

    desc "build", "Build in current directory"
    def build
      Munge::Runner.write(config_path, rules_path)
    end

    desc "view", "View built files"
    method_option :port, aliases: "-p", desc: "Set port", default: 3000, type: :numeric
    method_option :host, aliases: "-h", desc: "Set host", default: "0.0.0.0", type: :string
    def view
      config    = Munge::Core::Config.new(config_path)
      handler   = Rack::Handler::WEBrick
      rack_opts = { Host: options[:host], Port: options[:port] }

      app =
        Rack::Builder.new do
          use Rack::CommonLogger
          use Rack::ShowExceptions
          use Rack::Lint
          use Rack::Head
          use Adsf::Rack::IndexFileFinder, root: config[:output]
          run Rack::File.new(config[:output])
        end

      Rack::Handler::WEBrick.run(app, rack_opts)
    end

    desc "version", "Print version"
    def version
      puts "munge #{Munge::VERSION}"
    end

    private

    def config_path
      File.join(destination_root, "config.yml")
    end

    def rules_path
      File.join(destination_root, "rules.rb")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
munge-0.4.0 lib/munge/cli.rb
munge-0.3.0 lib/munge/cli.rb