abpframework/abp · warning · ArgumentException

Option names should start with '-' or '--'.

Error message

Option names should start with '-' or '--'.

What it means

Thrown by CommandLineArgumentParser.ParseOptionName when the argument does not start with '-' or '--' at all. ParseOptionName is only meant to run on tokens already identified as options; reaching its final throw means a positional/value token was fed where an option name was expected. In practice this indicates a parser state mismatch (an unexpected non-option token in the options section).

Source

Thrown at framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/CommandLineArgumentParser.cs:107

            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)
            {
                currentArg = currentArgBuilder.ToString();
                if (!currentArg.IsNullOrWhiteSpace())
                {
                    args.Add(currentArg);
                }

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Check the command syntax: only option flags (starting with - or --) are valid after the target; move positional values to the correct position or quote them as an option value.
  2. Re-run with 'abp help <command>' to confirm the expected argument layout.
  3. If invoking programmatically, ensure value tokens are paired with their option flag rather than passed bare.
  4. Quote values containing special characters so the tokenizer does not split them into stray tokens.

Example fix

# before: trailing positional token read as an option name
abp new MyProject extra --version
# after: keep only valid options after the target
abp new MyProject --version
Defensive patterns

Strategy: validation

Validate before calling

// Confirm every token after the target is an option before parsing.
var tokens = parser.Parse /* internal */; // (illustrative)
// In practice: validate command shape via 'abp help <command>' before scripting.
if (args.Any(a => !a.StartsWith("-") && /* positional after target */ false))
{
    Console.Error.WriteLine("Unexpected positional argument; only options are allowed after the target.");
}

Type guard

public static bool IsOptionToken(string arg) =>
    arg.StartsWith("-") || arg.StartsWith("--");

Try / catch

try
{
    var cmd = parser.Parse(args);
}
catch (ArgumentException ex) when (ex.Message.Contains("start with '-' or '--'", StringComparison.Ordinal))
{
    Console.Error.WriteLine($"Invalid CLI input: a token was not a valid option. Args: {string.Join(' ', args)}");
    return ExitCodes.InvalidArguments;
}

Prevention

When it happens

Trigger: The options-parsing while-loop in Parse calls ParseOptionName on a token that does not begin with '-'. This can happen when a value was not consumed as the previous option's argument, leaving a bare positional token to be misread as an option name.

Common situations: Passing extra positional arguments after the command/target where the parser expects options; a command that takes no options but receives trailing tokens; malformed generated commands; version differences in how a command's arguments are shaped.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/a39b63ea2a3633c1. Report an issue: GitHub.