From 0db3d19cc4641d1eaba046c82b9a46548968ecc8 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Mon, 26 Aug 2024 14:38:25 +0000 Subject: [PATCH] finally dropped (definitively) legacy commands --- bin/box-manifest | 4 - docs/README.md | 14 +- docs/Tutorial/generate-manifest-files.md | 4 +- docs/UseCases/ConsoleTextFormat.md | 6 +- docs/UseCases/CustomFormat.md | 6 +- docs/UseCases/DecoratedTextFormat.md | 6 +- docs/UseCases/PlainTextFormat.md | 6 +- docs/UseCases/SBomJsonFormat.md | 6 +- docs/UseCases/SBomXmlFormat.md | 6 +- docs/build-your-manifests.md | 12 +- docs/build-your-stub.md | 12 +- src/Composer/PostInstallStrategy.php | 5 +- src/Console/Command/ManifestBuild.php | 197 ----------------------- src/Console/Command/ManifestStub.php | 187 --------------------- 14 files changed, 48 insertions(+), 423 deletions(-) delete mode 100644 src/Console/Command/ManifestBuild.php delete mode 100644 src/Console/Command/ManifestStub.php diff --git a/bin/box-manifest b/bin/box-manifest index 272cf40..a591a1a 100755 --- a/bin/box-manifest +++ b/bin/box-manifest @@ -9,8 +9,6 @@ use Bartlett\BoxManifest\Console\Application; use Bartlett\BoxManifest\Console\Command\Inspect; -use Bartlett\BoxManifest\Console\Command\ManifestBuild; -use Bartlett\BoxManifest\Console\Command\ManifestStub; use Bartlett\BoxManifest\Console\Command\Make; gc_disable(); // performance boost @@ -18,8 +16,6 @@ gc_disable(); // performance boost require_once dirname(__DIR__) . '/autoload.php'; $application = new Application(); -$application->add(new ManifestBuild()); -$application->add(new ManifestStub()); $application->add(new Make()); $application->add(new Inspect()); $application->run(); diff --git a/docs/README.md b/docs/README.md index 1f2d883..23ab452 100644 --- a/docs/README.md +++ b/docs/README.md @@ -12,13 +12,13 @@ ## Features at a glance -| Feature | Legacy Command | Pipeline Command | -|-----------------------------------------------------------------|:------------------------:|:------------------------------------------:| -| Creates a manifest of your software components and dependencies | `build` :material-check: | `make build` [^1] :material-check: | -| Generates a stub for your manifest application | `stub` :material-check: | `make stub` :material-check: | -| Generates a final BOX configuration file | :material-close: | `make configure` :material-check: | -| Compiles an application into a PHAR | :material-close: | `make compile` [^2] :material-check: | -| Adds custom action easily | :material-close: | `make MyCustomStage` [^3] :material-check: | +| Feature | Legacy Command | Pipeline Command | +|-----------------------------------------------------------------|:---------------------------------:|:------------------------------------------:| +| Creates a manifest of your software components and dependencies | `manifest:build` :material-check: | `make build` [^1] :material-check: | +| Generates a stub for your manifest application | `manifest:stub` :material-check: | `make stub` :material-check: | +| Generates a final BOX configuration file | :material-close: | `make configure` :material-check: | +| Compiles an application into a PHAR | :material-close: | `make compile` [^2] :material-check: | +| Adds custom action easily | :material-close: | `make MyCustomStage` [^3] :material-check: | [^1]: You can create multiple manifest on same pipeline command, while legacy command allowed only once at a time. [^2]: Easy launcher of [BOX project][box-project] binary command (`vendor/bin/box`) diff --git a/docs/Tutorial/generate-manifest-files.md b/docs/Tutorial/generate-manifest-files.md index 24e14eb..698d818 100644 --- a/docs/Tutorial/generate-manifest-files.md +++ b/docs/Tutorial/generate-manifest-files.md @@ -96,10 +96,10 @@ In [Part 3](./generate-box-json-dist.md) of the tutorial, we will see how to dyn Then finally, compile your PHP Archive with `box compile` command, the metadata contents is only used as fallback contents in case you forgot to declare `files-bin` entries. -=== "Command" +=== "Pipeline Command" ```shell - vendor/bin/box compile --config app-fixtures.box.json.dist + box-manifest make --config app-fixtures.box.json.dist -vv compile ``` === "Output" diff --git a/docs/UseCases/ConsoleTextFormat.md b/docs/UseCases/ConsoleTextFormat.md index 452c347..0cf52f7 100644 --- a/docs/UseCases/ConsoleTextFormat.md +++ b/docs/UseCases/ConsoleTextFormat.md @@ -8,10 +8,14 @@ ## :material-numeric-1-box: With legacy command +> [!WARNING] +> +> We've dropped legacy commands, but we still show syntax usage to help Users of version 3 for a smooth migration. + === "Command" ```shell - box-manifest build -f console-table + box-manifest manifest:build -f console ``` === "Output" diff --git a/docs/UseCases/CustomFormat.md b/docs/UseCases/CustomFormat.md index 4f006e0..3cc2ba2 100644 --- a/docs/UseCases/CustomFormat.md +++ b/docs/UseCases/CustomFormat.md @@ -71,10 +71,14 @@ either by your autoloader or with bootstrap helper feature (see `--bootstrap|-b` ## :material-numeric-1-box: With legacy command +> [!WARNING] +> +> We've dropped legacy commands, but we still show syntax usage to help Users of version 3 for a smooth migration. + === "Command" ```shell - box-manifest build -f MyCustomFormat -b bootstrap.php + box-manifest manifest:build -f MyCustomFormat -b bootstrap.php ``` === "Output" diff --git a/docs/UseCases/DecoratedTextFormat.md b/docs/UseCases/DecoratedTextFormat.md index ecd02b1..5d03c49 100644 --- a/docs/UseCases/DecoratedTextFormat.md +++ b/docs/UseCases/DecoratedTextFormat.md @@ -8,10 +8,14 @@ ## :material-numeric-1-box: With legacy command +> [!WARNING] +> +> We've dropped legacy commands, but we still show syntax usage to help Users of version 3 for a smooth migration. + === "Command" ```shell - box-manifest build -f console-style + box-manifest manifest:build -f ansi ``` === "Output" diff --git a/docs/UseCases/PlainTextFormat.md b/docs/UseCases/PlainTextFormat.md index ac10dc4..0f063e3 100644 --- a/docs/UseCases/PlainTextFormat.md +++ b/docs/UseCases/PlainTextFormat.md @@ -8,10 +8,14 @@ ## :material-numeric-1-box: With legacy command +> [!WARNING] +> +> We've dropped legacy commands, but we still show syntax usage to help Users of version 3 for a smooth migration. + === "Command" ```shell - box-manifest build -f plain + box-manifest manifest:build -f plain ``` === "Output" diff --git a/docs/UseCases/SBomJsonFormat.md b/docs/UseCases/SBomJsonFormat.md index 2f0a849..5d6ac30 100644 --- a/docs/UseCases/SBomJsonFormat.md +++ b/docs/UseCases/SBomJsonFormat.md @@ -8,10 +8,14 @@ ## :material-numeric-1-box: With legacy command +> [!WARNING] +> +> We've dropped legacy commands, but we still show syntax usage to help Users of version 3 for a smooth migration. + === "Command" ```shell - box-manifest build -f sbom-json + box-manifest manifest:build -f sbom-json ``` === "Output" diff --git a/docs/UseCases/SBomXmlFormat.md b/docs/UseCases/SBomXmlFormat.md index b6b8939..448efd7 100644 --- a/docs/UseCases/SBomXmlFormat.md +++ b/docs/UseCases/SBomXmlFormat.md @@ -8,10 +8,14 @@ ## :material-numeric-1-box: With legacy command +> [!WARNING] +> +> We've dropped legacy commands, but we still show syntax usage to help Users of version 3 for a smooth migration. + === "Command" ```shell - box-manifest build -f sbom-xml + box-manifest manifest:build -f sbom-xml ``` === "Output" diff --git a/docs/build-your-manifests.md b/docs/build-your-manifests.md index a543dc9..66af78c 100644 --- a/docs/build-your-manifests.md +++ b/docs/build-your-manifests.md @@ -1,15 +1,9 @@ # Build your manifests -To help Users in a smooth usage migration, we have not yet removed legacy commands. - -- `manifest:build` now an alias of `build` command - -So, we are show here both usages with legacy and new pipeline commands ! - -> [!CAUTION] +> [!WARNING] > -> We recommend to learn the new pipeline syntax, because legacy commands will be dropped in next version 4.1 +> We've dropped legacy commands, but we still show syntax usage to help Users of version 3 for a smooth migration. === "Pipeline Command" @@ -20,7 +14,7 @@ So, we are show here both usages with legacy and new pipeline commands ! === "Legacy Command" ```shell - box-manifest build -f plain -o manifest.txt + box-manifest manifest:build -f plain -o manifest.txt ``` This will create, the `manifest.txt` file, with a plain text format of your dependencies inventory. diff --git a/docs/build-your-stub.md b/docs/build-your-stub.md index 4735e4a..b14660c 100644 --- a/docs/build-your-stub.md +++ b/docs/build-your-stub.md @@ -1,15 +1,9 @@ # Build your stub -To help Users in a smooth usage migration, we have not yet removed legacy commands. - -- `manifest:stub` now an alias of `stub` command - -So, we are show here both usages with legacy and new pipeline commands ! - -> [!CAUTION] +> [!WARNING] > -> We recommend to learn the new pipeline syntax, because legacy commands will be dropped in next version 4.1 +> We've dropped legacy commands, but we still show syntax usage to help Users of version 3 for a smooth migration. === "Pipeline Command" @@ -20,7 +14,7 @@ So, we are show here both usages with legacy and new pipeline commands ! === "Legacy Command" ```shell - box-manifest stub -r console-table.txt -r manifest.txt -r sbom.json -o stub.php + box-manifest manifest:stub -r console-table.txt -r manifest.txt -r sbom.json -o stub.php ``` This will create, the `stub.php` file, where manifests order is preserved and deterministic. diff --git a/src/Composer/PostInstallStrategy.php b/src/Composer/PostInstallStrategy.php index 7f4aad1..d26b492 100644 --- a/src/Composer/PostInstallStrategy.php +++ b/src/Composer/PostInstallStrategy.php @@ -8,6 +8,7 @@ namespace Bartlett\BoxManifest\Composer; use Bartlett\BoxManifest\Console\Application; +use Bartlett\BoxManifest\Console\Command\Make; use Bartlett\BoxManifest\Console\Command\ManifestBuild; use Bartlett\BoxManifest\Helper\BoxHelper; @@ -94,14 +95,14 @@ public static function postUpdate(Event $event): void false ); - $inputDefinition = (new ManifestBuild())->getDefinition(); + $inputDefinition = (new Make())->getDefinition(); $map = $config->getFileMapper()->getMap(); foreach ($map as $mapFile) { foreach ($mapFile as $source => $target) { if (str_starts_with($target, '.box.manifests/')) { - $arrayInput = new ArrayInput(['--format' => 'auto', '--output-file' => $source], $inputDefinition); + $arrayInput = new ArrayInput(['--output-format' => 'auto', '--output-file' => $source], $inputDefinition); $boxIO = new IO($arrayInput, new NullOutput()); $manifest = $factory->build(new ManifestOptions($boxIO)); diff --git a/src/Console/Command/ManifestBuild.php b/src/Console/Command/ManifestBuild.php deleted file mode 100644 index e647051..0000000 --- a/src/Console/Command/ManifestBuild.php +++ /dev/null @@ -1,197 +0,0 @@ -%command.name% command will generate a manifest of your application. - HELP; - - protected function configure(): void - { - $options = [ - new InputOption( - ManifestOptions::BOOTSTRAP_OPTION, - 'b', - InputOption::VALUE_REQUIRED, - 'A PHP script that is included before execution', - ), - new InputOption( - ManifestOptions::FORMAT_OPTION, - 'f', - InputOption::VALUE_REQUIRED, - 'Format of the output: ' . implode(', ', array_column(ManifestFormat::cases(), 'value')) . '', - ManifestFormat::auto->value - ), - new InputOption( - ManifestOptions::SBOM_SPEC_OPTION, - 's', - InputOption::VALUE_REQUIRED, - 'SBOM specification version: ' . implode(', ', array_column(Version::cases(), 'value')) . '', - Version::v1dot6->value - ), - new InputOption( - ManifestOptions::OUTPUT_OPTION, - 'o', - InputOption::VALUE_REQUIRED, - 'Write results to file (default to standard output)' - ), - ]; - - $this->setName(self::NAME) - ->setAliases(['manifest:' . self::NAME]) // give a chance to keep migration from v3 to v4 still working (but consider it as @deprecated) - ->setDescription('Creates a manifest of your software components and dependencies.') - ->setDefinition( - new InputDefinition( - array_merge((new BoxHelper())->getBoxConfigOptions(), $options) - ) - ) - ->setHelp(self::HELP) - ; - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $startTime = microtime(true); - - $io = new IO($input, $output); - - $options = new ManifestOptions($io); - - $bootstrap = $options->getBootstrap(); - $outputFile = $options->getOutputFile(); - $rawFormat = $options->getFormat(true); - $format = $options->getFormat(); - $sbomSpec = $options->getSbomSpec(); - - /** @var BoxHelper $boxHelper */ - $boxHelper = $this->getHelper(BoxHelper::NAME); - - /** @var DebugFormatterHelper $debugFormatter */ - $debugFormatter = $this->getHelper('debug_formatter'); - - $pid = uniqid(); - - if ($io->isVeryVerbose()) { - $io->write( - $debugFormatter->start( - $pid, - sprintf('Generating manifest in %s format', $options->getFormatDisplay()), - 'STARTED' - ) - ); - } - - if (!empty($bootstrap) && file_exists($bootstrap)) { - if ($io->isVeryVerbose()) { - $io->write( - $debugFormatter->progress( - $pid, - sprintf('Bootstrapped file "%s"', $bootstrap), - false, - 'STARTED' - ) - ); - } - include $bootstrap; - } - - $config = $boxHelper->getBoxConfiguration( - $io->withOutput(new NullOutput()), - true, - $io->getTypedOption(BoxHelper::NO_CONFIG_OPTION)->asBoolean() - ); - - $configFile = $config->getConfigurationFile(); - - if (null !== $configFile && $io->isVeryVerbose()) { - $io->write( - $debugFormatter->progress( - $pid, - sprintf((!empty($bootstrap) ? PHP_EOL : '') . 'Loading the configuration file "%s"', $configFile), - false, - 'STARTED' - ) - ); - } - - $boxManifestVersion = $this->getApplication()?->getVersion() ? : '@dev'; - $factory = new ManifestFactory($config, $output->isDecorated(), $boxHelper->getBoxVersion(), $boxManifestVersion, false); - $manifest = $factory->build($options) ?? ''; - - if (empty($outputFile)) { - $io->writeln($manifest); - $message = 'Writing results to standard output'; - } else { - // @phpstan-ignore argument.type - $stream = new StreamOutput(fopen($outputFile, 'w')); - if (ManifestFormat::consoleStyle === $format) { - $stream->setDecorated(true); - } - $stream->write($manifest); - fclose($stream->getStream()); - - $message = sprintf('Writing manifest to file "%s"', realpath($outputFile)); - } - - if ($io->isVeryVerbose()) { - $io->write( - $debugFormatter->stop($pid, $message, true, 'RESPONSE') - ); - $io->write( - $debugFormatter->stop( - $pid, - 'Process elapsed time ' . Helper::formatTime(microtime(true) - $startTime), - true, - 'FINISHED' - ) - ); - } - - return Command::SUCCESS; - } -} diff --git a/src/Console/Command/ManifestStub.php b/src/Console/Command/ManifestStub.php deleted file mode 100644 index 94c4b25..0000000 --- a/src/Console/Command/ManifestStub.php +++ /dev/null @@ -1,187 +0,0 @@ -%command.name% command will generate a stub of your manifest application. - HELP; - - protected function configure(): void - { - $options = [ - new InputOption( - ManifestOptions::TEMPLATE_OPTION, - 't', - InputOption::VALUE_REQUIRED, - 'PHP template file to customize the stub' - ), - new InputOption( - ManifestOptions::RESOURCE_OPTION, - 'r', - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'File(s) generated by the box-manifest binary command' - ), - new InputOption( - ManifestOptions::OUTPUT_OPTION, - 'o', - InputOption::VALUE_REQUIRED, - 'Write results to file (default to standard output)' - ), - ]; - - $this->setName(self::NAME) - ->setAliases(['manifest:' . self::NAME]) // give a chance to keep migration from v3 to v4 still working (but consider it as @deprecated) - ->setDescription('Generates a stub for your manifest application.') - ->setDefinition( - new InputDefinition( - array_merge((new BoxHelper())->getBoxConfigOptions(), $options) - ) - ) - ->setHelp(self::HELP) - ; - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $startTime = microtime(true); - - $io = new IO($input, $output); - - /** @var DebugFormatterHelper $debugFormatter */ - $debugFormatter = $this->getHelper('debug_formatter'); - - $templateFile = $io->getTypedOption(ManifestOptions::TEMPLATE_OPTION)->asNullableString(); - - $pid = uniqid(); - - if ($io->isVeryVerbose()) { - $templatePath = $templateFile ? : dirname(__DIR__, 3) . '/resources/default_stub.template'; - $io->write( - $debugFormatter->start($pid, 'Generating stub ' . sprintf('from template "%s"', $templatePath), 'STARTED') - ); - } - - /** @var BoxHelper $boxHelper */ - $boxHelper = $this->getHelper(BoxHelper::NAME); - - /** @var ManifestHelper $manifestHelper */ - $manifestHelper = $this->getHelper(ManifestHelper::NAME); - - $config = $boxHelper->getBoxConfiguration( - $io->withOutput(new NullOutput()), - true, - $io->getTypedOption(BoxHelper::NO_CONFIG_OPTION)->asBoolean() - ); - - $configPath = $config->getConfigurationFile(); - - if ($io->isVeryVerbose()) { - $message = $configPath - ? sprintf('Using the configuration file "%s"', $configPath) - : 'Ignoring any configuration file' - ; - $io->writeln( - $debugFormatter->progress($pid, $message, false, 'STARTED') - ); - } - - $stubGenerator = $manifestHelper->getStubGenerator( - $templateFile, - $io->getTypedOption(ManifestOptions::RESOURCE_OPTION)->asNonEmptyStringList(), - $config->getFileMapper()->getMap(), - $this->getApplication()?->getVersion() - ); - - if ($configPath) { - /** @var null|non-empty-string $shebang */ - $shebang = $config->getShebang(); - - $banner = $config->getStubBannerContents(); - - $index = $config->hasMainScript() - ? str_replace($config->getBasePath() . '/', '', $config->getMainScriptPath()) - : null; - $alias = $config->getAlias(); - - $stub = $stubGenerator->generateStub( - $alias, - $banner, - $index, - $config->isInterceptFileFuncs(), - $shebang, - $config->checkRequirements() - ); - } else { - $stub = $stubGenerator->generateStub(null, null, null, false, null, false); - } - - $outputFile = $io->getTypedOption(ManifestOptions::OUTPUT_OPTION)->asNullableString(); - - if (empty($outputFile)) { - $output->writeln($stub); - $message = 'Writing stub PHP code to standard output'; - } else { - // @phpstan-ignore argument.type - $stream = new StreamOutput(fopen($outputFile, 'w')); - $stream->write($stub); - fclose($stream->getStream()); - - $message = sprintf('Writing stub PHP code to file "%s"', realpath($outputFile)); - } - - if ($io->isVeryVerbose()) { - $io->write( - $debugFormatter->stop($pid, $message, true, 'RESPONSE') - ); - $io->write( - $debugFormatter->stop( - $pid, - 'Process elapsed time ' . Helper::formatTime(microtime(true) - $startTime), - true, - 'FINISHED' - ) - ); - } - - return Command::SUCCESS; - } -}