13
13
use Symfony \Component \Console \Input \InputArgument ;
14
14
use Symfony \Component \Console \Input \InputInterface ;
15
15
use Symfony \Component \Console \Output \OutputInterface ;
16
+ use Symfony \Component \Console \Input \InputOption ;
17
+ use Magento \FunctionalTestingFramework \Util \Logger \LoggingUtil ;
16
18
17
19
class GenerateDevUrnCommand extends Command
18
20
{
@@ -25,7 +27,13 @@ protected function configure()
25
27
{
26
28
$ this ->setName ('generate:urn-catalog ' )
27
29
->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
+ );
29
37
}
30
38
31
39
/**
@@ -40,12 +48,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
40
48
{
41
49
$ miscXmlFilePath = $ input ->getArgument ('path ' ) . DIRECTORY_SEPARATOR . "misc.xml " ;
42
50
$ miscXmlFile = realpath ($ miscXmlFilePath );
51
+ $ force = $ input ->getOption ('force ' );
43
52
44
53
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
+ }
49
65
}
50
66
$ dom = new \DOMDocument ('1.0 ' );
51
67
$ dom ->preserveWhiteSpace = false ;
0 commit comments