From fa703a987dcb736a737b63343022169ec103a794 Mon Sep 17 00:00:00 2001 From: Kathleen Dollard Date: Mon, 18 May 2020 15:36:13 -0700 Subject: [PATCH 1/2] Sync to upstream --- src/System.CommandLine/Option.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.CommandLine/Option.cs b/src/System.CommandLine/Option.cs index 75a6910208..74efa6be3c 100644 --- a/src/System.CommandLine/Option.cs +++ b/src/System.CommandLine/Option.cs @@ -45,7 +45,7 @@ public virtual Argument Argument IArgument IOption.Argument => Argument; public bool Required { get; set; } - + string IValueDescriptor.ValueName => Name; Type IValueDescriptor.ValueType => Argument.ArgumentType; From b2a31a720bdc5c7c49d06a0d6934e47ad506f980 Mon Sep 17 00:00:00 2001 From: Kathleen Dollard Date: Wed, 10 Jun 2020 09:19:53 -0700 Subject: [PATCH 2/2] Added ConfigurableCommandLineBuilder --- .../Builder/ConfigurableBuilderTests.cs | 44 +++++++++++++++++++ .../Builder/CommandBuilder.cs | 16 ++++++- .../Builder/CommandLineBuilder.cs | 4 ++ .../Builder/ConfigurableCommandLineBuilder.cs | 14 ++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/System.CommandLine.Tests/Builder/ConfigurableBuilderTests.cs create mode 100644 src/System.CommandLine/Builder/ConfigurableCommandLineBuilder.cs diff --git a/src/System.CommandLine.Tests/Builder/ConfigurableBuilderTests.cs b/src/System.CommandLine.Tests/Builder/ConfigurableBuilderTests.cs new file mode 100644 index 0000000000..0d5fab2d05 --- /dev/null +++ b/src/System.CommandLine.Tests/Builder/ConfigurableBuilderTests.cs @@ -0,0 +1,44 @@ +// 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.CommandLine.Builder; +using FluentAssertions; +using Xunit; + +namespace System.CommandLine.Tests.Builder +{ + public class ConfigurableBuilderTests + { + [Fact] + public void When_a_ConfigurableCommandLineBuider_is_created_it_has_a_null_Command() + { + var builder = new ConfigurableCommandLineBuilder(); + builder.Command.Should().BeNull(); + } + + [Fact] + public void ConfigurableCommandLineBuider_Command_can_be_set() + { + var builder = new ConfigurableCommandLineBuilder(); + builder.SetCommand(new Command("Bob")); + builder.Command.Should().NotBeNull() + .And.BeEmpty("Bob"); + + } + + [Fact] + public void ConfigurableCommandLineBuider_Command_should_throw_if_Command_already_set() + { + var builder = new ConfigurableCommandLineBuilder(); + builder.SetCommand(new Command("Bob")); + Action create = () => builder.SetCommand(new Command("Joe")); + + create.Should() + .Throw() + .Which + .Message + .Should() + .Be("Command has already been set."); + } + } +} diff --git a/src/System.CommandLine/Builder/CommandBuilder.cs b/src/System.CommandLine/Builder/CommandBuilder.cs index 8ae8d41a0b..f2bb18ffee 100644 --- a/src/System.CommandLine/Builder/CommandBuilder.cs +++ b/src/System.CommandLine/Builder/CommandBuilder.cs @@ -8,15 +8,27 @@ namespace System.CommandLine.Builder { public class CommandBuilder { - public CommandBuilder(Command command) + public CommandBuilder(Command command) { Command = command; } - public Command Command { get; } + private protected CommandBuilder() + { } + + public Command? Command { get; private set; } public IEnumerable