File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
src/System.CommandLine.Tests Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1
1
using System . CommandLine . Builder ;
2
+ using System . CommandLine . Help ;
2
3
using System . CommandLine . Invocation ;
3
4
using System . CommandLine . Parsing ;
4
5
using System . Globalization ;
@@ -149,5 +150,35 @@ public static async Task Sets_CurrentUICulture_to_invariant_culture()
149
150
150
151
asserted . Should ( ) . BeTrue ( ) ;
151
152
}
153
+
154
+ public class CultureAwareHelpBuilder : HelpBuilder
155
+ {
156
+ public CultureAwareHelpBuilder ( IConsole console , Action cultureAssert )
157
+ : base ( console )
158
+ {
159
+ cultureAssert . Invoke ( ) ;
160
+ }
161
+ }
162
+
163
+ [ Fact ]
164
+ public static async Task CurrentCulture_is_set_when_HelpBuilder_runs ( )
165
+ {
166
+ bool asserted = false ;
167
+ // Make sure we're invariant to begin with
168
+ CultureInfo . CurrentCulture = CultureInfo . InvariantCulture ;
169
+ var parser = new CommandLineBuilder ( )
170
+ . UseCultureDirective ( )
171
+ . UseHelp ( )
172
+ . UseHelpBuilder ( ctx => new CultureAwareHelpBuilder ( ctx . Console , ( ) =>
173
+ {
174
+ asserted = true ;
175
+ CultureInfo . CurrentCulture . Name . Should ( ) . Be ( "de-DE" ) ;
176
+ } ) )
177
+ . Build ( ) ;
178
+
179
+ await parser . InvokeAsync ( new [ ] { "[culture:de-DE]" , "--help" } ) ;
180
+
181
+ asserted . Should ( ) . BeTrue ( ) ;
182
+ }
152
183
}
153
184
}
You can’t perform that action at this time.
0 commit comments