Skip to content

opencode auth --foo prints help text twice #149

Description

@louis-brunet

When the auth command is incorrectly used without a subcommand and with an invalid option, there are two errors shown, each with its own help text.
This is not a big issue but I assume the desired behavior is to only print one help text in this case.
This only happens with the auth command, probably because it is the only command that requires a subcommand.

 ❯ opencode auth --foo --bar
opencode auth

manage credentials

Commands:
  opencode auth login   login to a provider
  opencode auth logout  logout from a configured provider
  opencode auth list    list providers                             [aliases: ls]

Options:
  --help        Show help                                              [boolean]
  --version     Show version number                                    [boolean]
  --print-logs  Print logs to stderr                                   [boolean]
2025-06-16T18:12:55 +45ms service=default Not enough non-option arguments: got 0, need at least 1
opencode auth

manage credentials

Commands:
  opencode auth login   login to a provider
  opencode auth logout  logout from a configured provider
  opencode auth list    list providers                             [aliases: ls]

Options:
  --help        Show help                                              [boolean]
  --version     Show version number                                    [boolean]
  --print-logs  Print logs to stderr                                   [boolean]
2025-06-16T18:12:55 +4ms service=default Unknown arguments: foo, bar

I believe this can be fixed by exiting the program in the yargs fail() function, as shown in the yargs documentation's example.

  .fail((msg, err) => {
    if (
      msg.startsWith("Unknown argument") ||
      msg.startsWith("Not enough non-option arguments")
    ) {
      cli.showHelp("log")
    }
    Log.Default.error(msg, {
      err,
    })
    process.exit(1) // <-- add this line?
  })

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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