Skip to content

hideCommandSummaryInDescription removes description when missing a line feed #1243

@daymxn

Description

@daymxn

Describe the bug
When using the hideCommandSummaryInDescription option of HelpOptions, if the command description doesn't start with a line feed, then the description is lost in the output.

To Reproduce

import { Command, CommandHelp } from "@oclif/core";

export class CoolCommand extends Command {
  static override description = "Cool description.";

  static override summary = "Cool summary";

  async run() {
    const command = this.config.findCommand(this.id!);

    const help = new CommandHelp(command!, this.config, {
      hideCommandSummaryInDescription: true,
      maxWidth: 120,
    });

    console.log(help.generate());
  }
}

Expected behavior

USAGE
  $ my-cli cool

DESCRIPTION
  Cool description.

Actual behavior

USAGE
  $ my-cli cool

Environment:

  • OS & version: Windows 10
  • Shell/terminal & version: Windows Terminal w/ powershell

Additional context
The problem comes from this line.

The usage of slice here is dropping the description if it doesn't start with a newline character.

I believe this behavior is here to support situations like this:

export class CoolCommand extends Command {
  static override description = `
Cool description.`;
}

Although, I'd argue that's an end-user problem. One that's easily fixed with trim:

export class CoolCommand extends Command {
  static override description = `
Cool description.`.trim();
}

Alternatively, oclif could call trim instead of slice, but that's making assumptions about end-user's descriptions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions