@@ -671,4 +671,37 @@ def help(command = nil, subcommand = false)
671671 self . class . help ( shell , subcommand )
672672 end
673673 end
674+
675+ map TREE_MAPPINGS => :tree
676+
677+ desc "tree" , "Print a tree of all available commands"
678+ def tree
679+ build_command_tree ( self . class , "" )
680+ end
681+
682+ private
683+
684+ def build_command_tree ( klass , indent )
685+ # Print current class name if it's not the root Thor class
686+ unless klass == Thor
687+ say "#{ indent } #{ klass . namespace || 'default' } " , :blue
688+ indent = "#{ indent } "
689+ end
690+
691+ # Print all commands for this class
692+ visible_commands = klass . commands . reject { |_ , cmd | cmd . hidden? || cmd . name == "help" }
693+ commands_count = visible_commands . count
694+ visible_commands . sort . each_with_index do |( command_name , command ) , i |
695+ description = command . description . split ( "\n " ) . first || ""
696+ icon = i == ( commands_count - 1 ) ? "└─" : "├─"
697+ say "#{ indent } #{ icon } " , nil , false
698+ say command_name , :green , false
699+ say " (#{ description } )" unless description . empty?
700+ end
701+
702+ # Print all subcommands (from registered Thor subclasses)
703+ klass . subcommand_classes . each do |_ , subclass |
704+ build_command_tree ( subclass , indent )
705+ end
706+ end
674707end
0 commit comments