@@ -178,9 +178,10 @@ def command(
178178 callback. This will also automatically attach all decorated
179179 :func:`option`\s and :func:`argument`\s as parameters to the command.
180180
181- The name of the command defaults to the name of the function with
182- underscores replaced by dashes. If you want to change that, you can
183- pass the intended name as the first argument.
181+ The name of the command defaults to the name of the function, converted to
182+ lowercase, with underscores ``_`` replaced by dashes ``-``, and the suffixes
183+ ``_command``, ``_cmd``, ``_group``, and ``_grp`` are removed. For example,
184+ ``init_data_command`` becomes ``init-data``.
184185
185186 All keyword arguments are forwarded to the underlying command class.
186187 For the ``params`` argument, any decorated params are appended to
@@ -190,10 +191,13 @@ def command(
190191 that can be invoked as a command line utility or be attached to a
191192 command :class:`Group`.
192193
193- :param name: the name of the command. This defaults to the function
194- name with underscores replaced by dashes.
195- :param cls: the command class to instantiate. This defaults to
196- :class:`Command`.
194+ :param name: The name of the command. Defaults to modifying the function's
195+ name as described above.
196+ :param cls: The command class to create. Defaults to :class:`Command`.
197+
198+ .. versionchanged:: 8.2
199+ The suffixes ``_command``, ``_cmd``, ``_group``, and ``_grp`` are
200+ removed when generating the name.
197201
198202 .. versionchanged:: 8.1
199203 This decorator can be applied without parentheses.
@@ -236,12 +240,16 @@ def decorator(f: _AnyCallable) -> CmdType:
236240 assert cls is not None
237241 assert not callable (name )
238242
239- cmd = cls (
240- name = name or f .__name__ .lower ().replace ("_" , "-" ),
241- callback = f ,
242- params = params ,
243- ** attrs ,
244- )
243+ if name is not None :
244+ cmd_name = name
245+ else :
246+ cmd_name = f .__name__ .lower ().replace ("_" , "-" )
247+ cmd_left , sep , suffix = cmd_name .rpartition ("-" )
248+
249+ if sep and suffix in {"command" , "cmd" , "group" , "grp" }:
250+ cmd_name = cmd_left
251+
252+ cmd = cls (name = cmd_name , callback = f , params = params , ** attrs )
245253 cmd .__doc__ = f .__doc__
246254 return cmd
247255
0 commit comments