chocolatey/choco · error · ApplicationException
A single apikey command must be listed. Please see the help
Error message
A single apikey command must be listed. Please see the help menu for those commands.
What it means
The apikey command accepts at most one positional subcommand token (list/add/remove). ParseAdditionalArguments throws when unparsedArguments.Count > 1, because more than one leftover positional argument means the user supplied multiple subcommand-like tokens. It directs the user to the help menu to see the valid single commands.
Source
Thrown at src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs:62
configuration.Sources = null;
optionSet
.Add("s=|source=",
"Source [REQUIRED] - The source location for the key",
option => configuration.Sources = option.UnquoteSafe())
.Add("k=|key=|apikey=|api-key=",
"ApiKey - The API key for the source. This is the authentication that identifies you and allows you to push to a source. With some sources this is either a key or it could be a user name and password specified as 'user:password'.",
option => configuration.ApiKeyCommand.Key = option.UnquoteSafe())
;
}
public virtual void ParseAdditionalArguments(IList<string> unparsedArguments, ChocolateyConfiguration configuration)
{
configuration.Input = string.Join(" ", unparsedArguments);
if (unparsedArguments.Count > 1)
{
throw new ApplicationException("A single apikey command must be listed. Please see the help menu for those commands.");
}
var command = ApiKeyCommandType.Unknown;
var unparsedCommand = unparsedArguments.DefaultIfEmpty(string.Empty).FirstOrDefault();
if (!Enum.TryParse(unparsedCommand, true, out command) || command == ApiKeyCommandType.Unknown)
{
command = ApiKeyCommandType.List;
if (!string.IsNullOrWhiteSpace(unparsedCommand))
{
this.Log().Warn("Unknown command {0}. Setting to list.".FormatWith(unparsedCommand));
}
else if (!string.IsNullOrWhiteSpace(configuration.ApiKeyCommand.Key))
{
this.Log().Warn("API key provided. Setting command to add.");
command = ApiKeyCommandType.Add;
}
View on GitHub (pinned to 0d5abdd10c)
Solutions
- Pass a single apikey subcommand (list, add, or remove) and use flags for source/key.
- Use the explicit form: 'choco apikey add -s <source> -k <key>'.
- Run 'choco apikey -?' to confirm accepted subcommands.
Example fix
# before choco apikey add remove -s https://feed -k abc # after choco apikey add -s https://feed -k abc
Defensive patterns
Strategy: validation
Validate before calling
// Build apikey args with at most one positional subcommand.
var verbs = new[] { "list", "add", "remove" };
var positional = tokens.Where(t => !t.StartsWith("-")).ToList();
if (positional.Count(t => verbs.Contains(t, StringComparer.OrdinalIgnoreCase)) > 1)
{
throw new ArgumentException("apikey accepts a single subcommand.");
} Prevention
- Always use the explicit 'choco apikey <verb> -s ... -k ...' form with flags.
- Count positional tokens before invoking choco in scripts.
- Consult 'choco apikey -?' when unsure of accepted subcommands.
When it happens
Trigger: Running 'choco apikey add remove', 'choco apikey list extra', or any invocation where more than one unflagged positional token remains after option parsing.
Common situations: Copying examples that concatenate subcommands; scripting that appends a source as a positional argument instead of -s; misunderstanding that apikey takes exactly one verb.
Related errors
- A single config command must be listed. Please see the help
- A single feature command must be listed. Please see the help
- A single license command must be listed. Please see the help
- You must specify 'source' to remove an API key.
- You must specify both 'source' and 'key' to set an API key.
AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13).
Data as JSON: /api/errors/8ab37cf5ea4df1e9.
Report an issue: GitHub.