@@ -20,6 +20,7 @@ protected function configure()
2020 $ this ->addOption ('no-recurse ' , null , InputOption::VALUE_NONE , 'Do not recurse ' );
2121 $ this ->addOption ('skip-binary ' , null , InputOption::VALUE_NONE , 'Skip binary properties ' );
2222 $ this ->addOption ('document ' , null , InputOption::VALUE_NONE , 'Export the document view ' );
23+ $ this ->addOption ('pretty ' , null , InputOption::VALUE_NONE , 'Export in human readable format ' );
2324 $ this ->setHelp (<<<HERE
2425Serializes the node (and if <info>--no-recurse</info> is false, the whole subgraph) at
2526<info>absPath</info> as an XML stream and outputs it to the supplied URI. The
@@ -58,12 +59,20 @@ public function execute(InputInterface $input, OutputInterface $output)
5859 {
5960 $ session = $ this ->getHelper ('phpcr ' )->getSession ();
6061 $ file = $ input ->getArgument ('file ' );
62+ $ pretty = $ input ->getOption ('pretty ' );
6163 $ exportDocument = $ input ->getOption ('document ' );
64+ $ dialog = $ this ->getHelper ('dialog ' );
6265
6366 if (file_exists ($ file )) {
64- throw new \InvalidArgumentException (sprintf (
65- 'File "%s" already exists. ' , $ file
66- ));
67+ $ confirmed = true ;
68+
69+ if (false === $ input ->getOption ('no-interaction ' )) {
70+ $ confirmed = $ dialog ->askConfirmation ($ output , 'File already exists, overwrite? ' );
71+ }
72+
73+ if (false === $ confirmed ) {
74+ return ;
75+ }
6776 }
6877
6978 $ stream = fopen ($ file , 'w ' );
@@ -87,5 +96,13 @@ public function execute(InputInterface $input, OutputInterface $output)
8796 }
8897
8998 fclose ($ stream );
99+
100+ if ($ pretty ) {
101+ $ xml = new \DOMDocument (1.0 );
102+ $ xml ->load ($ file );
103+ $ xml ->preserveWhitespace = true ;
104+ $ xml ->formatOutput = true ;
105+ $ xml ->save ($ file );
106+ }
90107 }
91108}
0 commit comments