22
33from cleo .application import Application
44from cleo .commands .command import Command
5+ from cleo .helpers import argument
6+ from cleo .helpers import option
57from cleo .testers .application_tester import ApplicationTester
68
79
810class FooCommand (Command ):
911 """
1012 Foo command
13+ """
14+
15+ name = "foo"
16+
17+ description = "Foo command"
18+
19+ arguments = [argument ("foo" )]
20+
21+ options = [option ("--bar" )]
22+
23+ def handle (self ):
24+ self .line (self .argument ("foo" ))
25+
26+ if self .option ("bar" ):
27+ self .line ("--bar activated" )
28+
1129
12- foo
13- {foo : Foo argument}
30+ class FooBarCommand (Command ):
1431 """
32+ Foo Bar command
33+ """
34+
35+ name = "foo bar"
36+
37+ description = "Foo Bar command"
38+
39+ arguments = [argument ("foo" )]
40+
41+ options = [option ("--baz" )]
1542
1643 def handle (self ):
1744 self .line (self .argument ("foo" ))
1845
46+ if self .option ("baz" ):
47+ self .line ("--baz activated" )
48+
1949
2050@pytest .fixture ()
2151def app ():
2252 app = Application ()
2353 app .add (FooCommand ())
54+ app .add (FooBarCommand ())
2455
2556 return app
2657
@@ -30,7 +61,14 @@ def tester(app):
3061 return ApplicationTester (app )
3162
3263
33- def test_execute (tester ):
34- assert 0 == tester .execute ("foo bar" )
64+ def test_execute (tester : ApplicationTester ):
65+ assert 0 == tester .execute ("foo baz --bar" )
66+ assert 0 == tester .status_code
67+ assert "baz\n --bar activated\n " == tester .io .fetch_output ()
68+
69+
70+ def test_execute_namespace_command (tester : ApplicationTester ):
71+ tester .application .catch_exceptions (False )
72+ assert 0 == tester .execute ("foo bar baz --baz" )
3573 assert 0 == tester .status_code
36- assert "bar \n " == tester .io .fetch_output ()
74+ assert "baz \n --baz activated \n " == tester .io .fetch_output ()
0 commit comments