Class: Shellpress::CLI

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

Constant Summary

Constants inherited from Thor

Thor::ORDER

Instance Method Summary collapse

Methods inherited from Thor

banner

Instance Method Details

#help(*commands) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/shellpress/cli.rb', line 43

def help(*commands)
  if commands.empty?
    # Case 1:
    # Either `shellpress help' or `shellpress' called. Print out help for all commands.
    ks = Shellpress.constants.map { |k| Shellpress.const_get(k) }
    ks = ks.sort_by { |k| k::ORDER }
    # Don't call help on CLI or infinite recursion occurs
    ks.reject { |k| self.class == k || k == Shellpress::Thor }.each do |klass|
      print_table_for_class(klass)
    end
    say "Use `#{prefix(self.class)} help [COMMAND] [SUBCOMMAND]' to learn more."
  else
    cmd = commands[0]
    klass = constantize(cmd)
    unless klass
      say "Unknown command `#{cmd}'."
    else
      klass.new.help(*commands[1..-1])
    end
  end
end