packager = $packager;
$this->isWindows = $isWindows;
parent::__construct();
}
protected function configure()
{
$this->setName('install')
->setDescription('Install phar into system wide binary directory' . ($this->isWindows ? ' (not available on Windows)' : ''))
->addArgument('project', InputArgument::OPTIONAL, 'Project name or path', '.')
->addArgument('target', InputArgument::OPTIONAL, 'Path to install to', '/usr/local/bin');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->isWindows) {
$output->writeln('Command not available on this platform. Please use the "build" command and place Phar in your $PATH manually.');
return 1;
}
$this->packager->setOutput($output);
$this->packager->coerceWritable();
$pharer = $this->packager->getPharer($input->getArgument('project'));
$path = $this->packager->getSystemBin($pharer->getPackageRoot(), $input->getArgument('target'));
if (is_file($path)) {
$helper = $this->getHelper('question');
assert($helper instanceof QuestionHelper);
$question = new ConfirmationQuestion('Overwrite existing file ' . $path . '? [y] > ', true);
if (!$helper->ask($input, $output, $question)) {
$output->writeln('Aborting');
return 0;
}
}
$this->packager->install($pharer, $path);
return 0;
}
}