Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add links to the new conceptual documentation #1707

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions src/System.CommandLine/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace System.CommandLine
/// <summary>
/// A symbol defining a value that can be passed on the command line to a <see cref="Command">command</see> or <see cref="Option">option</see>.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public abstract class Argument : Symbol, IValueDescriptor
{
private Func<ArgumentResult, object?>? _defaultValueFactory;
Expand All @@ -23,6 +25,7 @@ public abstract class Argument : Symbol, IValueDescriptor
/// <summary>
/// Initializes a new instance of the Argument class.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
protected Argument()
{
}
Expand All @@ -32,6 +35,7 @@ protected Argument()
/// </summary>
/// <param name="name">The name of the argument.</param>
/// <param name="description">The description of the argument, shown in help.</param>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
protected Argument(string? name = null, string? description = null)
{
Name = name!;
Expand All @@ -41,8 +45,9 @@ protected Argument(string? name = null, string? description = null)
internal HashSet<string>? AllowedValues { get; private set; }

/// <summary>
/// Gets or sets the arity of the argument.
/// Gets or sets the <see href="/dotnet/standard/commandline/syntax#argument-arity">arity</see> of the argument.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public ArgumentArity Arity
{
get
Expand All @@ -63,6 +68,7 @@ public ArgumentArity Arity
/// <summary>
/// The name used in help output to describe the argument.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/customize-help">How to customize help</seealso>
public string? HelpName { get; set; }

internal TryConvertArgument? ConvertArguments
Expand All @@ -83,6 +89,7 @@ internal TryConvertArgument? ConvertArguments
/// <summary>
/// Gets or sets the <see cref="Type" /> that the argument token(s) will be converted to.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public abstract Type ValueType { get; }

private protected override string DefaultName
Expand Down Expand Up @@ -111,13 +118,15 @@ private protected override string DefaultName
/// to provide custom errors based on user input.
/// </summary>
/// <param name="validate">The delegate to validate the parsed argument.</param>
/// <seealso href="/dotnet/standard/commandline/model-binding#custom-validation-and-binding">How to bind arguments to handlers - Custom validation and binding</seealso>
public void AddValidator(ValidateSymbolResult<ArgumentResult> validate) => Validators.Add(validate);

/// <summary>
/// Gets the default value for the argument.
/// </summary>
/// <returns>Returns the default value for the argument, if defined. Null otherwise.</returns>
public object? GetDefaultValue()
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public object? GetDefaultValue()
{
return GetDefaultValue(new ArgumentResult(this, null));
}
Expand All @@ -136,6 +145,7 @@ private protected override string DefaultName
/// Sets the default value for the argument.
/// </summary>
/// <param name="value">The default value for the argument.</param>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public void SetDefaultValue(object? value)
{
SetDefaultValueFactory(() => value);
Expand All @@ -146,6 +156,7 @@ public void SetDefaultValue(object? value)
/// </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>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public void SetDefaultValueFactory(Func<object?> getDefaultValue)
{
if (getDefaultValue is null)
Expand All @@ -161,6 +172,7 @@ public void SetDefaultValueFactory(Func<object?> getDefaultValue)
/// </summary>
/// <param name="getDefaultValue">The delegate to invoke to return the default value.</param>
/// <remarks>In this overload, the <see cref="ArgumentResult"/> is provided to the delegate.</remarks>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public void SetDefaultValueFactory(Func<ArgumentResult, object?> getDefaultValue)
{
_defaultValueFactory = getDefaultValue ?? throw new ArgumentNullException(nameof(getDefaultValue));
Expand All @@ -169,6 +181,7 @@ public void SetDefaultValueFactory(Func<ArgumentResult, object?> getDefaultValue
/// <summary>
/// Specifies if a default value is defined for the argument.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public bool HasDefaultValue => _defaultValueFactory is not null;

internal virtual bool HasCustomParser => false;
Expand Down
11 changes: 10 additions & 1 deletion src/System.CommandLine/ArgumentArity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
namespace System.CommandLine
{
/// <summary>
/// Defines the arity of an option or argument.
/// Defines the <see href="/dotnet/standard/commandline/syntax#argument-arity">arity</see> of an option or argument.
/// </summary>
/// <remarks>The arity refers to the number of values that can be passed on the command line.
/// </remarks>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
[DebuggerDisplay("\\{{" + nameof(MinimumNumberOfValues) + "},{" + nameof(MaximumNumberOfValues) + "}\\}")]
public readonly struct ArgumentArity : IEquatable<ArgumentArity>
{
Expand All @@ -25,6 +26,7 @@ namespace System.CommandLine
/// <param name="maximumNumberOfValues">The maximum number of values allowed for the argument.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="minimumNumberOfValues"/> is negative.</exception>
/// <exception cref="ArgumentException">Thrown when the maximum number is less than the minimum number or the maximum number is greater than MaximumArity.</exception>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
public ArgumentArity(int minimumNumberOfValues, int maximumNumberOfValues)
{
if (minimumNumberOfValues < 0)
Expand All @@ -50,11 +52,13 @@ public ArgumentArity(int minimumNumberOfValues, int maximumNumberOfValues)
/// <summary>
/// Gets the minimum number of values required for an <see cref="Argument">argument</see>.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
public int MinimumNumberOfValues { get; }

/// <summary>
/// Gets the maximum number of values allowed for an <see cref="Argument">argument</see>.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
public int MaximumNumberOfValues { get; }

internal bool IsNonDefault { get; }
Expand Down Expand Up @@ -119,26 +123,31 @@ public override int GetHashCode()
/// <summary>
/// An arity that does not allow any values.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
public static ArgumentArity Zero => new(0, 0);

/// <summary>
/// An arity that may have one value, but no more than one.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
public static ArgumentArity ZeroOrOne => new(0, 1);

/// <summary>
/// An arity that must have exactly one value.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
public static ArgumentArity ExactlyOne => new(1, 1);

/// <summary>
/// An arity that may have multiple values.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
public static ArgumentArity ZeroOrMore => new(0, MaximumArity);

/// <summary>
/// An arity that must have at least one value.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
public static ArgumentArity OneOrMore => new(1, MaximumArity);

internal static ArgumentArity Default(Type type, Argument argument, ParentNode? firstParent)
Expand Down
15 changes: 15 additions & 0 deletions src/System.CommandLine/ArgumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace System.CommandLine
/// <summary>
/// Provides extension methods for <see cref="Argument" />.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/syntax">Command-line syntax overview</seealso>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public static class ArgumentExtensions
{
/// <summary>
Expand All @@ -20,6 +22,7 @@ public static class ArgumentExtensions
/// <param name="argument">The argument for which to add completions.</param>
/// <param name="values">The completions to add.</param>
/// <returns>The configured argument.</returns>
/// <seealso href="/dotnet/standard/commandline/tab-completion">Tab completion</seealso>
public static TArgument AddCompletions<TArgument>(
this TArgument argument,
params string[] values)
Expand All @@ -37,6 +40,7 @@ public static TArgument AddCompletions<TArgument>(
/// <param name="argument">The argument for which to add completions.</param>
/// <param name="complete">A <see cref="CompletionDelegate"/> that will be called to provide completions.</param>
/// <returns>The option being extended.</returns>
/// <seealso href="/dotnet/standard/commandline/tab-completion">Tab completion</seealso>
public static TArgument AddCompletions<TArgument>(
this TArgument argument,
Func<CompletionContext, IEnumerable<string>> complete)
Expand All @@ -54,6 +58,7 @@ public static TArgument AddCompletions<TArgument>(
/// <param name="argument">The argument for which to add completions.</param>
/// <param name="complete">A <see cref="CompletionDelegate"/> that will be called to provide completions.</param>
/// <returns>The configured argument.</returns>
/// <seealso href="/dotnet/standard/commandline/tab-completion">Tab completion</seealso>
public static TArgument AddCompletions<TArgument>(
this TArgument argument,
CompletionDelegate complete)
Expand All @@ -71,6 +76,8 @@ public static TArgument AddCompletions<TArgument>(
/// <param name="values">The values that are allowed for the argument.</param>
/// <typeparam name="TArgument">The type of the argument.</typeparam>
/// <returns>The configured argument.</returns>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
/// <seealso href="/dotnet/standard/commandline/tab-completion">Tab completion</seealso>
public static TArgument FromAmong<TArgument>(
this TArgument argument,
params string[] values)
Expand All @@ -87,6 +94,7 @@ public static TArgument FromAmong<TArgument>(
/// </summary>
/// <param name="argument">The argument to configure.</param>
/// <returns>The configured argument.</returns>
/// <seealso href="/dotnet/standard/commandline/model-binding">How to bind arguments to handlers</seealso>
public static Argument<FileInfo> ExistingOnly(this Argument<FileInfo> argument)
{
argument.AddValidator(Validate.FileExists);
Expand All @@ -98,6 +106,7 @@ public static Argument<FileInfo> ExistingOnly(this Argument<FileInfo> argument)
/// </summary>
/// <param name="argument">The argument to configure.</param>
/// <returns>The configured argument.</returns>
/// <seealso href="/dotnet/standard/commandline/model-binding">How to bind arguments to handlers</seealso>
public static Argument<DirectoryInfo> ExistingOnly(this Argument<DirectoryInfo> argument)
{
argument.AddValidator(Validate.DirectoryExists);
Expand All @@ -109,6 +118,7 @@ public static Argument<DirectoryInfo> ExistingOnly(this Argument<DirectoryInfo>
/// </summary>
/// <param name="argument">The argument to configure.</param>
/// <returns>The configured argument.</returns>
/// <seealso href="/dotnet/standard/commandline/model-binding">How to bind arguments to handlers</seealso>
public static Argument<FileSystemInfo> ExistingOnly(this Argument<FileSystemInfo> argument)
{
argument.AddValidator(Validate.FileOrDirectoryExists);
Expand All @@ -120,6 +130,7 @@ public static Argument<FileSystemInfo> ExistingOnly(this Argument<FileSystemInfo
/// </summary>
/// <param name="argument">The argument to configure.</param>
/// <returns>The configured argument.</returns>
/// <seealso href="/dotnet/standard/commandline/model-binding">How to bind arguments to handlers</seealso>
public static Argument<T> ExistingOnly<T>(this Argument<T> argument)
where T : IEnumerable<FileSystemInfo>
{
Expand All @@ -144,6 +155,7 @@ public static Argument<T> ExistingOnly<T>(this Argument<T> argument)
/// </summary>
/// <param name="argument">The argument to configure.</param>
/// <returns>The configured argument.</returns>
/// <seealso href="/dotnet/standard/commandline/model-binding">How to bind arguments to handlers</seealso>
public static TArgument LegalFilePathsOnly<TArgument>(
this TArgument argument)
where TArgument : Argument
Expand Down Expand Up @@ -176,6 +188,7 @@ public static TArgument LegalFilePathsOnly<TArgument>(
/// <remarks>A parse error will result, for example, if file path separators are found in the parsed value.</remarks>
/// <param name="argument">The argument to configure.</param>
/// <returns>The configured argument.</returns>
/// <seealso href="/dotnet/standard/commandline/model-binding">How to bind arguments to handlers</seealso>
public static TArgument LegalFileNamesOnly<TArgument>(
this TArgument argument)
where TArgument : Argument
Expand Down Expand Up @@ -206,6 +219,7 @@ public static TArgument LegalFileNamesOnly<TArgument>(
/// <param name="argument">The argument to use to parse the command line input.</param>
/// <param name="commandLine">A command line string to parse, which can include spaces and quotes equivalent to what can be entered into a terminal.</param>
/// <returns>A parse result describing the outcome of the parse operation.</returns>
/// <seealso href="/dotnet/standard/commandline/syntax#directives">Command-line syntax overview - Directives</seealso>
public static ParseResult Parse(
this Argument argument,
string commandLine) =>
Expand All @@ -217,6 +231,7 @@ public static ParseResult Parse(
/// <param name="argument">The argument to use to parse the command line input.</param>
/// <param name="args">The string arguments to parse.</param>
/// <returns>A parse result describing the outcome of the parse operation.</returns>
/// <seealso href="/dotnet/standard/commandline/syntax#directives">Command-line syntax overview - Directives</seealso>
public static ParseResult Parse(
this Argument argument,
string[] args) =>
Expand Down
5 changes: 5 additions & 0 deletions src/System.CommandLine/Argument{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Argument<T> : Argument, IValueDescriptor<T>
/// <summary>
/// Initializes a new instance of the Argument class.
/// </summary>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public Argument()
{
}
Expand All @@ -32,6 +33,7 @@ public Argument(
/// <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>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public Argument(
string name,
Func<T> getDefaultValue,
Expand All @@ -50,6 +52,7 @@ public Argument(
/// </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>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public Argument(Func<T> getDefaultValue) : this()
{
if (getDefaultValue is null)
Expand All @@ -68,6 +71,7 @@ public Argument(Func<T> getDefaultValue) : this()
/// <param name="isDefault"><see langword="true"/> to use the <paramref name="parse"/> result as default value.</param>
/// <param name="description">The description of the argument, shown in help.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="parse"/> is null.</exception>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public Argument(
string? name,
ParseArgument<T> parse,
Expand Down Expand Up @@ -108,6 +112,7 @@ public Argument(
/// </summary>
/// <param name="parse">A custom argument parser.</param>
/// <param name="isDefault"><see langword="true"/> to use the <paramref name="parse"/> result as default value.</param>
/// <seealso href="/dotnet/standard/commandline/define-commands">How to define commands, options, and arguments</seealso>
public Argument(ParseArgument<T> parse, bool isDefault = false) : this(null!, parse, isDefault)
{
}
Expand Down
3 changes: 3 additions & 0 deletions src/System.CommandLine/Binding/BinderBase{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/// Supports binding of custom types.
/// </summary>
/// <typeparam name="T">The type to be bound.</typeparam>
/// <seealso href="/dotnet/standard/commandline/model-binding#model-binding-more-than-16-options-and-arguments">Model binding more than 16 options and arguments</seealso>

public abstract class BinderBase<T> :
IValueDescriptor<T>,
IValueSource
Expand All @@ -13,6 +15,7 @@ public abstract class BinderBase<T> :
/// </summary>
/// <param name="bindingContext"></param>
/// <returns></returns>
/// <seealso href="/dotnet/standard/commandline/model-binding#model-binding-more-than-16-options-and-arguments">Model binding more than 16 options and arguments</seealso>
protected abstract T GetBoundValue(BindingContext bindingContext);

string IValueDescriptor.ValueName => GetType().Name;
Expand Down
Loading