3434 * @author Joshua Estes <[email protected] > 3535 * @author Jordi Boggiano <[email protected] > 3636 */
37- class ConfigCommand extends BaseCommand
37+ class ConfigCommand extends BaseConfigCommand
3838{
3939 /**
4040 * List of additional configurable package-properties
@@ -56,21 +56,6 @@ class ConfigCommand extends BaseCommand
5656 'extra ' ,
5757 ];
5858
59- /**
60- * @var Config
61- */
62- protected $ config ;
63-
64- /**
65- * @var JsonFile
66- */
67- protected $ configFile ;
68-
69- /**
70- * @var JsonConfigSource
71- */
72- protected $ configSource ;
73-
7459 /**
7560 * @var JsonFile
7661 */
@@ -176,52 +161,17 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
176161 {
177162 parent ::initialize ($ input , $ output );
178163
179- if ($ input ->getOption ('global ' ) && null !== $ input ->getOption ('file ' )) {
180- throw new \RuntimeException ('--file and --global can not be combined ' );
181- }
182-
183- $ io = $ this ->getIO ();
184- $ this ->config = Factory::createConfig ($ io );
185-
186- // When using --global flag, set baseDir to home directory for correct absolute path resolution
187- if ($ input ->getOption ('global ' )) {
188- $ this ->config ->setBaseDir ($ this ->config ->get ('home ' ));
189- }
190-
191- $ configFile = $ this ->getComposerConfigFile ($ input , $ this ->config );
192-
193- // Create global composer.json if this was invoked using `composer global config`
194- if (
195- ($ configFile === 'composer.json ' || $ configFile === './composer.json ' )
196- && !file_exists ($ configFile )
197- && realpath (Platform::getCwd ()) === realpath ($ this ->config ->get ('home ' ))
198- ) {
199- file_put_contents ($ configFile , "{ \n} \n" );
200- }
201-
202- $ this ->configFile = new JsonFile ($ configFile , null , $ io );
203- $ this ->configSource = new JsonConfigSource ($ this ->configFile );
204-
205164 $ authConfigFile = $ this ->getAuthConfigFile ($ input , $ this ->config );
206165
207- $ this ->authConfigFile = new JsonFile ($ authConfigFile , null , $ io );
166+ $ this ->authConfigFile = new JsonFile ($ authConfigFile , null , $ this -> getIO () );
208167 $ this ->authConfigSource = new JsonConfigSource ($ this ->authConfigFile , true );
209168
210169 // Initialize the global file if it's not there, ignoring any warnings or notices
211- if ($ input ->getOption ('global ' ) && !$ this ->configFile ->exists ()) {
212- touch ($ this ->configFile ->getPath ());
213- $ this ->configFile ->write (['config ' => new \ArrayObject ]);
214- Silencer::call ('chmod ' , $ this ->configFile ->getPath (), 0600 );
215- }
216170 if ($ input ->getOption ('global ' ) && !$ this ->authConfigFile ->exists ()) {
217171 touch ($ this ->authConfigFile ->getPath ());
218172 $ this ->authConfigFile ->write (['bitbucket-oauth ' => new \ArrayObject , 'github-oauth ' => new \ArrayObject , 'gitlab-oauth ' => new \ArrayObject , 'gitlab-token ' => new \ArrayObject , 'http-basic ' => new \ArrayObject , 'bearer ' => new \ArrayObject , 'forgejo-token ' => new \ArrayObject ()]);
219173 Silencer::call ('chmod ' , $ this ->authConfigFile ->getPath (), 0600 );
220174 }
221-
222- if (!$ this ->configFile ->exists ()) {
223- throw new \RuntimeException (sprintf ('File "%s" cannot be found in the current directory ' , $ configFile ));
224- }
225175 }
226176
227177 /**
@@ -1035,29 +985,6 @@ protected function listConfiguration(array $contents, array $rawContents, Output
1035985 }
1036986 }
1037987
1038- /**
1039- * Get the local composer.json, global config.json, or the file passed by the user
1040- */
1041- private function getComposerConfigFile (InputInterface $ input , Config $ config ): string
1042- {
1043- return $ input ->getOption ('global ' )
1044- ? ($ config ->get ('home ' ) . '/config.json ' )
1045- : ($ input ->getOption ('file ' ) ?: Factory::getComposerFile ())
1046- ;
1047- }
1048-
1049- /**
1050- * Get the local auth.json or global auth.json, or if the user passed in a file to use,
1051- * the corresponding auth.json
1052- */
1053- private function getAuthConfigFile (InputInterface $ input , Config $ config ): string
1054- {
1055- return $ input ->getOption ('global ' )
1056- ? ($ config ->get ('home ' ) . '/auth.json ' )
1057- : dirname ($ this ->getComposerConfigFile ($ input , $ config )) . '/auth.json '
1058- ;
1059- }
1060-
1061988 /**
1062989 * Suggest setting-keys, while taking given options in account.
1063990 */
0 commit comments