Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/VirtualClient/VirtualClient.Main/CommandLineExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ public static void ThrowOnUsageError(this ParseResult parseResults)
}

// Scenario 3:
// There are no options on the command line that are not valid for the command.
// There are options on the command line that are not valid for the command.
// Use a full-string match (anchored regex) to avoid false positives from
// values bound to recognized options that contain double-dash prefixed
// substrings (e.g. --parameters="...DriverInstallationCommandArguments=--silent...").
IEnumerable<Token> arguments = parseResults.Tokens.Where(t => t.Type == TokenType.Argument);
if (arguments?.Any() == true)
{
Regex optionMatchExpression = new Regex("--[a-z]+", RegexOptions.IgnoreCase);
Regex optionMatchExpression = new Regex(@"^--[a-z][-a-z]*$", RegexOptions.IgnoreCase);
foreach (Token argument in arguments)
{
if (optionMatchExpression.IsMatch(argument.Value?.Trim()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public void VirtualClientThrowsWhenAnUnrecognizedOptionIsSuppliedOnTheCommandLin
[TestCase("--ps", "https://anystorageaccount.blob.core.windows.net/?sv=2020-08-04&ss=b")]
[TestCase("--parameters", "Param1=Value1,,,Param2=Value2")]
[TestCase("--pm", "Param1=Value1,,,Param2=Value2")]
[TestCase("--parameters", "DriverInstallationCommandArguments=--silent,,,UserName=HpcUser,,,DriverBlobName=nvidiagriddriver-v20.0.zip")]
[TestCase("--seed", "1234")]
[TestCase("--sd", "1234")]
[TestCase("--scenarios", "Scenario1")]
Expand Down