From 6a2f9870a7e7dfea187ff88ed2d4f991d11f723f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 11 Nov 2020 17:08:23 +0100 Subject: [PATCH] Warn when init is being used non-interactively without any args passed in, instead of silently overwriting the file --- src/Composer/Command/InitCommand.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 7ece80ca6..885c1ba4f 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -129,6 +129,12 @@ EOT return 1; } + } else { + if (json_encode($options) === '{"require":{}}') { + throw new \RuntimeException('You have to run this command in interactive mode, or specify at least some data using --name, --require, etc.'); + } + + $io->writeError('Writing composer.json'); } $file->write($options);