Skip to content

Commit

Permalink
fix #1135
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Feb 18, 2021
1 parent 34c0c34 commit 2557b0c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/System.CommandLine.Tests/SuggestionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ public void Enum_suggestions_can_be_configured_without_list_clear()
{
var command = new Command("the-command")
{
new Argument<DayOfWeek?>()
new Argument<DayOfWeek?>
{
Suggestions = { "mon", "tues", "wed", "thur", "fri", "sat", "sun" }
}
Expand Down
6 changes: 3 additions & 3 deletions src/System.CommandLine/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Argument : Symbol, IArgument
private IArgumentArity? _arity;
private TryConvertArgument? _convertArguments;
private Type _argumentType = typeof(string);
private List<ISuggestionSource>? _suggestions = null;
private SuggestionSourceList? _suggestions = null;

/// <summary>
/// Initializes a new instance of the Argument class.
Expand Down Expand Up @@ -93,13 +93,13 @@ internal TryConvertArgument? ConvertArguments
/// <summary>
/// Gets the list of suggestion sources for the argument.
/// </summary>
public List<ISuggestionSource> Suggestions
public SuggestionSourceList Suggestions
{
get
{
if (_suggestions is null)
{
_suggestions = new List<ISuggestionSource>
_suggestions = new SuggestionSourceList
{
SuggestionSource.ForType(ArgumentType)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Environment;
Expand Down
5 changes: 2 additions & 3 deletions src/System.CommandLine/SuggestionSourceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.CommandLine.Suggestions;

namespace System.CommandLine
{
public static class SuggestionSourceExtensions
{
public static void Add(
this List<ISuggestionSource> suggestionSources,
this SuggestionSourceList suggestionSources,
SuggestDelegate suggest)
{
if (suggestionSources is null)
Expand All @@ -26,7 +25,7 @@ public static void Add(
}

public static void Add(
this List<ISuggestionSource> suggestionSources,
this SuggestionSourceList suggestionSources,
params string[] suggestions)
{
if (suggestionSources is null)
Expand Down
32 changes: 32 additions & 0 deletions src/System.CommandLine/SuggestionSourceList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// // Copyright (c) .NET Foundation and contributors. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections;
using System.Collections.Generic;
using System.CommandLine.Suggestions;

namespace System.CommandLine
{
public class SuggestionSourceList : IReadOnlyList<ISuggestionSource>
{
private readonly List<ISuggestionSource> _sources = new List<ISuggestionSource>();

public void Add(ISuggestionSource source)
{
_sources.Add(source);
}

public IEnumerator<ISuggestionSource> GetEnumerator() => _sources.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public void Clear()
{
_sources.Clear();
}

public int Count => _sources.Count;

public ISuggestionSource this[int index] => _sources[index];
}
}

0 comments on commit 2557b0c

Please sign in to comment.