abpframework/abp · warning · ArgumentException
Should specify an option name after '-' prefix!
Error message
Should specify an option name after '-' prefix!
What it means
Thrown by CommandLineArgumentParser.ParseOptionName when an argument equals exactly '-' (length <= 1). A lone hyphen is not a valid option name; the parser requires at least one character after the '-' prefix. This mirrors the '--' guard for single-dash short options.
Source
Thrown at framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/CommandLineArgumentParser.cs:101
}
private static string ParseOptionName(string argument)
{
if (argument.StartsWith("--"))
{
if (argument.Length <= 2)
{
throw new ArgumentException("Should specify an option name after '--' prefix!");
}
return argument.RemovePreFix("--");
}
if (argument.StartsWith("-"))
{
if (argument.Length <= 1)
{
throw new ArgumentException("Should specify an option name after '-' prefix!");
}
return argument.RemovePreFix("-");
}
throw new ArgumentException("Option names should start with '-' or '--'.");
}
private static string[] GetArgsArrayFromLine(string lineText)
{
var args = new List<string>();
var currentArgBuilder = new StringBuilder();
string currentArg = null;
bool isInQuotes = false;
for (int i = 0; i < lineText.Length; i++)
{
var c = lineText[i];
if (c == ' ' && !isInQuotes)View on GitHub (pinned to 7ed43b1931)
Solutions
- Remove or correct the lone '-' token; supply the intended short option (e.g., '-v', '-h').
- If '-' was meant as a filename/stdin marker, note the ABP CLI does not support that convention; pass an explicit path or value instead.
- Sanitize programmatically built argument lists to drop empty or hyphen-only tokens before invoking the CLI.
- Re-run the command with the corrected flag and verify no env var collapsed to '-' again.
Example fix
# before abp get-source Volo.Account - # after (remove the lone hyphen or supply the intended option) abp get-source Volo.Account -v
Defensive patterns
Strategy: validation
Validate before calling
// Drop lone '-' tokens before parsing. var sanitized = args.Where(a => a != "-").ToArray(); var parsed = parser.Parse(sanitized);
Type guard
public static bool IsValidOptionToken(string arg) =>
!(arg.StartsWith("-") && !arg.StartsWith("--") && arg.Length <= 1); Try / catch
try
{
var cmd = parser.Parse(args);
}
catch (ArgumentException ex) when (ex.Message.Contains("'-' prefix", StringComparison.Ordinal))
{
Console.Error.WriteLine($"Invalid CLI input: a bare '-' is not allowed. Args: {string.Join(' ', args)}");
return ExitCodes.InvalidArguments;
} Prevention
- Never use a lone '-' as a flag; supply a real short option (e.g., '-v').
- Sanitize programmatically built argument lists to remove hyphen-only tokens.
- Verify shell variable expansion does not collapse a flag to '-'.
- Quote values containing special characters.
When it happens
Trigger: The CLI receives a standalone '-' token, e.g., piping '-' as a flag or a shell artifact that collapses to a single hyphen. The options loop passes it to ParseOptionName which rejects it.
Common situations: Shell redirection misuse ('abp cmd -' intended as stdin); a variable that expanded to empty leaving a bare '-'; CI scripts concatenating flags where one variable was unset; typo of a short flag like intending '-v' but typing '-'.
Related errors
- Should specify an option name after '--' prefix!
- Option names should start with '-' or '--'.
- There is no template found with given name: {name}
- "public class" declaration not found!
- ERROR: Remote server returns '{response.StatusCode}'
AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13).
Data as JSON: /api/errors/bc87f1ca79d7c1c0.
Report an issue: GitHub.