@@ -12,14 +12,14 @@ public function __construct()
1212 $ this ->cmds = new CIArray ();
1313 }
1414
15- function add (string $ command , callable $ method , array $ preArgs = [], array $ postArgs = [], string $ syntax = '' ) {
15+ function add (string $ command , callable $ method , array $ preArgs = [], array $ postArgs = [], string $ syntax = '' , array $ opts = [] ) {
1616 if (str_contains ($ command , '# ' )) {
1717 throw new \Exception ('Command name cannot contain # ' );
1818 }
1919 if (isset ($ this ->cmds [$ command ])) {
2020 throw new \Exception ('Command already exists ' );
2121 }
22- $ this ->cmds [$ command ] = new Cmd ($ command , $ method , $ preArgs , $ postArgs , $ syntax );
22+ $ this ->cmds [$ command ] = new Cmd ($ command , $ method , $ preArgs , $ postArgs , $ syntax, $ opts );
2323 }
2424
2525 function get (string $ command , string $ text ) : Request |false {
@@ -52,18 +52,22 @@ protected function attrAddCmd($rf, $f) {
5252 $ sa = $ syntaxAttr [0 ]->newInstance ();
5353 $ syntax = $ sa ->syntax ;
5454 }
55+
5556 $ callWrapAttr = $ rf ->getAttributes (attributes \CallWrap::class);
56- if (isset ($ callWrapAttr [0 ])) {
57- $ cw = $ callWrapAttr [0 ]->newInstance ();
58- $ callWrapper = $ cw ->caller ;
59- $ callWrapperPre = $ cw ->preArgs ;
57+ if ($ cw = ($ callWrapAttr [0 ]??null )?->newInstance()) {
58+ $ callWrapperPre = [...$ cw ->preArgs , $ f ];
59+ $ f = $ cw ->caller ;
6060 $ callWrapperPost = $ cw ->postArgs ;
6161 }
62+
63+ $ optionsAttr = $ rf ->getAttributes (attributes \Options::class);
64+ $ opts = [];
65+ if (isset ($ optionsAttr [0 ]))
66+ $ opts = $ optionsAttr [0 ]->newInstance ()->options ;
67+
68+
6269 foreach ($ cmdAttr ->args as $ command ) {
63- if ($ callWrapper != null )
64- $ this ->cmds [$ command ] = new Cmd ($ command , $ callWrapper , [...$ callWrapperPre , $ f ], $ callWrapperPost , $ syntax );
65- else
66- $ this ->cmds [$ command ] = new Cmd ($ command , $ f , $ callWrapperPre , $ callWrapperPost , $ syntax );
70+ $ this ->cmds [$ command ] = new Cmd ($ command , $ f , $ callWrapperPre , $ callWrapperPost , $ syntax , $ opts );
6771 }
6872 }
6973
0 commit comments