Skip to content

Commit 702c3eb

Browse files
committed
Adds a sync command
1 parent ccbb2c8 commit 702c3eb

4 files changed

Lines changed: 127 additions & 21 deletions

File tree

bin/lean-package-validator

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if (false === $autoloaded) {
2626

2727
use Stolt\LeanPackage\Commands\CreateCommand;
2828
use Stolt\LeanPackage\Commands\InitCommand;
29+
use Stolt\LeanPackage\Commands\RefreshCommand;
2930
use Stolt\LeanPackage\Commands\TreeCommand;
3031
use Stolt\LeanPackage\Commands\UpdateCommand;
3132
use Stolt\LeanPackage\Commands\ValidateCommand;
@@ -46,6 +47,11 @@ $analyser = new Analyser($finder);
4647
$initCommand = new InitCommand(
4748
$analyser
4849
);
50+
51+
$refreshCommand = new RefreshCommand(
52+
$analyser
53+
);
54+
4955
$validateCommand = new ValidateCommand(
5056
$analyser,
5157
new Validator($archive),
@@ -57,6 +63,6 @@ $treeCommand = new TreeCommand(new Tree(new Archive(WORKING_DIRECTORY,'tree-temp
5763

5864
$application = new Application('Lean package validator', VERSION);
5965
$application->addCommands(
60-
[$initCommand, $validateCommand, $createCommand, $updateCommand, $treeCommand]
66+
[$initCommand, $refreshCommand, $validateCommand, $createCommand, $updateCommand, $treeCommand]
6167
);
6268
$application->run();

src/Commands/InitCommand.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Stolt\LeanPackage\Analyser;
88
use Stolt\LeanPackage\Exceptions\PresetNotAvailable;
9+
use Stolt\LeanPackage\Presets\CommonPreset;
910
use Stolt\LeanPackage\Presets\Finder;
1011
use Symfony\Component\Console\Command\Command;
1112
use Symfony\Component\Console\Input\InputArgument;
@@ -53,7 +54,7 @@ protected function configure(): void
5354
. 'project/micro-package repository';
5455
$this->setDescription($description);
5556

56-
$availablePresets = $this->formatAvailablePresetDefinitionsForDescription(
57+
$availablePresets = (new CommonPreset())->formatAvailablePresetDefinitionsForDescription(
5758
$this->finder->getAvailablePresets()
5859
);
5960

@@ -83,24 +84,6 @@ protected function configure(): void
8384
));
8485
}
8586

86-
/**
87-
* @param array $presets
88-
* @return string
89-
*/
90-
private function formatAvailablePresetDefinitionsForDescription(array $presets): string
91-
{
92-
$presets = \array_map(function ($preset) {
93-
return '<comment>' . $preset . '</comment>';
94-
}, $presets);
95-
96-
if (\count($presets) > 2) {
97-
$lastPreset = \array_pop($presets);
98-
return \implode(', ', $presets) . ', and ' . $lastPreset;
99-
}
100-
101-
return $presets[0] . ' and ' . $presets[1];
102-
}
103-
10487
/**
10588
* Execute command.
10689
*

src/Commands/RefreshCommand.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stolt\LeanPackage\Commands;
6+
7+
use Stolt\LeanPackage\Analyser;
8+
use Stolt\LeanPackage\Exceptions\PresetNotAvailable;
9+
use Stolt\LeanPackage\Presets\CommonPreset;
10+
use Stolt\LeanPackage\Presets\Finder;
11+
use Symfony\Component\Console\Command\Command;
12+
use Symfony\Component\Console\Input\InputArgument;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Input\InputOption;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
17+
class RefreshCommand extends Command
18+
{
19+
private const DEFAULT_PRESET = 'PHP';
20+
21+
/**
22+
* Package analyser.
23+
*
24+
* @var Analyser
25+
*/
26+
protected Analyser $analyser;
27+
28+
/**
29+
* @var Finder
30+
*/
31+
private Finder $finder;
32+
33+
/**
34+
* @param Analyser $analyser
35+
*/
36+
public function __construct(Analyser $analyser)
37+
{
38+
$this->analyser = $analyser;
39+
$this->finder = $analyser->getFinder();
40+
41+
parent::__construct();
42+
}
43+
44+
/**
45+
* Command configuration.
46+
*
47+
* @return void
48+
*/
49+
protected function configure(): void
50+
{
51+
$this->analyser->setDirectory(WORKING_DIRECTORY);
52+
53+
$this
54+
->setName('refresh')
55+
->setDescription('Refresh a present .lpv file');
56+
57+
$availablePresets = (new CommonPreset())->formatAvailablePresetDefinitionsForDescription(
58+
$this->finder->getAvailablePresets()
59+
);
60+
61+
$directoryDescription = 'The directory of a project/micro-package repository';
62+
$presetDescription = 'The preset to use for the .lpv file. Available ones are ' . $availablePresets . '.';
63+
64+
$this->addArgument(
65+
'directory',
66+
InputArgument::OPTIONAL,
67+
$directoryDescription,
68+
$this->analyser->getDirectory()
69+
);
70+
71+
$this->addOption(
72+
'preset',
73+
null,
74+
InputOption::VALUE_REQUIRED,
75+
$presetDescription,
76+
self::DEFAULT_PRESET
77+
);
78+
$this->getDefinition()->addOption(new InputOption(
79+
'dry-run',
80+
null,
81+
InputOption::VALUE_NONE,
82+
'Do not write any files. Output the content that would be written'
83+
));
84+
}
85+
86+
/**
87+
* Execute command.
88+
*
89+
* @param InputInterface $input
90+
* @param OutputInterface $output
91+
*
92+
* @throws PresetNotAvailable
93+
* @return integer
94+
*/
95+
protected function execute(InputInterface $input, OutputInterface $output): int
96+
{
97+
98+
}
99+
}

src/Presets/CommonPreset.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Stolt\LeanPackage\Presets;
66

7-
class CommonPreset
7+
final class CommonPreset
88
{
99
protected function getCommonGlob(): array
1010
{
@@ -34,4 +34,22 @@ protected function getCommonGlob(): array
3434
'*.{png,gif,jpeg,jpg,webp}',
3535
];
3636
}
37+
38+
/**
39+
* @param array $presets
40+
* @return string
41+
*/
42+
public function formatAvailablePresetDefinitionsForDescription(array $presets): string
43+
{
44+
$presets = \array_map(function ($preset) {
45+
return '<comment>' . $preset . '</comment>';
46+
}, $presets);
47+
48+
if (\count($presets) > 2) {
49+
$lastPreset = \array_pop($presets);
50+
return \implode(', ', $presets) . ', and ' . $lastPreset;
51+
}
52+
53+
return $presets[0] . ' and ' . $presets[1];
54+
}
3755
}

0 commit comments

Comments
 (0)