Skip to content

Commit 43a20f3

Browse files
committed
✨ add argument source to the command
1 parent c6df2ae commit 43a20f3

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

README.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,41 @@ you will get asked for each file that has changes if you want to apply them.
1212

1313
## Example
1414

15-
`rector-p`
15+
`rector-p` or `vendor/bin/rector-p` if you did not setup your PATH environment variable
1616

1717
[![asciicast](https://asciinema.org/a/671145.png)](https://asciinema.org/a/671145)
1818

19+
### if you only want to run it with a specific path you can do it like this:
20+
21+
`rector-p src/Controller/`
22+
or
23+
`rector-p src/Controller/MyController.php src/Controller/MyOtherController.php`
24+
25+
# options you can use:
26+
27+
`rector-p --help`
28+
````bash
29+
Usage:
30+
partial [options] [--] [<source>...]
31+
32+
Arguments:
33+
source Files or directories to be upgraded.
34+
35+
Options:
36+
-s, --startOver Start over with the first file (be default rector-p keeps a record of files that have no changes in them)
37+
-p, --chunk=CHUNK chunk(part) definition eg 1/2 (first half) or 2/2 (second half) or 3/10 (third tenth) [default: "1/1"]
38+
-c, --config=CONFIG Path to config file [default: "/app/rector.php"]
39+
-h, --help Display help for the given command. When no command is given display help for the partial command
40+
-q, --quiet Do not output any message
41+
-V, --version Display this application version
42+
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
43+
-n, --no-interaction Do not ask any interactive question
44+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
45+
````
1946

2047
# with ♥️ from anders und sehr GmbH
2148

2249
> If something did not work 😮
2350
> or you appreciate this Extension 🥰 let us know.
2451
2552
> We are hiring https://www.andersundsehr.com/karriere/
26-

src/PartialCommand.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Rector\ValueObject\Configuration;
2121
use Symfony\Component\Console\Command\Command;
2222
use Symfony\Component\Console\Helper\QuestionHelper;
23+
use Symfony\Component\Console\Input\InputArgument;
2324
use Symfony\Component\Console\Input\InputInterface;
2425
use Symfony\Component\Console\Input\InputOption;
2526
use Symfony\Component\Console\Output\OutputInterface;
@@ -41,6 +42,7 @@ public function __construct(private readonly Cache $cache)
4142

4243
protected function configure(): void
4344
{
45+
$this->addArgument(Option::SOURCE, InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Files or directories to be upgraded.');
4446
$this->addOption(
4547
'startOver',
4648
's',
@@ -61,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6163
$this->cache->clear();
6264
}
6365

64-
$allFiles = $this->getAllFiles();
66+
$allFiles = $this->getAllFiles($this->input->getArgument(Option::SOURCE));
6567

6668
$chunkConfig = $this->parseChunkConfig($input->getOption('chunk'));
6769
if ($chunkConfig->chunkNumber === 1) {
@@ -96,9 +98,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9698
}
9799

98100
/**
101+
* @param list<string> $sources
99102
* @return list<string>
100103
*/
101-
private function getAllFiles(): array
104+
private function getAllFiles(array $sources): array
102105
{
103106
$bootstrapConfigs = (new RectorConfigsResolver())->provide();
104107

@@ -107,9 +110,13 @@ private function getAllFiles(): array
107110
$configFunction(new RectorConfig());
108111
}
109112

110-
$paths = SimpleParameterProvider::provideArrayParameter(Option::PATHS);
111-
if (!$paths) {
112-
throw new InvalidArgumentException('No paths found in configuration ' . $bootstrapConfigs->getMainConfigFile());
113+
if ($sources) {
114+
$paths = $sources;
115+
} else {
116+
$paths = SimpleParameterProvider::provideArrayParameter(Option::PATHS);
117+
if (!$paths) {
118+
throw new InvalidArgumentException('No paths found in configuration ' . $bootstrapConfigs->getMainConfigFile());
119+
}
113120
}
114121

115122
$rectorContainer = (new RectorContainerFactory())->createFromBootstrapConfigs($bootstrapConfigs);

0 commit comments

Comments
 (0)