Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ export function cli(pkg: any) {
});

// If this is a help command, load all commands so we can display them.
const isHelp = !args.length || args[0] === "help" || (args.length === 1 && args[0] === "ext");
const commandName = args[0];
const isHelp =
!args.length ||
commandName === "help" ||
(args.length === 1 && commandName === "ext") ||
commandName === "--help";
const hasHelpFlag = args.includes("--help") || args.includes("-h");

Comment on lines +113 to +119
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This implementation has a couple of issues:

  1. It doesn't correctly handle firebase --help. This should be treated as a general help command, which requires loading all commands to display them. The current logic fails to do so.
  2. The client.getCommand(commandName) call is made even when commandName is an option (e.g., --help), which is not ideal.

I've refactored the logic to address both points. It now correctly identifies firebase --help as a help command and avoids calling getCommand with an option.

  const hasHelpFlag = args.includes("--help") || args.includes("-h");
  const isHelp =
    !args.length ||
    commandName === "help" ||
    (args.length === 1 && commandName === "ext") ||
    (args.length === 1 && hasHelpFlag);

  if (hasHelpFlag && commandName && !commandName.startsWith("-")) {
    client.getCommand(commandName);
  }
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, as shown by the testing above.

if (hasHelpFlag) {
client.getCommand(commandName);
}

if (isHelp) {
const seen = new Set();
const loadAll = (obj: any) => {
Expand Down
Loading