1818use phpDocumentor \Guides \Handlers \RenderCommand ;
1919use phpDocumentor \Guides \Intersphinx \InventoryRepository ;
2020use phpDocumentor \Guides \Nodes \ProjectNode ;
21+ use phpDocumentor \Guides \Settings \ProjectSettings ;
2122use phpDocumentor \Guides \Settings \SettingsManager ;
2223use phpDocumentor \Guides \Twig \Theme \ThemeManager ;
2324use RuntimeException ;
@@ -55,35 +56,30 @@ public function __construct(
5556 'input ' ,
5657 InputArgument::OPTIONAL ,
5758 'Directory to read for files ' ,
58- 'docs ' ,
5959 );
6060 $ this ->addArgument (
6161 'output ' ,
6262 InputArgument::OPTIONAL ,
6363 'Directory to read for files ' ,
64- 'output ' ,
6564 );
6665
6766 $ this ->addOption (
6867 'input-format ' ,
6968 null ,
7069 InputOption::VALUE_REQUIRED ,
7170 'Format of the input can be RST, or Markdown ' ,
72- 'rst ' ,
7371 );
7472 $ this ->addOption (
7573 'output-format ' ,
7674 null ,
7775 InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY ,
78- 'Format of the input can be html ' ,
79- ['html ' ],
76+ 'Format of the input can be html and or intersphinx ' ,
8077 );
8178 $ this ->addOption (
8279 'log-path ' ,
8380 null ,
8481 InputOption::VALUE_REQUIRED ,
8582 'Write log to this path ' ,
86- 'php://stder ' ,
8783 );
8884 $ this ->addOption (
8985 'fail-on-log ' ,
@@ -104,40 +100,70 @@ public function __construct(
104100 null ,
105101 InputOption::VALUE_NEGATABLE ,
106102 'Whether to show a progress bar ' ,
107- true ,
108103 );
109104 }
110105
106+ private function getSettingsOverridenWithInput (InputInterface $ input ): ProjectSettings
107+ {
108+ $ settings = $ this ->settingsManager ->getProjectSettings ();
109+ if ($ input ->getArgument ('input ' )) {
110+ $ settings ->setInput ((string ) $ input ->getArgument ('input ' ));
111+ }
112+
113+ if ($ input ->getArgument ('output ' )) {
114+ $ settings ->setOutput ((string ) $ input ->getArgument ('output ' ));
115+ }
116+
117+ if ($ input ->getOption ('log-path ' )) {
118+ $ settings ->setLogPath ((string ) $ input ->getOption ('log-path ' ));
119+ }
120+
121+ if ($ input ->getOption ('fail-on-log ' )) {
122+ $ settings ->setFailOnError (true );
123+ }
124+
125+ if ($ input ->getOption ('input-format ' )) {
126+ $ settings ->setInputFormat ((string ) $ input ->getOption ('input-format ' ));
127+ }
128+
129+ if (count ($ input ->getOption ('output-format ' )) > 0 ) {
130+ $ settings ->setOutputFormats ($ input ->getOption ('output-format ' ));
131+ }
132+
133+ if ($ input ->getOption ('theme ' )) {
134+ $ settings ->setTheme ((string ) $ input ->getOption ('theme ' ));
135+ }
136+
137+ return $ settings ;
138+ }
139+
111140 protected function execute (InputInterface $ input , OutputInterface $ output ): int
112141 {
113- $ inputDir = $ this ->getAbsolutePath ((string ) ($ input ->getArgument ('input ' ) ?? '' ));
142+ $ settings = $ this ->getSettingsOverridenWithInput ($ input );
143+ $ inputDir = $ this ->getAbsolutePath ($ settings ->getInput ());
114144 if (!is_dir ($ inputDir )) {
115145 throw new RuntimeException (sprintf ('Input directory "%s" was not found! ' . "\n" .
116146 'Run "vendor/bin/guides -h" for information on how to configure this command. ' , $ inputDir ));
117147 }
118148
119- $ settings = $ this ->settingsManager ->getProjectSettings ();
120-
121149 $ projectNode = new ProjectNode (
122150 $ settings ->getTitle () === '' ? null : $ settings ->getTitle (),
123151 $ settings ->getVersion () === '' ? null : $ settings ->getVersion (),
124152 );
125153 $ this ->inventoryRepository ->initialize ($ settings ->getInventories ());
126154
127- $ outputDir = $ this ->getAbsolutePath (( string ) ( $ input -> getArgument ( ' output ' ) ?? '' ));
128- $ sourceFileSystem = new Filesystem (new Local ($ input -> getArgument ( ' input ' )));
155+ $ outputDir = $ this ->getAbsolutePath ($ settings -> getOutput ( ));
156+ $ sourceFileSystem = new Filesystem (new Local ($ settings -> getInput ( )));
129157 $ sourceFileSystem ->addPlugin (new Finder ());
130- $ logPath = $ input -> getOption ( ' log-path ' ) ?? ' php://stder ' ;
158+ $ logPath = $ settings -> getLogPath () ;
131159 if ($ logPath === 'php://stder ' ) {
132160 $ this ->logger ->pushHandler (new ErrorLogHandler (ErrorLogHandler::OPERATING_SYSTEM , Logger::WARNING ));
133161 } else {
134162 $ this ->logger ->pushHandler (new StreamHandler ($ logPath . '/warning.log ' , Logger::WARNING ));
135163 $ this ->logger ->pushHandler (new StreamHandler ($ logPath . '/error.log ' , Logger::ERROR ));
136164 }
137165
138- $ failOnLog = $ input ->getOption ('fail-on-log ' ) ?? false ;
139-
140- if ($ failOnLog ) {
166+ if ($ settings ->isFailOnError ()) {
141167 $ spyProcessor = new SpyProcessor ();
142168 $ this ->logger ->pushProcessor ($ spyProcessor );
143169 }
@@ -146,28 +172,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int
146172 new ParseDirectoryCommand (
147173 $ sourceFileSystem ,
148174 '' ,
149- $ input -> getOption ( ' input-format ' ),
175+ $ settings -> getInputFormat ( ),
150176 $ projectNode ,
151177 ),
152178 );
153179
154- $ theme = $ input ->getOption ('theme ' );
155- if ($ theme ) {
156- $ settings ->setTheme ($ theme );
157- }
180+
158181
159182 $ this ->themeManager ->useTheme ($ settings ->getTheme ());
160183
161184 $ documents = $ this ->commandBus ->handle (new CompileDocumentsCommand ($ documents , new CompilerContext ($ projectNode )));
162185
163186 $ destinationFileSystem = new Filesystem (new Local ($ outputDir ));
164187
165- $ outputFormats = $ input -> getOption ( ' output-format ' );
188+ $ outputFormats = $ settings -> getOutputFormats ( );
166189
167190 foreach ($ outputFormats as $ format ) {
168191 $ progressBar = null ;
169192
170- if ($ output instanceof ConsoleOutputInterface && $ input -> getOption ( ' progress ' )) {
193+ if ($ output instanceof ConsoleOutputInterface && $ settings -> isShowProgressBar ( )) {
171194 $ progressBar = new ProgressBar ($ output ->section ());
172195 }
173196
@@ -195,7 +218,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
195218 'Successfully placed ' . (is_countable ($ documents ) ? count ($ documents ) : 0 ) . ' rendered ' . $ formatsText . ' files into ' . $ outputDir ,
196219 );
197220
198- if ($ failOnLog && $ spyProcessor ->hasBeenCalled ()) {
221+ if ($ settings -> isFailOnError () && $ spyProcessor ->hasBeenCalled ()) {
199222 return Command::FAILURE ;
200223 }
201224
0 commit comments