-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-4374) Fix Frosting argument parsing
* Add argument to Forsting integration tests * Unify Scripting / Frosting Spectre.Console IRemainingArguments to CakeArguments parsing * fixes #4374
- Loading branch information
Showing
5 changed files
with
77 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Cake.Core; | ||
using Spectre.Console.Cli; | ||
|
||
namespace Cake.Cli.Infrastructure | ||
{ | ||
/// <summary> | ||
/// Spectre.Console <see cref="IRemainingArguments"/> extensions. | ||
/// </summary> | ||
public static class IRemainingArgumentsExtensions | ||
{ | ||
/// <summary> | ||
/// Parses Spectre.Console <see cref="IRemainingArguments"/> to <see cref="CakeArguments"/>. | ||
/// </summary> | ||
/// <param name="remainingArguments">The remainingArguments.</param> | ||
/// <param name="targets">The optional targets, i.e. if specified by command.</param> | ||
/// <param name="preProcessArgs">The optional pre-process arguments.</param> | ||
/// <returns><see cref="CakeArguments"/>.</returns> | ||
public static CakeArguments ToCakeArguments( | ||
this IRemainingArguments remainingArguments, | ||
string[] targets = null, | ||
Action<IDictionary<string, List<string>>> preProcessArgs = null) | ||
{ | ||
var arguments = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase); | ||
|
||
// Keep the actual remaining arguments in the cake arguments | ||
foreach (var group in remainingArguments.Parsed) | ||
{ | ||
string key = group.Key.TrimStart('-'); | ||
arguments[key] = new List<string>(); | ||
foreach (var argument in group) | ||
{ | ||
arguments[key].Add(argument); | ||
} | ||
} | ||
|
||
// Fixes #3291, We have to add arguments manually which are defined within the DefaultCommandSettings type. Those are not considered "as remaining" because they could be parsed | ||
const string targetArgumentName = "target"; | ||
if (!arguments.ContainsKey(targetArgumentName)) | ||
{ | ||
arguments[targetArgumentName] = new List<string>(); | ||
} | ||
|
||
if (targets != null) | ||
{ | ||
foreach (var target in targets) | ||
{ | ||
arguments[targetArgumentName].Add(target); | ||
} | ||
} | ||
|
||
preProcessArgs?.Invoke(arguments); | ||
|
||
var argumentLookUp = arguments.SelectMany(a => a.Value, Tuple.Create).ToLookup(a => a.Item1.Key, a => a.Item2); | ||
return new CakeArguments(argumentLookUp); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters