From 60d0ba8e4ca302504c71ee7262b5ed0ac2235092 Mon Sep 17 00:00:00 2001 From: Staormin Date: Tue, 5 Nov 2024 02:00:09 +0100 Subject: [PATCH] feat: improve output for user --- Makefile | 28 +++++++++++++++------------- src/Command/GenerateCommand.php | 24 ++++++++++++++++++++++++ src/Command/MergeCommand.php | 18 +++++++++++++++++- 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 6e318fc..f75238a 100644 --- a/Makefile +++ b/Makefile @@ -5,21 +5,21 @@ DOCKER_COMPOSE := docker-compose DOCKER_COMPOSE_RUN := $(DOCKER_COMPOSE) run --user=$(USER_ID) --rm --no-deps $(CONTAINER_NAME) help: ## Show this help. - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | grep -v '###' + @grep -F -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | grep -v '###' build: ## Build containers - DOCKER_BUILDKIT=1 docker-compose build --pull --build-arg USER_ID=$(USER_ID) --build-arg GROUP_ID=$(GROUP_ID) + @DOCKER_BUILDKIT=1 docker-compose build --pull --build-arg USER_ID=$(USER_ID) --build-arg GROUP_ID=$(GROUP_ID) ssh: ## Log into php container - $(DOCKER_COMPOSE_RUN) fish + @$(DOCKER_COMPOSE_RUN) fish install: copy-env destroy build install-vendor ## install project copy-env: - [ -f .env.local ] || cp .env.local-dist .env.local + @[ -f .env.local ] || cp .env.local-dist .env.local install-vendor: ## install vendor - $(DOCKER_COMPOSE_RUN) composer install + @$(DOCKER_COMPOSE_RUN) composer install destroy: ## Destroy containers $(DOCKER_COMPOSE) down -v --remove-orphans --rmi local @@ -28,23 +28,25 @@ destroy: ## Destroy containers cc: phpstan ecs ## Check code phpstan: ## Run PHPStan - echo "Running PHPStan" - $(DOCKER_COMPOSE_RUN) ./vendor/bin/phpstan + @echo "Running PHPStan" + @$(DOCKER_COMPOSE_RUN) ./vendor/bin/phpstan ecs: ## Run ECS - echo "Running ECS" - $(DOCKER_COMPOSE_RUN) ./vendor/bin/ecs + @echo "Running ECS" + @$(DOCKER_COMPOSE_RUN) ./vendor/bin/ecs merge-view: merge view-last ## Merge and view last merge: ## Playground - $(DOCKER_COMPOSE_RUN) bin/console app:merge + @$(DOCKER_COMPOSE_RUN) bin/console app:merge view-last: ## View last generation in imv - imv -f ./output/merge/$(shell ls -Art ./output/merge/ | tail -n 1) + @if [ -z "$(shell ls -Art ./output/merge/ | tail -n 1)" ]; then echo "No file to view"; exit 1; fi + @if [ -z "$(shell command -v imv 2> /dev/null)" ]; then echo "Please install imv see https://sr.ht/~exec64/imv/"; exit 1; fi + @imv -f ./output/merge/$(shell ls -Art ./output/merge/ | tail -n 1) generate: ## Generate from 1 to 9999 - $(DOCKER_COMPOSE_RUN) bin/console app:generate + @$(DOCKER_COMPOSE_RUN) bin/console app:generate fix-cs: ## Fix code style - $(DOCKER_COMPOSE_RUN) ./vendor/bin/ecs --fix \ No newline at end of file + @$(DOCKER_COMPOSE_RUN) ./vendor/bin/ecs --fix diff --git a/src/Command/GenerateCommand.php b/src/Command/GenerateCommand.php index 94b2835..558302f 100644 --- a/src/Command/GenerateCommand.php +++ b/src/Command/GenerateCommand.php @@ -9,6 +9,8 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\DependencyInjection\Attribute\Autowire; #[AsCommand( name: 'app:generate', @@ -16,20 +18,42 @@ )] final class GenerateCommand extends Command { + private SymfonyStyle $io; + + private string $outputDirectory; + public function __construct( private readonly CistercianNumberGeneratorService $cistercianNumberGeneratorService, + #[Autowire('%kernel.project_dir%')] + string $projectDirectory, ) { parent::__construct(); + $this->outputDirectory = $projectDirectory . '/output/CistercianNumbers'; } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->io = new SymfonyStyle($input, $output); + + $this->io->title('Generating Cistercian numbers from 1 to 9999'); + $numbers = range(1, 9999); + $this->io->progressStart(count($numbers)); + foreach ($numbers as $number) { $this->cistercianNumberGeneratorService->generateCistercianNumber($number); + $this->io->progressAdvance(); } + $this->io->progressFinish(); + + $outputDirectoryForDisplay = implode('/', array_slice(explode('/', $this->outputDirectory), -2)); + + $this->io->success( + sprintf('Cistercian numbers generated successfully! You can find them in %s/', $outputDirectoryForDisplay) + ); + return Command::SUCCESS; } } diff --git a/src/Command/MergeCommand.php b/src/Command/MergeCommand.php index 500c527..3cf0035 100644 --- a/src/Command/MergeCommand.php +++ b/src/Command/MergeCommand.php @@ -13,6 +13,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\DependencyInjection\Attribute\Autowire; /** @@ -31,6 +32,8 @@ final class MergeCommand extends Command private string $outputDirectory; + private SymfonyStyle $io; + public function __construct( private readonly CistercianNumberGeneratorService $cistercianNumberGeneratorService, #[Autowire('%env(CISTERCIAN_NUMBER_GENERATOR_SEGMENT_LENGTH)%')] @@ -50,6 +53,10 @@ public function __construct( protected function execute(InputInterface $input, OutputInterface $output): int { + $this->io = new SymfonyStyle($input, $output); + + $this->io->title('Cistercian Merge Command'); + FileUtil::ensureDirectoryExists($this->outputDirectory); $numbers = [ @@ -66,6 +73,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int [8030, 59], ]; + $this->io->table(['Numbers'], $numbers); + + $this->io->text('Generating images...'); + $this->generateOneLineDifference($numbers); $this->generateOneLineSideToSideUnmerged($numbers); $this->generateOneLineSideToSideMerged($numbers); @@ -75,9 +86,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->generateMultipleLinesUnmergedWithShiftHalfSpace($numbers); $this->generateMultipleLinesMergedWithShiftFullSpace($numbers); $this->generateMultipleLinesMergedWithShiftHalfSpace($numbers); - $this->generateTruncatedOutput(); + $outputDirectoryForDisplay = implode('/', array_slice(explode('/', $this->outputDirectory), -3)); + + $this->io->success( + sprintf('Images generated successfully! You can find them in %s/', $outputDirectoryForDisplay) + ); + return Command::SUCCESS; }