Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve output for user #4

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
@$(DOCKER_COMPOSE_RUN) ./vendor/bin/ecs --fix
24 changes: 24 additions & 0 deletions src/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,51 @@
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',
description: 'Generate cistercian numbers from 1 to 9999',
)]
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;
}
}
18 changes: 17 additions & 1 deletion src/Command/MergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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)%')]
Expand All @@ -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 = [
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down
Loading