File tree Expand file tree Collapse file tree 4 files changed +38
-3
lines changed
System.CommandLine/Builder Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 1+ using System . CommandLine . Builder ;
2+ using System . CommandLine . Parsing ;
3+ using FluentAssertions ;
4+ using Xunit ;
5+
6+ namespace System . CommandLine . Tests . Builder
7+ {
8+ public class CommandLineBuilderExtensionsTests
9+ {
10+ [ Fact ]
11+ public void Global_options_are_added_to_the_root_command ( )
12+ {
13+ var globalOption = new Option ( "global" ) ;
14+ var builder = new CommandLineBuilder ( )
15+ . AddGlobalOption ( globalOption ) ;
16+
17+ Parser parser = builder . Build ( ) ;
18+
19+ Command rootCommand = ( Command ) parser . Configuration . RootCommand ;
20+ rootCommand . GlobalOptions
21+ . Should ( )
22+ . Contain ( globalOption ) ;
23+ }
24+ }
25+ }
Original file line number Diff line number Diff line change 11// Copyright (c) .NET Foundation and contributors. All rights reserved.
22// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33
4- using System . CommandLine . Binding ;
5- using System . CommandLine . Invocation ;
6- using System . CommandLine . Parsing ;
74using FluentAssertions ;
5+ using System . CommandLine . Parsing ;
86using System . Linq ;
97using Xunit ;
108
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ public CommandBuilder(Command command)
2121
2222 internal void AddOption ( Option option ) => Command . AddOption ( option ) ;
2323
24+ internal void AddGlobalOption ( Option option ) => Command . AddGlobalOption ( option ) ;
25+
2426 internal void AddArgument ( Argument argument ) => Command . AddArgument ( argument ) ;
2527 }
2628}
Original file line number Diff line number Diff line change @@ -64,6 +64,16 @@ public static TBuilder AddOption<TBuilder>(
6464 return builder ;
6565 }
6666
67+ public static TBuilder AddGlobalOption < TBuilder > (
68+ this TBuilder builder ,
69+ Option option )
70+ where TBuilder : CommandBuilder
71+ {
72+ builder . AddGlobalOption ( option ) ;
73+
74+ return builder ;
75+ }
76+
6777 public static CommandLineBuilder CancelOnProcessTermination ( this CommandLineBuilder builder )
6878 {
6979 builder . AddMiddleware ( async ( context , next ) =>
You can’t perform that action at this time.
0 commit comments