0

I have a Symfony command controller in a TYPO3 extension which has arguments. The arguments are set using for example $this->addArgument('myArgument', InputArgument::OPTIONAL, 'My argument', 'default'); and fetched using $input->getArgument('myArgument'). The command is executed using vendor/bin/typo3 myextension:mycommand myargument.

This works fine usually, however one argument is used to set a relative date using strtotime, like -1 week. This causes an error: The "-1" option does not exist. The command used for this is vendor/bin/typo3 myextension:mycommand "-1 week".

Is there a different way to input the argument or a way to escape it? I've already tried "\-1 week"

Rudy Gnodde
  • 4,286
  • 2
  • 12
  • 34
  • if you are in a hurry and you wanna do it quick and dirty, why dont you just add one more argument which accepts either minus or plus as word and evaluate it in your command? vendor/bin/typo3 myextension:mycommand 'minus' '1-week'. – Aristeidis Karavas Jul 15 '21 at 10:07
  • I thought about that, but `strtotime` accepts other things as well. I might use a different character, like `_` instead of `-` and replace it in my code if nothing else fixes it, but I'd rather have a clean fix. – Rudy Gnodde Jul 15 '21 at 10:13

1 Answers1

0

It's a known bug in Symfony for both arguments and options. I've "fixed" it for now by using _ instead of - and replacing it in my code using $myArgument = preg_replace('/^_/', '-', $input->getArgument('myArgument'));. This does mean my argument can't start with an underscore, but that's not a problem in this case.

Rudy Gnodde
  • 4,286
  • 2
  • 12
  • 34