{"record":{"id":"a39b63ea2a3633c1","repo":"abpframework/abp","slug":"option-names-should-start-with-or","errorCode":null,"errorMessage":"Option names should start with '-' or '--'.","messagePattern":"Option names should start with '-' or '--'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/CommandLineArgumentParser.cs","lineNumber":107,"sourceCode":"            if (argument.Length <= 2)\n            {\n                throw new ArgumentException(\"Should specify an option name after '--' prefix!\");\n            }\n\n            return argument.RemovePreFix(\"--\");\n        }\n\n        if (argument.StartsWith(\"-\"))\n        {\n            if (argument.Length <= 1)\n            {\n                throw new ArgumentException(\"Should specify an option name after '-' prefix!\");\n            }\n\n            return argument.RemovePreFix(\"-\");\n        }\n\n        throw new ArgumentException(\"Option names should start with '-' or '--'.\");\n    }\n\n    private static string[] GetArgsArrayFromLine(string lineText)\n    {\n        var args = new List<string>();\n        var currentArgBuilder = new StringBuilder();\n        string currentArg = null;\n        bool isInQuotes = false;\n        for (int i = 0; i < lineText.Length; i++)\n        {\n            var c = lineText[i];\n            if (c == ' ' && !isInQuotes)\n            {\n                currentArg = currentArgBuilder.ToString();\n                if (!currentArg.IsNullOrWhiteSpace())\n                {\n                    args.Add(currentArg);\n                }","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/CommandLineArgumentParser.cs#L89-L125","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Re-run with 'abp help <command>' to confirm the expected argument layout.","If invoking programmatically, ensure value tokens are paired with their option flag rather than passed bare.","Quote values containing special characters so the tokenizer does not split them into stray tokens."],"exampleFix":"# before: trailing positional token read as an option name\nabp new MyProject extra --version\n# after: keep only valid options after the target\nabp new MyProject --version","handlingStrategy":"validation","validationCode":"// Confirm every token after the target is an option before parsing.\nvar tokens = parser.Parse /* internal */; // (illustrative)\n// In practice: validate command shape via 'abp help <command>' before scripting.\nif (args.Any(a => !a.StartsWith(\"-\") && /* positional after target */ false))\n{\n    Console.Error.WriteLine(\"Unexpected positional argument; only options are allowed after the target.\");\n}","typeGuard":"public static bool IsOptionToken(string arg) =>\n    arg.StartsWith(\"-\") || arg.StartsWith(\"--\");","tryCatchPattern":"try\n{\n    var cmd = parser.Parse(args);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"start with '-' or '--'\", StringComparison.Ordinal))\n{\n    Console.Error.WriteLine($\"Invalid CLI input: a token was not a valid option. Args: {string.Join(' ', args)}\");\n    return ExitCodes.InvalidArguments;\n}","preventionTips":["Consult 'abp help <command>' to learn the exact argument layout before scripting.","Keep only option flags after the target; pass values as option arguments.","Quote positional values so the tokenizer does not split them into stray tokens.","Validate generated command strings in tests before shelling out."],"tags":["cli","args","parsing","user-input"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}