@@ -18,6 +18,77 @@ public SubCommandTest(ITestOutputHelper testOutput)
1818 this . testOutput = testOutput ;
1919 }
2020
21+ public class TwoSubCommand : BatchBase
22+ {
23+ public void Main ( double d )
24+ {
25+ Context . Logger . LogInformation ( $ "d:{ d } ") ;
26+ }
27+
28+ [ Command ( "run" ) ]
29+ public void Run ( string path , string pfx )
30+ {
31+ Context . Logger . LogInformation ( $ "path:{ path } ") ;
32+ Context . Logger . LogInformation ( $ "pfx:{ pfx } ") ;
33+ }
34+
35+ [ Command ( "sum" ) ]
36+ public void Sum ( [ Option ( 0 ) ] int x , [ Option ( 1 ) ] int y )
37+ {
38+ Context . Logger . LogInformation ( $ "x:{ x } ") ;
39+ Context . Logger . LogInformation ( $ "y:{ y } ") ;
40+ }
41+
42+ [ Command ( "opt" ) ]
43+ public void Option ( [ Option ( 0 ) ] string input , [ Option ( "x" ) ] int xxx , [ Option ( "y" ) ] int yyy )
44+ {
45+ Context . Logger . LogInformation ( $ "input:{ input } ") ;
46+ Context . Logger . LogInformation ( $ "x:{ xxx } ") ;
47+ Context . Logger . LogInformation ( $ "y:{ yyy } ") ;
48+ }
49+ }
50+
51+ [ Fact ]
52+ public async Task TwoSubCommandTest ( )
53+ {
54+ {
55+ var args = "-d 12345.12345" . Split ( ' ' ) ;
56+ var log = new LogStack ( ) ;
57+ await new HostBuilder ( )
58+ . ConfigureTestLogging ( testOutput , log , true )
59+ . RunBatchEngineAsync < TwoSubCommand > ( args ) ;
60+ log . InfoLogShouldBe ( 0 , "d:12345.12345" ) ;
61+ }
62+ {
63+ var args = "run -path foo -pfx bar" . Split ( ' ' ) ;
64+ var log = new LogStack ( ) ;
65+ await new HostBuilder ( )
66+ . ConfigureTestLogging ( testOutput , log , true )
67+ . RunBatchEngineAsync < TwoSubCommand > ( args ) ;
68+ log . InfoLogShouldBe ( 0 , "path:foo" ) ;
69+ log . InfoLogShouldBe ( 1 , "pfx:bar" ) ;
70+ }
71+ {
72+ var args = "sum 10 20" . Split ( ' ' ) ;
73+ var log = new LogStack ( ) ;
74+ await new HostBuilder ( )
75+ . ConfigureTestLogging ( testOutput , log , true )
76+ . RunBatchEngineAsync < TwoSubCommand > ( args ) ;
77+ log . InfoLogShouldBe ( 0 , "x:10" ) ;
78+ log . InfoLogShouldBe ( 1 , "y:20" ) ;
79+ }
80+ {
81+ var args = "opt foobarbaz -x 10 -y 20" . Split ( ' ' ) ;
82+ var log = new LogStack ( ) ;
83+ await new HostBuilder ( )
84+ . ConfigureTestLogging ( testOutput , log , true )
85+ . RunBatchEngineAsync < TwoSubCommand > ( args ) ;
86+ log . InfoLogShouldBe ( 0 , "input:foobarbaz" ) ;
87+ log . InfoLogShouldBe ( 1 , "x:10" ) ;
88+ log . InfoLogShouldBe ( 2 , "y:20" ) ;
89+ }
90+ }
91+
2192 public class NotFoundPath : BatchBase
2293 {
2394 [ Command ( "run" ) ]
0 commit comments