@@ -41,9 +41,11 @@ final class AddPrefixCommand extends Command
4141 /** @internal */
4242 const STOP_ON_FAILURE_OPT = 'stop-on-failure ' ;
4343 /** @internal */
44- const CONFIG_FILE = 'config ' ;
44+ const CONFIG_FILE_OPT = 'config ' ;
4545 /** @internal */
4646 const CONFIG_FILE_DEFAULT = 'scoper.inc.php ' ;
47+ /** @internal */
48+ const WORKING_DIR_OPT = 'working-dir ' ;
4749
4850 private $ fileSystem ;
4951 private $ handle ;
@@ -98,7 +100,7 @@ protected function configure()
98100 'Stops on failure. '
99101 )
100102 ->addOption (
101- self ::CONFIG_FILE ,
103+ self ::CONFIG_FILE_OPT ,
102104 'c ' ,
103105 InputOption::VALUE_REQUIRED ,
104106 sprintf (
@@ -107,6 +109,13 @@ protected function configure()
107109 ),
108110 null
109111 )
112+ ->addOption (
113+ self ::WORKING_DIR_OPT ,
114+ 'd ' ,
115+ InputOption::VALUE_REQUIRED ,
116+ 'If specified, use the given directory as working directory. ' ,
117+ null
118+ )
110119 ;
111120 }
112121
@@ -117,6 +126,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
117126 {
118127 $ io = new SymfonyStyle ($ input , $ output );
119128
129+ $ workingDir = $ input ->getOption (self ::WORKING_DIR_OPT );
130+
131+ if (null !== $ workingDir ) {
132+ chdir ($ workingDir );
133+ }
134+
120135 $ this ->validatePrefix ($ input );
121136 $ this ->validatePaths ($ input );
122137 $ this ->validateOutputDir ($ input , $ io );
@@ -264,7 +279,7 @@ private function validateOutputDir(InputInterface $input, OutputStyle $io)
264279
265280 private function retrieveConfig (InputInterface $ input , OutputStyle $ io ): Configuration
266281 {
267- $ configFile = $ input ->getOption (self ::CONFIG_FILE );
282+ $ configFile = $ input ->getOption (self ::CONFIG_FILE_OPT );
268283
269284 if (null === $ configFile ) {
270285 $ configFile = $ this ->makeAbsolutePath (self ::CONFIG_FILE_DEFAULT );
0 commit comments