From 44c532950d7c1dc1ba03ef3039caf9a405e239a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20Erdo=C4=9Fru?= Date: Wed, 2 Mar 2022 15:42:14 +0300 Subject: [PATCH] Added return statement to add methods to use them as chain method. --- src/System.CommandLine/Command.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/System.CommandLine/Command.cs b/src/System.CommandLine/Command.cs index 4f9cfc7cd8..3daf1ed169 100644 --- a/src/System.CommandLine/Command.cs +++ b/src/System.CommandLine/Command.cs @@ -78,10 +78,11 @@ internal IReadOnlyList> Validators /// Adds an to the command. /// /// The argument to add to the command. - public void AddArgument(Argument argument) + public Command AddArgument(Argument argument) { argument.AddParent(this); (_arguments ??= new()).Add(argument); + return this; } /// @@ -89,20 +90,22 @@ public void AddArgument(Argument argument) /// /// The subcommand to add to the command. /// Commands can be nested to an arbitrary depth. - public void AddCommand(Command command) + public Command AddCommand(Command command) { command.AddParent(this); (_subcommands ??= new()).Add(command); + return this; } /// /// Adds an to the command. /// /// The option to add to the command. - public void AddOption(Option option) + public Command AddOption(Option option) { option.AddParent(this); (_options ??= new()).Add(option); + return this; } /// @@ -120,20 +123,20 @@ public void AddGlobalOption(Option option) /// Adds an to the command. /// /// The option to add to the command. - public void Add(Option option) => AddOption(option); + public Command Add(Option option) => AddOption(option); /// /// Adds an to the command. /// /// The argument to add to the command. - public void Add(Argument argument) => AddArgument(argument); + public Command Add(Argument argument) => AddArgument(argument); /// /// Adds a subcommand to the command. /// /// The subcommand to add to the command. /// Commands can be nested to an arbitrary depth. - public void Add(Command command) => AddCommand(command); + public Command Add(Command command) => AddCommand(command); private protected override string DefaultName => throw new NotImplementedException();