Skip to content

Commit cd9e2f9

Browse files
committed
feat(configuration-option): adds option and default value
1 parent ae73223 commit cd9e2f9

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,30 @@ To check your project for spelling mistakes, run:
3434
./vendor/bin/peck
3535
```
3636

37+
## Configuration
38+
39+
Peck can be configured using a `peck.json` file in the root of your project. Here's an example configuration:
40+
41+
```json
42+
{
43+
"ignore": {
44+
"words": [
45+
"config",
46+
"namespace"
47+
],
48+
"directories": [
49+
"app/MyNamespace"
50+
]
51+
}
52+
}
53+
```
54+
55+
You can also specify the path to the configuration file using the `--config` option:
56+
57+
```bash
58+
./vendor/bin/peck --config relative/path/to/peck.json
59+
```
60+
3761
---
3862

3963
Peck is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

bin/peck

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

44
declare(strict_types=1);
55

6+
use Peck\Console\Commands\CheckCommand;
67
use Symfony\Component\Console\Application;
78

89
foreach ([
@@ -22,9 +23,9 @@ $application = new Application(
2223
);
2324

2425
$application->add(
25-
new \Peck\Console\Commands\DefaultCommand(),
26+
new CheckCommand(),
2627
);
2728

28-
$application->setDefaultCommand('default');
29+
$application->setDefaultCommand('check');
2930

3031
$application->run();

src/Config.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function __construct(
3737
*/
3838
public static function resolveConfigFilePathUsing(Closure $closure): void
3939
{
40+
self::flush();
41+
4042
self::$resolveConfigFilePathUsing = $closure;
4143
}
4244

@@ -59,12 +61,12 @@ public static function instance(): self
5961
}
6062

6163
$basePath = dirname(array_keys(ClassLoader::getRegisteredLoaders())[0]);
62-
$filePath = self::$resolveConfigFilePathUsing instanceof Closure
64+
$filePath = $basePath.'/'.(self::$resolveConfigFilePathUsing instanceof Closure
6365
? (self::$resolveConfigFilePathUsing)()
64-
: ($basePath.'/peck.json');
66+
: 'peck.json');
6567

6668
$contents = file_exists($filePath)
67-
? (string) file_get_contents($basePath.'/peck.json')
69+
? (string) file_get_contents($filePath)
6870
: '{}';
6971

7072
/** @var array{
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
namespace Peck\Console\Commands;
66

77
use Composer\Autoload\ClassLoader;
8+
use Peck\Config;
89
use Peck\Kernel;
910
use Peck\ValueObjects\Issue;
1011
use Symfony\Component\Console\Attribute\AsCommand;
1112
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Input\InputOption;
1315
use Symfony\Component\Console\Output\OutputInterface;
1416

1517
use function Termwind\render;
@@ -20,14 +22,17 @@
2022
*
2123
* @internal
2224
*/
23-
#[AsCommand(name: 'default')]
24-
final class DefaultCommand extends Command
25+
#[AsCommand(name: 'check')]
26+
final class CheckCommand extends Command
2527
{
2628
/**
2729
* Executes the command.
2830
*/
2931
protected function execute(InputInterface $input, OutputInterface $output): int
3032
{
33+
$configurationPath = $input->getOption('config');
34+
Config::resolveConfigFilePathUsing(fn (): mixed => $configurationPath);
35+
3136
$kernel = Kernel::default();
3237

3338
$issues = $kernel->handle([
@@ -63,7 +68,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6368
*/
6469
protected function configure(): void
6570
{
66-
$this->setDescription('Checks for misspellings in the given directory.');
71+
$this->setDescription('Checks for misspellings in the given directory.')
72+
->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'The configuration file to use.', 'peck.json');
6773
}
6874

6975
/**

0 commit comments

Comments
 (0)