Sha256: 43634154bcc53e99ad5e0813fcb8833e652c049ba19bea566bbc577f4858594b

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

# Require thor since that's what the who CLI is built around
require 'thor'
require "thor/group"

# CLI Module
module Middleman::Cli
  
  # The base task from which everything else etends
  class Base < Thor
    
    desc "version", "Show version"
    def version
      require 'middleman-core/version'
      say "Middleman #{Middleman::VERSION}"
    end
    
    # Override the Thor help method to find help for subtasks
    # @param [Symbol, String, nil] meth
    # @param [Boolean] subcommand
    # @return [void]
    def help(meth = nil, subcommand = false)
      if meth && !self.respond_to?(meth)
        klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
        klass.start(["-h", task].compact, :shell => self.shell)
      else
        list = []
        Thor::Util.thor_classes_in(Middleman::Cli).each do |klass|
          list += klass.printable_tasks(false)
        end
        list.sort!{ |a,b| a[0] <=> b[0] }
        
        shell.say "Tasks:"
        shell.print_table(list, :ident => 2, :truncate => true)
        shell.say
      end
    end
    
    # Intercept missing methods and search subtasks for them
    # @param [Symbol] meth
    def method_missing(meth, *args)
      meth = meth.to_s
      
      if self.class.map.has_key?(meth)
        meth = self.class.map[meth]
      end
      
      klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
      args.unshift(task) if task
      klass.start(args, :shell => self.shell)
    end
  end
end

# Include the core CLI items
require "middleman-core/cli/init"
require "middleman-core/cli/server"
require "middleman-core/cli/build"

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
middleman-core-3.0.0.beta.1 lib/middleman-core/cli.rb
middleman-core-3.0.0.alpha.9 lib/middleman-core/cli.rb
middleman-core-3.0.0.alpha.8 lib/middleman-core/cli.rb
middleman-core-3.0.0.alpha.7 lib/middleman-core/cli.rb