Skip to content

auth switch: --profile duplicates the positional <NAME>, and --help / error usage strings disagree #663

Description

@slabgorb

Summary

Two related problems on auth switch:

  1. It takes a positional <NAME>, but the global --profile flag is also accepted — those
    mean nearly the same thing, and the invocation that finally works passes the same profile
    name twice.
  2. --help and the error-path usage strings don't agree. The same command reports three
    different signatures depending on how you invoke it, so there's no single authoritative
    answer to "what is the correct syntax?"

What happened

Trying to make develop-okta the active profile:

$ jr-a auth switch --profile develop-okta
error: the following required arguments were not provided:
  <NAME>

Usage: jr-a auth switch --profile <PROFILE> <NAME>

That usage line reads as though --profile <PROFILE> is a required part of switch. So the
obvious next guess is that the name is also a flag:

$ jr-a auth switch --profile develop-okta --name develop-okta
error: unexpected argument '--name' found

  tip: to pass '--name' as a value, use '-- --name'

Usage: jr-a auth switch --profile <PROFILE> <NAME>

Still the same usage line. Eventually this worked:

$ jr-a auth switch --profile "develop-okta" "develop-okta"
Active profile set to "develop-okta"

…which is the same value supplied twice. Meanwhile the bare form was correct all along:

$ jr-a auth switch
error: the following required arguments were not provided:
  <NAME>

Usage: jr-a auth switch <NAME>

The usage strings and --help disagree

This is the part that made the above unsolvable by reading. The same subcommand advertises
three different signatures:

Source Reported usage
jr-a auth switch --help jr-a auth switch [OPTIONS] <NAME>
error, bare jr-a auth switch jr-a auth switch <NAME>
error, jr-a auth switch --profile develop-okta jr-a auth switch --profile <PROFILE> <NAME>

--help is the canonical form ([OPTIONS] <NAME>), but neither error path prints it. The
first error drops [OPTIONS] entirely — implying switch takes no flags at all. The second
promotes --profile out of [OPTIONS] into a required-looking position. So depending on
which one you happen to see, you conclude either "no options are accepted" or "--profile is
mandatory," and both conclusions are wrong.

Consistently echoing the --help signature on error paths would have made this a non-issue.

Why it's confusing

--profile is documented globally as:

--profile <PROFILE>  Override the active profile (precedence: this flag > JR_PROFILE > config > "default")

and auth switch is documented as:

Set the default profile in config.toml

Arguments:
  <NAME>  Profile name to make active. Must already exist in config

For every other subcommand, --profile selecting the profile to act as makes sense. For
auth switch, whose entire purpose is to set the active profile, "override the active
profile" is at best a no-op and at worst reads as the argument you're supposed to use. Two
different ways to name a profile in one command, one of which is silently ignored.

Suggested fix

For the duplicated flag, any of these removes the ambiguity:

  1. Hide or reject the global --profile on auth switch (clap hide = true, or a
    conflicts_with so it errors with "use the positional NAME instead").
  2. Accept --profile as an alias for the positional, so both forms do the same thing.
  3. Keep it, but make the error explicit — e.g. "auth switch sets the profile via a
    positional NAME; --profile has no effect here."

Option 1 seems cleanest, since --profile genuinely has no meaning for this subcommand.

For the usage/help mismatch: print the same signature everywhere, matching --help. If the
error usage is being derived from the parsed-so-far argument state rather than from the
command definition, that's the thing to fix — a usage string that changes based on what the
user just typed can't be used to learn the correct syntax.

Version

jr 0.6.0-dev.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions