@@ -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,16 @@ 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+ $ res = $ dialog ->askConfirmation ($ output , 'File already exists, overwrite? ' );
68+
69+ if (false === $ res ) {
70+ return ;
71+ }
6772 }
6873
6974 $ stream = fopen ($ file , 'w ' );
@@ -87,5 +92,13 @@ public function execute(InputInterface $input, OutputInterface $output)
8792 }
8893
8994 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+ }
90103 }
91104}
0 commit comments