Method: Thor#help

Defined in:
lib/thor.rb

#help(*args) ⇒ Object



882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
# File 'lib/thor.rb', line 882

def help(*args)
  is_subcommand = case args[-1]
  when true, false
    args.pop
  else
    false
  end
  
  # Will be the {String} command (get help on that command)
  # or `nil` (get help on this class)
  command = args.shift
  
  # Possibly empty array of string subcommands from something like
  # 
  #     myexe help sub cmd
  # 
  # in which case it would end up being `['cmd']` and we actually are just
  # passing through and want to get help on the `cmd` subcommand.
  # 
  subcommands = args
  
  logger.trace "#help",
    args: args,
    command: command,
    is_subcommand: is_subcommand,
    subcommands: subcommands
  
  if command
    if self.class.subcommands.include? command
      if subcommands.empty?
        # Get help on a subcommand *class*
        self.class.subcommand_classes[command].help(shell, true)
      else
        # Atli addition - handle things like `myexe help sub cmd`
        # Want help on something (class or command) further down the line
        invoke  self.class.subcommand_classes[command],
                ['help', *subcommands],
                {},
                {:invoked_via_subcommand => true, :class_options => options}
      end
    else
      # Want help on a *command* of this class
      # 
      # Atli -  Now that we've modified {.command_help} to accept
      #         `subcommand`, pass it (it seems to have already been getting
      #         the correct value to here).
      self.class.command_help(shell, command, is_subcommand)
    end
  else
    # We want help on *this class itself* (list available commands)
    self.class.help(shell, is_subcommand)
  end
end