{"record":{"id":"bc87f1ca79d7c1c0","repo":"abpframework/abp","slug":"should-specify-an-option-name-after-prefix-bc87f1","errorCode":null,"errorMessage":"Should specify an option name after '-' prefix!","messagePattern":"Should specify an option name after '-' prefix!","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/CommandLineArgumentParser.cs","lineNumber":101,"sourceCode":"    }\n\n    private static string ParseOptionName(string argument)\n    {\n        if (argument.StartsWith(\"--\"))\n        {\n            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)","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Args/CommandLineArgumentParser.cs#L83-L119","documentation":"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.","triggerScenarios":"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.","commonSituations":"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 '-'.","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."],"exampleFix":"# before\nabp get-source Volo.Account -\n# after (remove the lone hyphen or supply the intended option)\nabp get-source Volo.Account -v","handlingStrategy":"validation","validationCode":"// Drop lone '-' tokens before parsing.\nvar sanitized = args.Where(a => a != \"-\").ToArray();\nvar parsed = parser.Parse(sanitized);","typeGuard":"public static bool IsValidOptionToken(string arg) =>\n    !(arg.StartsWith(\"-\") && !arg.StartsWith(\"--\") && arg.Length <= 1);","tryCatchPattern":"try\n{\n    var cmd = parser.Parse(args);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"'-' prefix\", StringComparison.Ordinal))\n{\n    Console.Error.WriteLine($\"Invalid CLI input: a bare '-' is not allowed. Args: {string.Join(' ', args)}\");\n    return ExitCodes.InvalidArguments;\n}","preventionTips":["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."],"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"}