Sha256: c4e2157c51442908aa65644dd5be0defc64d712de6060b1e7750804bdd6c703f

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require_relative 'commands/build'
require_relative 'commands/new'
require_relative 'commands/version'

module Mako
  class CLI
    COMMANDS = %w[build new version].freeze

    # Takes ARGV and parses the first element (command) to see if it is
    # in the commands array.  If not, display help.
    #
    # @param [Array] argv
    def self.start(argv)
      command = argv.shift
      if COMMANDS.include? command
        CLI.invoke(command, argv)
      else
        help = <<~EOS
          Usage:
            mako [subcommand] [path...]

          Subcommands:
            new       Create a new Mako scaffold in PATH.  If no PATH provided, defaults to current directory.
            build     Build your Mako site. Default: only build HTML.
            version   Display the version.

          Options:
            --with-sass  When supplied to build, also generates CSS from SCSS files.
        EOS
        Mako.logger.info help
      end
    end

    # Calls #perform on the provided command class. When the command is done
    # running, print out any errors that the command had.
    #
    # @param [String] command
    # @param [Array] args the remainder of the ARGV arguments
    def self.invoke(command, args = [])
      Object.const_get("Mako::#{command.capitalize}").perform(args)
      return unless Mako.errors.any?
      Mako.errors.messages.each do |error_msg|
        Mako.logger.warn error_msg
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mako_rss-0.1.0 lib/mako/cli.rb