@@ -20,6 +20,7 @@ protected function configure()
20
20
$ this ->addOption ('no-recurse ' , null , InputOption::VALUE_NONE , 'Do not recurse ' );
21
21
$ this ->addOption ('skip-binary ' , null , InputOption::VALUE_NONE , 'Skip binary properties ' );
22
22
$ this ->addOption ('document ' , null , InputOption::VALUE_NONE , 'Export the document view ' );
23
+ $ this ->addOption ('pretty ' , null , InputOption::VALUE_NONE , 'Export in human readable format ' );
23
24
$ this ->setHelp (<<<HERE
24
25
Serializes the node (and if <info>--no-recurse</info> is false, the whole subgraph) at
25
26
<info>absPath</info> as an XML stream and outputs it to the supplied URI. The
@@ -58,12 +59,16 @@ public function execute(InputInterface $input, OutputInterface $output)
58
59
{
59
60
$ session = $ this ->getHelper ('phpcr ' )->getSession ();
60
61
$ file = $ input ->getArgument ('file ' );
62
+ $ pretty = $ input ->getOption ('pretty ' );
61
63
$ exportDocument = $ input ->getOption ('document ' );
64
+ $ dialog = $ this ->getHelper ('dialog ' );
62
65
63
66
if (file_exists ($ file )) {
64
- throw new \InvalidArgumentException (sprintf (
65
- 'File "%s" already exists. ' , $ file
66
- ));
67
+ $ res = $ dialog ->askConfirmation ($ output , 'File already exists, overwrite? ' );
68
+
69
+ if (false === $ res ) {
70
+ return ;
71
+ }
67
72
}
68
73
69
74
$ stream = fopen ($ file , 'w ' );
@@ -87,5 +92,13 @@ public function execute(InputInterface $input, OutputInterface $output)
87
92
}
88
93
89
94
fclose ($ stream );
95
+
96
+ if ($ pretty ) {
97
+ $ xml = new \DOMDocument (1.0 );
98
+ $ xml ->load ($ file );
99
+ $ xml ->preserveWhitespace = true ;
100
+ $ xml ->formatOutput = true ;
101
+ $ xml ->save ($ file );
102
+ }
90
103
}
91
104
}
0 commit comments