8
8
use MarekNocon \ComposerCheckout \PullRequest \GithubPullRequestData ;
9
9
use Symfony \Component \Console \Input \ArrayInput ;
10
10
use Symfony \Component \Console \Input \InputInterface ;
11
+ use Symfony \Component \Console \Input \InputOption ;
11
12
use Symfony \Component \Console \Output \OutputInterface ;
12
13
13
14
class CheckoutCommand extends BaseCommand
@@ -16,20 +17,21 @@ protected function configure(): void
16
17
{
17
18
parent ::configure ();
18
19
$ this ->setName ('checkout ' );
19
- $ this ->setHelp (
20
- 'Adds the branch from given GitHub Pull Request as a Composer dependency. '
21
- );
20
+ $ this ->setHelp ('Adds the branch from given GitHub Pull Request as a Composer dependency. ' );
21
+ $ this ->addOption ('prefer-source ' , 's ' , InputOption::VALUE_OPTIONAL );
22
22
}
23
23
24
24
protected function execute (InputInterface $ input , OutputInterface $ output ): int
25
25
{
26
26
$ pullRequestUrls = $ this ->validateInput ($ input ->getArgument ('pullRequestUrls ' ));
27
27
28
+ $ preferSource = $ input ->hasOption ('prefer-source ' );
29
+
28
30
foreach ($ pullRequestUrls as $ pullRequestUrl ) {
29
31
$ githubPullRequestData = GithubPullRequestData::fromUrl ($ pullRequestUrl );
30
32
$ composerPullRequestData = $ this ->extractDataFromPullRequest ($ githubPullRequestData );
31
33
$ this ->addRepository ($ composerPullRequestData ->repositoryUrl , $ output );
32
- $ this ->requireDependency ($ composerPullRequestData , $ output );
34
+ $ this ->requireDependency ($ composerPullRequestData , $ output, $ preferSource );
33
35
}
34
36
35
37
$ this ->executePostInstallCommands ($ output );
@@ -102,7 +104,7 @@ private function extractDataFromPullRequest(GithubPullRequestData $pullRequestDa
102
104
);
103
105
}
104
106
105
- private function requireDependency (ComposerPullRequestData $ pullRequestData , OutputInterface $ output ): void
107
+ private function requireDependency (ComposerPullRequestData $ pullRequestData , OutputInterface $ output, bool $ preferSource ): void
106
108
{
107
109
/** @var RequireCommand */
108
110
$ requireCommand = $ this ->getApplication ()->get ('require ' );
@@ -113,15 +115,19 @@ private function requireDependency(ComposerPullRequestData $pullRequestData, Out
113
115
$ dependencyString
114
116
));
115
117
116
- $ input = new ArrayInput ([
117
- 'packages ' => [
118
- $ pullRequestData ->packageName ,
119
- $ dependencyString ,
120
- ],
121
- '--no-scripts ' => true ,
122
- ]);
118
+ $ input = [
119
+ 'packages ' => [
120
+ $ pullRequestData ->packageName ,
121
+ $ dependencyString ,
122
+ ],
123
+ '--no-scripts ' => true ,
124
+ ];
125
+
126
+ if ($ preferSource ) {
127
+ $ input ['--prefer-source ' ] = true ;
128
+ }
123
129
124
- if ($ requireCommand ->run ($ input , $ output )) {
130
+ if ($ requireCommand ->run (new ArrayInput ( $ input) , $ output )) {
125
131
throw new \RuntimeException ('`Failed on adding dependency ' );
126
132
}
127
133
}
0 commit comments