Skip to content

Commit

Permalink
New CLI parsing and handling
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Jul 2, 2016
1 parent e2c8715 commit 4e71c84
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 173 deletions.
16 changes: 8 additions & 8 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getHelpCommand() {
*/
public function getSkelCommand() {
return new SkelCommand(
new SkelCommandConfig($this->request->getCommandOptions(), getcwd()),
new SkelCommandConfig($this->request->parse(new SkelContext()), getcwd()),
$this->getPhiveVersion()
);
}
Expand All @@ -86,7 +86,7 @@ public function getUpdateRepositoryListCommand() {
*/
public function getRemoveCommand() {
return new RemoveCommand(
new RemoveCommandConfig($this->request->getCommandOptions(), $this->getTargetDirectoryLocator()),
new RemoveCommandConfig($this->request->parse(new RemoveContext()), $this->getTargetDirectoryLocator()),
$this->getPharRegistry(),
$this->getPharService(),
$this->getOutput(),
Expand All @@ -99,7 +99,7 @@ public function getRemoveCommand() {
*/
public function getResetCommand() {
return new ResetCommand(
new ResetCommandConfig($this->request->getCommandOptions()),
new ResetCommandConfig($this->request->parse(new ResetContext())),
$this->getPharRegistry(),
$this->getEnvironment(),
$this->getPharInstaller()
Expand All @@ -126,7 +126,7 @@ public function getInstallCommand() {
public function getUpdateCommand() {
return new UpdateCommand(
new UpdateCommandConfig(
$this->request->getCommandOptions(),
$this->request->parse(new UpdateContext()),
$this->getPhiveXmlConfig(),
$this->getTargetDirectoryLocator()
),
Expand All @@ -151,7 +151,7 @@ public function getListCommand() {
public function getPurgeCommand() {
return new PurgeCommand(
new PurgeCommandConfig(
$this->request->getCommandOptions(),
$this->request->parse(new PurgeContext()),
$this->getConfig()
),
$this->getPharRegistry(),
Expand All @@ -165,7 +165,7 @@ public function getPurgeCommand() {
public function getComposerCommand() {
return new ComposerCommand(
new ComposerCommandConfig(
$this->request->getCommandOptions(),
$this->request->parse(new ComposerContext()),
$this->getPhiveXmlConfig(),
$this->getTargetDirectoryLocator(),
$this->getEnvironment()->getWorkingDirectory()
Expand All @@ -182,7 +182,7 @@ public function getComposerCommand() {
* @return TargetDirectoryLocator
*/
private function getTargetDirectoryLocator() {
return new TargetDirectoryLocator($this->getConfig(), $this->getPhiveXmlConfig(), $this->request->getCommandOptions());
return new TargetDirectoryLocator($this->getConfig(), $this->getPhiveXmlConfig(), $this->request->getOptions());
}

/**
Expand Down Expand Up @@ -245,7 +245,7 @@ private function getSourcesListFileLoader() {
protected function getConfig() {
return new Config(
$this->getEnvironment(),
$this->request->getCommandOptions()
$this->request->getOptions()
);
}

Expand Down
45 changes: 7 additions & 38 deletions src/PhiveContext.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,24 @@
<?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\Context;
use PharIo\Phive\Cli\Options;
use PharIo\Phive\Cli\GeneralContext;

class PhiveContext implements Context {
class PhiveContext extends GeneralContext {

/**
* @var Options
*/
private $options;

/**
* PhiveContext constructor.
*/
public function __construct() {
$this->options = new Options();
}

/**
* @return Options
*/
public function getOptions() {
return $this->options;
}

public function knowsOption($option) {
return false;
protected function getKnownOptions() {
return ['home'];
}

public function requiresValue($option) {
return false;
}

public function getOptionForChar($char) {
return $option === 'home';
}

public function acceptsArguments() {
return $this->options->getArgumentCount() === 0;
return $this->getOptions()->getArgumentCount() === 0;
}

public function canContinue() {
return $this->options->getArgumentCount() === 0;
}

public function addArgument($arg) {
$this->options->addArgument($arg);
}

public function setOption($option, $value) {
$this->options->setOption($option, $value);
return $this->acceptsArguments();
}

}
8 changes: 8 additions & 0 deletions src/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ function($class) {
'phario\\phive\\cli\\consoleinput' => '/shared/cli/input/ConsoleInput.php',
'phario\\phive\\cli\\consoleoutput' => '/shared/cli/output/ConsoleOutput.php',
'phario\\phive\\cli\\context' => '/shared/cli/Context.php',
'phario\\phive\\cli\\contextexception' => '/shared/cli/ContextException.php',
'phario\\phive\\cli\\generalcontext' => '/shared/cli/GeneralContext.php',
'phario\\phive\\cli\\input' => '/shared/cli/input/Input.php',
'phario\\phive\\cli\\options' => '/shared/cli/Options.php',
'phario\\phive\\cli\\output' => '/shared/cli/output/Output.php',
Expand All @@ -34,6 +36,7 @@ function($class) {
'phario\\phive\\composeralias' => '/shared/ComposerAlias.php',
'phario\\phive\\composercommand' => '/commands/composer/ComposerCommand.php',
'phario\\phive\\composercommandconfig' => '/commands/composer/ComposerCommandConfig.php',
'phario\\phive\\composercontext' => '/commands/composer/ComposerContext.php',
'phario\\phive\\composerservice' => '/commands/composer/ComposerService.php',
'phario\\phive\\config' => '/shared/config/Config.php',
'phario\\phive\\configexception' => '/shared/exceptions/ConfigException.php',
Expand Down Expand Up @@ -106,22 +109,26 @@ function($class) {
'phario\\phive\\publickey' => '/services/key/PublicKey.php',
'phario\\phive\\purgecommand' => '/commands/purge/PurgeCommand.php',
'phario\\phive\\purgecommandconfig' => '/commands/purge/PurgeCommandConfig.php',
'phario\\phive\\purgecontext' => '/commands/purge/PurgeContext.php',
'phario\\phive\\release' => '/shared/phar/Release.php',
'phario\\phive\\releasecollection' => '/shared/phar/ReleaseCollection.php',
'phario\\phive\\releaseexception' => '/shared/exceptions/ReleaseException.php',
'phario\\phive\\removecommand' => '/commands/remove/RemoveCommand.php',
'phario\\phive\\removecommandconfig' => '/commands/remove/RemoveCommandConfig.php',
'phario\\phive\\removecontext' => '/commands/remove/RemoveContext.php',
'phario\\phive\\requestedphar' => '/shared/phar/RequestedPhar.php',
'phario\\phive\\requestedpharalias' => '/shared/phar/RequestedPharAlias.php',
'phario\\phive\\requestedpharurl' => '/shared/phar/RequestedPharUrl.php',
'phario\\phive\\resetcommand' => '/commands/reset/ResetCommand.php',
'phario\\phive\\resetcommandconfig' => '/commands/reset/ResetCommandConfig.php',
'phario\\phive\\resetcontext' => '/commands/reset/ResetContext.php',
'phario\\phive\\resolveexception' => '/shared/exceptions/ResolveException.php',
'phario\\phive\\sha1hash' => '/shared/hash/sha/Sha1Hash.php',
'phario\\phive\\sha256hash' => '/shared/hash/sha/Sha256Hash.php',
'phario\\phive\\signatureverifier' => '/services/signature/SignatureVerifier.php',
'phario\\phive\\skelcommand' => '/commands/skel/SkelCommand.php',
'phario\\phive\\skelcommandconfig' => '/commands/skel/SkelCommandConfig.php',
'phario\\phive\\skelcontext' => '/commands/skel/SkelContext.php',
'phario\\phive\\source' => '/shared/sources/Source.php',
'phario\\phive\\sourcerepository' => '/shared/repository/SourceRepository.php',
'phario\\phive\\sourcerepositoryloader' => '/shared/sources/SourceRepositoryLoader.php',
Expand All @@ -137,6 +144,7 @@ function($class) {
'phario\\phive\\unsupportedversionconstraintexception' => '/shared/exceptions/UnsupportedVersionConstraintException.php',
'phario\\phive\\updatecommand' => '/commands/update/UpdateCommand.php',
'phario\\phive\\updatecommandconfig' => '/commands/update/UpdateCommandConfig.php',
'phario\\phive\\updatecontext' => '/commands/update/UpdateContext.php',
'phario\\phive\\updaterepositorylistcommand' => '/commands/update-repository-list/UpdateRepositoryListCommand.php',
'phario\\phive\\url' => '/shared/Url.php',
'phario\\phive\\verificationfailedexception' => '/shared/exceptions/VerificationFailedException.php',
Expand Down
8 changes: 8 additions & 0 deletions src/commands/composer/ComposerContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\GeneralContext;

class ComposerContext extends GeneralContext {

}
10 changes: 5 additions & 5 deletions src/commands/help/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ list
install [--target bin/] <alias|url> [<alias|url> ...]
Perform installation of a phar distributed application or library

alias/url Installation via github profile/project, phar.io alias or explicit download form given URL
alias/url Installation via github profile/project, phar.io alias or explicit download form given URL

--target Set custom target directory for the PHAR
-t, --target Set custom target directory for the PHAR

-copy Copy PHAR file instead of using symlink
-global Install PHAR globally (likely to require root privileges)
-temporary Do not add entries in phive.xml for installed PHARs
-c, --copy Copy PHAR file instead of using symlink
-g, --global Install PHAR globally (likely to require root privileges)
--temporary Do not add entries in phive.xml for installed PHARs

composer
Parse composer.json file for known aliases and suggest installation
Expand Down
52 changes: 10 additions & 42 deletions src/commands/install/InstallContext.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,21 @@
<?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\Context;
use PharIo\Phive\Cli\Options;
use PharIo\Phive\Cli\GeneralContext;

class InstallContext implements Context {
class InstallContext extends GeneralContext {

/**
* @var Options
*/
private $options;

/**
* InstallContext constructor.
*/
public function __construct() {
$this->options = new Options();
}

public function canContinue() {
return true;
}

public function knowsOption($option) {
return false;
protected function getKnownOptions() {
return [
'target' => 't',
'copy' => 'c',
'global' => 'g',
'temporary' => false
];
}

public function requiresValue($option) {
// TODO: Implement requiresValue() method.
return false;
}

public function getOptionForChar($char) {
return null;
}

public function acceptsArguments() {
return true;
}

public function addArgument($arg) {
$this->options->addArgument($arg);
}

public function setOption($option, $value) {
}

public function getOptions() {
return $this->options;
return $option === 'target';
}

}
8 changes: 8 additions & 0 deletions src/commands/purge/PurgeContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\GeneralContext;

class PurgeContext extends GeneralContext {

}
7 changes: 7 additions & 0 deletions src/commands/remove/RemoveContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\GeneralContext;

class RemoveContext extends GeneralContext {
}
8 changes: 8 additions & 0 deletions src/commands/reset/ResetContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\GeneralContext;

class ResetContext extends GeneralContext {

}
8 changes: 8 additions & 0 deletions src/commands/skel/SkelContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\GeneralContext;

class SkelContext extends GeneralContext {

}
8 changes: 8 additions & 0 deletions src/commands/update/UpdateContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\GeneralContext;

class UpdateContext extends GeneralContext {

}
7 changes: 7 additions & 0 deletions src/shared/cli/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public function requiresValue($option);
*/
public function getOptionForChar($char);

/**
* @param $char
*
* @return bool
*/
public function hasOptionForChar($char);

/**
* @return bool
*/
Expand Down
8 changes: 8 additions & 0 deletions src/shared/cli/ContextException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace PharIo\Phive\Cli;

use PharIo\Phive\Exception;

class ContextException extends \Exception implements Exception {

}
Loading

0 comments on commit 4e71c84

Please sign in to comment.