Sha256: aa22b217c0aaa2ff944d2fc0fce43f319784900b78ed837d206255a586d8d874

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require "mothership/help/printer"

class Mothership
  class << self
    # add command to help group
    def group(*names)
      options =
        if names.last.is_a? Hash
          names.pop
        else
          {}
        end

      Mothership::Help.add_to_group(@command, names, options)
    end
  end

  def default_action
    invoke :help
  end

  def unknown_command(name)
    $stderr.print "Unknown command '#{name.to_s.gsub("_", "-")}'. "
    $stderr.puts "See 'help' for available commands."
    exit_status 1
  end

  desc "Help!"
  input :command, :argument => :optional
  input :all, :type => :boolean
  def help
    if name = input[:command]
      if cmd = @@commands[name.gsub("-", "_").to_sym]
        Mothership::Help.command_help(cmd)
      else
        unknown_command(name)
      end
    elsif Help.has_groups?
      unless input[:all]
        puts "Showing basic command set. Run with 'help --all' to list all commands."
        puts ""
      end

      Mothership::Help.print_help_groups(@@global, input[:all])
    else
      Mothership::Help.basic_help(@@commands, @@global)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mothership-0.5.1 lib/mothership/help/commands.rb