diff --git a/spin/cmds/util.py b/spin/cmds/util.py index e0ca361..f79dae3 100644 --- a/spin/cmds/util.py +++ b/spin/cmds/util.py @@ -170,9 +170,15 @@ def parent_cmd(*user_args, **user_kwargs): my_cmd.callback = click.pass_context(callback_with_parent_callback) my_cmd.callback._parent = user_func # type: ignore[attr-defined] + # If doc is present then combine it with user_func.__doc__ + # Otherwise override it with user_func.__doc__ + # if it is not empty. if doc is not None: - my_cmd.help = doc - my_cmd.help = (my_cmd.help or "") + "\n\n" + (user_func.__doc__ or "") + my_cmd.help = doc + "\n\n" + (user_func.__doc__ or "") + else: + my_cmd.help = (my_cmd.help or "") + if user_func.__doc__ is not None: + my_cmd.help = user_func.__doc__ my_cmd.help = my_cmd.help.strip() my_cmd.name = user_func.__name__.replace("_", "-") diff --git a/spin/tests/test_extend_command.py b/spin/tests/test_extend_command.py index 9677e9f..547e8c8 100644 --- a/spin/tests/test_extend_command.py +++ b/spin/tests/test_extend_command.py @@ -28,6 +28,7 @@ def build_ext(*, parent_callback, extra=None, **kwargs): assert "Additional docstring" in get_usage(build_ext) assert "Additional docstring" not in get_usage(cmds.meson.build) + assert get_usage(cmds.meson.build) not in get_usage(build_ext) @extend_command(cmds.meson.build, doc="Hello world") def build_ext(*, parent_callback, extra=None, **kwargs): @@ -39,6 +40,7 @@ def build_ext(*, parent_callback, extra=None, **kwargs): doc = get_usage(build_ext) assert "Hello world\n" in doc assert "\n Additional docstring" in doc + assert get_usage(cmds.meson.build) not in get_usage(build_ext) def test_ext_additional_args():