Skip to content

Commit

Permalink
add overload taking params array (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sir-Baconn authored Jan 15, 2022
1 parent 0b988ff commit f221c1f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Spectre.Console/Prompts/MultiSelectionPromptExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ public static MultiSelectionPrompt<T> AddChoiceGroup<T>(this MultiSelectionPromp
return obj;
}

/// <summary>
/// Adds multiple grouped choices.
/// </summary>
/// <typeparam name="T">The prompt result type.</typeparam>
/// <param name="obj">The prompt.</param>
/// <param name="group">The group.</param>
/// <param name="choices">The choices to add.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static MultiSelectionPrompt<T> AddChoiceGroup<T>(this MultiSelectionPrompt<T> obj, T group, params T[] choices)
where T : notnull
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}

var root = obj.AddChoice(group);
foreach (var choice in choices)
{
root.AddChild(choice);
}

return obj;
}

/// <summary>
/// Marks an item as selected.
/// </summary>
Expand Down
25 changes: 25 additions & 0 deletions src/Spectre.Console/Prompts/SelectionPromptExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ public static SelectionPrompt<T> AddChoiceGroup<T>(this SelectionPrompt<T> obj,
return obj;
}

/// <summary>
/// Adds multiple grouped choices.
/// </summary>
/// <typeparam name="T">The prompt result type.</typeparam>
/// <param name="obj">The prompt.</param>
/// <param name="group">The group.</param>
/// <param name="choices">The choices to add.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static SelectionPrompt<T> AddChoiceGroup<T>(this SelectionPrompt<T> obj, T group, params T[] choices)
where T : notnull
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}

var root = obj.AddChoice(group);
foreach (var choice in choices)
{
root.AddChild(choice);
}

return obj;
}

/// <summary>
/// Sets the title.
/// </summary>
Expand Down

0 comments on commit f221c1f

Please sign in to comment.