1313use Symfony \Component \Console \Input \InputArgument ;
1414use Symfony \Component \Console \Input \InputInterface ;
1515use Symfony \Component \Console \Output \OutputInterface ;
16+ use Symfony \Component \Console \Input \InputOption ;
17+ use Magento \FunctionalTestingFramework \Util \Logger \LoggingUtil ;
1618
1719class GenerateDevUrnCommand extends Command
1820{
@@ -25,7 +27,13 @@ protected function configure()
2527 {
2628 $ this ->setName ('generate:urn-catalog ' )
2729 ->setDescription ('This command generates an URN catalog to enable PHPStorm to recognize and highlight URNs. ' )
28- ->addArgument ('path ' , InputArgument::REQUIRED , 'path to PHPStorm misc.xml file (typically located in [ProjectRoot]/.idea/misc.xml) ' );
30+ ->addArgument ('path ' , InputArgument::REQUIRED , 'path to PHPStorm misc.xml file (typically located in [ProjectRoot]/.idea/misc.xml) ' )
31+ ->addOption (
32+ "force " ,
33+ 'f ' ,
34+ InputOption::VALUE_NONE ,
35+ 'forces creation of misc.xml file if not found in the path given. '
36+ );
2937 }
3038
3139 /**
@@ -40,12 +48,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
4048 {
4149 $ miscXmlFilePath = $ input ->getArgument ('path ' ) . DIRECTORY_SEPARATOR . "misc.xml " ;
4250 $ miscXmlFile = realpath ($ miscXmlFilePath );
51+ $ force = $ input ->getOption ('force ' );
4352
4453 if ($ miscXmlFile === false ) {
45- $ exceptionMessage = "misc.xml not found in given path ' {$ miscXmlFilePath }' " ;
46- LoggingUtil::getInstance ()->getLogger (GenerateDevUrnCommand::class)
47- ->error ($ exceptionMessage );
48- throw new TestFrameworkException ($ exceptionMessage );
54+ if ($ force == true ) {
55+ // create file and refresh realpath
56+ $ xml = "<project version= \"4 \"/> " ;
57+ file_put_contents ($ miscXmlFilePath , $ xml );
58+ $ miscXmlFile = realpath ($ miscXmlFilePath );
59+ } else {
60+ $ exceptionMessage = "misc.xml not found in given path ' {$ miscXmlFilePath }' " ;
61+ LoggingUtil::getInstance ()->getLogger (GenerateDevUrnCommand::class)
62+ ->error ($ exceptionMessage );
63+ throw new TestFrameworkException ($ exceptionMessage );
64+ }
4965 }
5066 $ dom = new \DOMDocument ('1.0 ' );
5167 $ dom ->preserveWhiteSpace = false ;
0 commit comments