Skip to content

[MessageOutput] fails to integrate with HelpCommand #90

@indraneel12

Description

@indraneel12

Premise

Based on the current documentation, it is expected that MessageOutput redirects all command logs when passed to BetterCommandRunner:

  • A proxy for user-provided functions for passing specific log messages.

  • [...] adds additional functionality such as logging, [...]

Problem

For any program mock based on BetterCommandRunner with a custom MessageOutput, run:

mock help help

or

mock help -h

It is a valid command, as it seeks usage information about the help command of the mock program. The command log in this case, unfortunately, does not pass through MessageOutput.

Cause

As per my assessment, I believe this problem is caused by the following design:

  1. MessageOutput is injected through only BetterCommand

  2. BetterCommand is a child of upstream Command

  3. The private HelpCommand is a child of Command but not BetterCommand

  4. BetterCommandRunner indirectly adds HelpCommand via its super-call

Essentially, in this inheritance schema, BetterCommand is a sibling of HelpCommand and not a parent. It fails to meet the goal of printUsage.

Suggestion

I reckon this design bug could be patched by passing the buck to the upstream package for their private implementation of HelpCommand, or, by making their CommandRunner an even better BetterCommandRunner by choosing implements over extends such that it not only satisfies all design contracts but also provides the ability to customize the constructor to add a proper HelpCommand that inherits from BetterCommand.

Aside, there is another limitation with both BetterCommandRunner and the upstream CommandRunner constructor that it fails to allow the customization of its argParser similar to an issue mentioned earlier.

Hopefully, all such issues can be fixed without relying on upstream support through this approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions