hashicorp/vagrant · error · Vagrant::Errors::CLIInvalidUsage

This command was not invoked properly. The help for this com

Error message

This command was not invoked properly. The help for this command is
available below.

%{help}

What it means

Vagrant raises Vagrant::Errors::CLIInvalidUsage when `vagrant cloud auth whoami` receives more than one positional argument. The command accepts either zero arguments (it then reads the token stored by `vagrant cloud auth login`) or exactly one argument (an explicit access token). Any other count is a usage error, and the message re-prints the command's OptionParser help so the correct invocation is visible.

Source

Thrown at plugins/commands/cloud/auth/whoami.rb:26

    module AuthCommand
      module Command
        class Whoami < Vagrant.plugin("2", :command)
          include Util

          def execute
            options = {}

            opts = OptionParser.new do |o|
              o.banner = "Usage: vagrant cloud auth whoami [token]"
              o.separator ""
              o.separator "Display currently logged in user"
            end

            # Parse the options
            argv = parse_options(opts)
            return if !argv
            if argv.size > 1
              raise Vagrant::Errors::CLIInvalidUsage,
                help: opts.help.chomp
            end

            if argv.first
              token = argv.first
            else
              client = Client.new(@env)
              token = client.token
            end

            whoami(token)
          end

          def whoami(access_token)
            if access_token.to_s.empty?
              @env.ui.error(I18n.t("cloud_command.check_not_logged_in"))
              return 1
            end

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Run `vagrant cloud auth whoami` with no arguments to use the stored token, or with exactly one token argument
  2. Quote the token so it cannot split: `vagrant cloud auth whoami "$VAGRANT_CLOUD_TOKEN"`
  3. Run `vagrant cloud auth whoami -h` to confirm the exact usage banner

Example fix

# before
vagrant cloud auth whoami mytoken extra-arg
# after
vagrant cloud auth whoami mytoken
# or use the token stored by `vagrant cloud auth login`
vagrant cloud auth whoami
Defensive patterns

Strategy: validation

Validate before calling

# bash: enforce the 0-or-1 argument contract before invoking vagrant
if [ "$#" -gt 1 ]; then
  echo "usage: vagrant cloud auth whoami [token]" >&2
  exit 64
fi
exec vagrant cloud auth whoami "$@"

Type guard

# Ruby: Vagrant signals usage problems by error class — narrow before handling
def cli_usage_error?(e)
  e.is_a?(Vagrant::Errors::CLIInvalidUsage)
end

Try / catch

begin
  env.cli(%w[cloud auth whoami], *args)
rescue Vagrant::Errors::CLIInvalidUsage => e
  # e.message already embeds the full help; log only the banner line
  $stderr.puts e.message.lines.first
  exit 64
end

Prevention

When it happens

Trigger: Running `vagrant cloud auth whoami <token> <extra-arg>`, or any invocation where argv.size > 1 after option parsing. An unquoted shell variable containing whitespace splits into multiple argv entries and triggers it.

Common situations: Copy-pasting a command written for a different CLI that expects username plus token; shell scripts that append arguments unconditionally; passing an unquoted $TOKEN that expands to more than one word.

Related errors


AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21). Data as JSON: /api/errors/a76d2e4ec7dcd738. Report an issue: GitHub.