Class: Mako::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/mako/cli.rb

Constant Summary collapse

COMMANDS =
%w[build new subscribe version].freeze

Class Method Summary collapse

Class Method Details

.invoke(command, args = []) ⇒ Object

Calls #perform on the provided command class. When the command is done running, print out any errors that the command had.

Parameters:

  • command (String)
  • args (Array) (defaults to: [])

    the remainder of the ARGV arguments



43
44
45
46
47
48
49
50
# File 'lib/mako/cli.rb', line 43

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

.start(argv) ⇒ Object

Takes ARGV and parses the first element (command) to see if it is in the commands array. If not, display help.

Parameters:

  • argv (Array)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mako/cli.rb', line 16

def self.start(argv)
  command = argv.shift
  if COMMANDS.include? command
    CLI.invoke(command, argv)
  else
    help = <<~HELP
      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.
        subscribe Subscribe to the supplied URL or URLs.  Accepts a list separated by spaces.
        version   Display the version.

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