@@ -141,50 +141,65 @@ def list_commands(self, ctx: Context) -> list[str]:
141141 return super ().list_commands (ctx )
142142
143143 def format_commands (self , ctx : Context , formatter : Any ) -> None :
144- """Format commands with separate sections for shortcuts and regular commands."""
144+ """Format commands with separate sections for common, core, and package commands."""
145145 self ._ensure_registry_loaded ()
146146
147- # Get all commands from both sources
147+ # Get all commands from both sources, tracking their source
148148 commands = []
149- for source in self .sources :
149+ for source_index , source in enumerate ( self .sources ) :
150150 for name in source .list_commands (ctx ):
151151 cmd = source .get_command (ctx , name )
152152 if cmd is not None :
153- commands .append ((name , cmd ))
153+ # source_index 0 = plain_cli (core), 1+ = registry (packages)
154+ commands .append ((name , cmd , source_index ))
154155
155156 if not commands :
156157 return
157158
158- # Get metadata about shortcuts from the registry
159+ # Get metadata from the registry (for shortcuts)
159160 shortcuts_metadata = cli_registry .get_shortcuts ()
160161
161- # Separate shortcuts from regular commands
162- shortcuts = []
163- regular_commands = []
164-
165- for name , cmd in commands :
166- if name in shortcuts_metadata :
167- # This is a shortcut
168- help_text = cmd .get_short_help_str (limit = 200 )
169- shortcut_for = shortcuts_metadata [name ].shortcut_for
170- if shortcut_for :
171- # Add italic styling to the alias information (more concise)
172- alias_info = click .style (f"(→ { shortcut_for } )" , italic = True )
173- help_text = f"{ help_text } { alias_info } "
174- shortcuts .append ((name , help_text ))
162+ # Separate commands into common, core, and package
163+ common_commands = []
164+ core_commands = []
165+ package_commands = []
166+
167+ for name , cmd , source_index in commands :
168+ help_text = cmd .get_short_help_str (limit = 200 )
169+
170+ # Check if command is marked as common via decorator
171+ is_common = getattr (cmd , "is_common_command" , False )
172+
173+ if is_common :
174+ # This is a common command
175+ # Add arrow notation if it's also a shortcut
176+ if name in shortcuts_metadata :
177+ shortcut_for = shortcuts_metadata [name ].shortcut_for
178+ if shortcut_for :
179+ alias_info = click .style (f"(→ { shortcut_for } )" , italic = True )
180+ help_text = f"{ help_text } { alias_info } "
181+ common_commands .append ((name , help_text ))
182+ elif source_index == 0 :
183+ # Package command (from registry, inserted at index 0)
184+ package_commands .append ((name , help_text ))
175185 else :
176- # Regular command or group
177- regular_commands .append ((name , cmd .get_short_help_str (limit = 200 )))
178-
179- # Write shortcuts section if any exist
180- if shortcuts :
181- with formatter .section ("Shortcuts" ):
182- formatter .write_dl (sorted (shortcuts ))
183-
184- # Write regular commands section
185- if regular_commands :
186- with formatter .section ("Commands" ):
187- formatter .write_dl (sorted (regular_commands ))
186+ # Core command (from plain_cli, at index 1)
187+ core_commands .append ((name , help_text ))
188+
189+ # Write common commands section if any exist
190+ if common_commands :
191+ with formatter .section ("Common Commands" ):
192+ formatter .write_dl (sorted (common_commands ))
193+
194+ # Write core commands section if any exist
195+ if core_commands :
196+ with formatter .section ("Core Commands" ):
197+ formatter .write_dl (sorted (core_commands ))
198+
199+ # Write package commands section if any exist
200+ if package_commands :
201+ with formatter .section ("Package Commands" ):
202+ formatter .write_dl (sorted (package_commands ))
188203
189204
190205cli = PlainCommandCollection ()
0 commit comments