File tree 4 files changed +38
-3
lines changed
System.CommandLine/Builder
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 1
1
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
- using System . CommandLine . Binding ;
5
- using System . CommandLine . Invocation ;
6
- using System . CommandLine . Parsing ;
7
4
using FluentAssertions ;
5
+ using System . CommandLine . Parsing ;
8
6
using System . Linq ;
9
7
using Xunit ;
10
8
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ public CommandBuilder(Command command)
21
21
22
22
internal void AddOption ( Option option ) => Command . AddOption ( option ) ;
23
23
24
+ internal void AddGlobalOption ( Option option ) => Command . AddGlobalOption ( option ) ;
25
+
24
26
internal void AddArgument ( Argument argument ) => Command . AddArgument ( argument ) ;
25
27
}
26
28
}
Original file line number Diff line number Diff line change @@ -64,6 +64,16 @@ public static TBuilder AddOption<TBuilder>(
64
64
return builder ;
65
65
}
66
66
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
+
67
77
public static CommandLineBuilder CancelOnProcessTermination ( this CommandLineBuilder builder )
68
78
{
69
79
builder . AddMiddleware ( async ( context , next ) =>
You can’t perform that action at this time.
0 commit comments