Skip to content

Commit

Permalink
feat: Add HasArgument method to PreviewProcessArguments for argument …
Browse files Browse the repository at this point in the history
…presence checking
  • Loading branch information
github-actions[bot] committed Dec 2, 2024
1 parent aa03101 commit c159f08
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions AzureLiquid.Preview/PreviewProcessArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PreviewProcessArguments
/// <summary>
/// Gets the index of the argument, if it exists.
/// </summary>
/// <param name="args">The arguments.</param>
/// <param name="key">The key.</param>
/// <returns>The index of the argument.</returns>
private static int GetArgumentIndex(string[] args, string key)
Expand Down Expand Up @@ -46,6 +47,14 @@ private static bool IsArgMatch(string arg, string key)
return string.CompareOrdinal(arg, "--" + key) == 0;
}

/// <summary>
/// Gets a value indicating whether the specific argument key was found in the arguments.
/// </summary>
/// <param name="args">The passed arguments.</param>
/// <param name="key">The key.</param>
/// <returns><c>true</c> if the argument was found, otherwise <c>false</c>,</returns>
public static bool HasArgument(string[] args, string key) => args.Any(arg => IsArgMatch(arg, key));

/// <summary>
/// Parses the argument value.
/// </summary>
Expand All @@ -56,8 +65,8 @@ public string ParsePath(string[] args, string key)
{
var index = GetArgumentIndex(args, key);
return
index == -1 || index - 1 >= args?.Length || args == null ? string.Empty : // No match, or no arguments passed
Path.GetFullPath(args[index + 1], _path) // Argument found, parsing path
?? string.Empty; // Argument found, but path is invalid
index == -1 || index - 1 >= args?.Length || args == null

Check warning on line 68 in AzureLiquid.Preview/PreviewProcessArguments.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Conditional access qualifier expression is not null according to nullable reference types' annotations

Conditional access qualifier expression is never null according to nullable reference types' annotations
? string.Empty // No match, or no arguments passed
: Path.GetFullPath(args[index + 1], _path); // Argument found, parsing path
}
}

0 comments on commit c159f08

Please sign in to comment.