Skip to content
Merged
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
33 changes: 33 additions & 0 deletions src/System.CommandLine/Argument{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@

namespace System.CommandLine
{
///<inheritdoc/>
public class Argument<T> : Argument
{
/// <summary>
/// Initializes a new instance of the Argument class.
/// </summary>
public Argument()
{
ArgumentType = typeof(T);
}

/// <summary>
/// Initializes a new instance of the Argument class.
/// </summary>
/// <param name="name">The name of the argument.</param>
/// <param name="description">The description of the argument, shown in help.</param>
public Argument(
string name,
string? description = null) : base(name)
Expand All @@ -20,6 +29,13 @@ public Argument(
Description = description;
}

/// <summary>
/// Initializes a new instance of the Argument class.
/// </summary>
/// <param name="name">The name of the argument.</param>
/// <param name="getDefaultValue">The delegate to invoke to return the default value.</param>
/// <param name="description">The description of the argument, shown in help.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="getDefaultValue"/> is null.</exception>
public Argument(
string name,
Func<T> getDefaultValue,
Expand All @@ -35,6 +51,11 @@ public Argument(
Description = description;
}

/// <summary>
/// Initializes a new instance of the Argument class.
/// </summary>
/// <param name="getDefaultValue">The delegate to invoke to return the default value.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="getDefaultValue"/> is null.</exception>
public Argument(Func<T> getDefaultValue) : this()
{
if (getDefaultValue is null)
Expand All @@ -45,6 +66,13 @@ public Argument(Func<T> getDefaultValue) : this()
SetDefaultValueFactory(() => getDefaultValue());
}

/// <summary>
/// Initializes a new instance of the Argument class.
/// </summary>
/// <param name="name">The name of the argument.</param>
/// <param name="parse">A custom argument parser.</param>
/// <param name="isDefault"><c>true</c> to use the <paramref name="parse"/> result as default value.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="parse"/> is null.</exception>
public Argument(
string? name,
ParseArgument<T> parse,
Expand Down Expand Up @@ -82,6 +110,11 @@ public Argument(
};
}

/// <summary>
/// Initializes a new instance of the Argument class.
/// </summary>
/// <param name="parse">A custom argument parser.</param>
/// <param name="isDefault"><c>true</c> to use the <paramref name="parse"/> result as default value.</param>
public Argument(ParseArgument<T> parse, bool isDefault = false) : this(null, parse, isDefault)
{
}
Expand Down