Skip to content

Commit 017245d

Browse files
committed
feat: add --dev option to install command
1 parent 3a70974 commit 017245d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "leafs/cli",
33
"description": "A simple command line tool for installing and interacting with your leaf apps",
44
"homepage": "https://cli.leafphp.dev",
5-
"version": "v2.13.0",
5+
"version": "v2.13.1",
66
"keywords": [
77
"leaf",
88
"php",

src/InstallCommand.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Command\Command;
88
use Symfony\Component\Console\Input\InputArgument;
99
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Input\InputOption;
1011
use Symfony\Component\Console\Output\OutputInterface;
1112
use Symfony\Component\Process\Process;
1213

@@ -19,15 +20,16 @@ protected function configure()
1920
$this
2021
->setHelp('Install a new package')
2122
->setDescription('Add a new package to your leaf app')
22-
->addArgument('packages', InputArgument::IS_ARRAY, 'package(s) to install. Can also include a version constraint, e.g. foo/bar or foo/[email protected]');
23+
->addArgument('packages', InputArgument::IS_ARRAY, 'package(s) to install. Can also include a version constraint, e.g. foo/bar or foo/[email protected]')
24+
->addOption('dev', 'd', InputOption::VALUE_NONE, 'Install package as a dev dependency');
2325
}
2426

2527
protected function execute(InputInterface $input, OutputInterface $output): int
2628
{
2729
$packages = $input->getArgument('packages');
2830

2931
if (count($packages)) {
30-
return $this->install($packages, $output);
32+
return $this->install($packages, $input, $output);
3133
}
3234

3335
return $this->installDependencies($output);
@@ -66,18 +68,19 @@ protected function installDependencies($output)
6668
/**
6769
* Install packages
6870
*/
69-
protected function install($packages, $output)
71+
protected function install($packages, $input, $output)
7072
{
7173
foreach ($packages as $package) {
7274
if (strpos($package, '/') == false) {
7375
$package = "leafs/$package";
7476
}
77+
7578
$package = str_replace('@', ':', $package);
7679

7780
$output->writeln("<info>Installing $package...</info>");
7881
$composer = Utils\Core::findComposer();
7982
$process = Process::fromShellCommandline(
80-
"$composer require $package",
83+
"$composer require $package" . ($input->getOption('dev') ? ' --dev' : ''),
8184
null,
8285
null,
8386
null,

0 commit comments

Comments
 (0)