-
Notifications
You must be signed in to change notification settings - Fork 29
properly use the cli helper #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
"dev-master": "1.1-dev" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
* @license http://opensource.org/licenses/MIT MIT License | ||
* | ||
* @author Daniel Barsotti <[email protected]> | ||
* @author David Buchmann <david@liip.ch> | ||
* @author David Buchmann <mail@davidbu.ch> | ||
*/ | ||
class CndParser extends AbstractParser | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/PHPCR/Util/Console/Command/BaseNodeManipulationCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace PHPCR\Util\Console\Command; | ||
|
||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* Base command for node manipulations, providing common setup. | ||
* | ||
* @license http://www.apache.org/licenses Apache License Version 2.0, January 2004 | ||
* @license http://opensource.org/licenses/MIT MIT License | ||
*/ | ||
abstract class BaseNodeManipulationCommand extends BaseCommand | ||
{ | ||
/** | ||
* Set up the options to manipulate nodes. | ||
*/ | ||
protected function configureNodeManipulationInput() | ||
{ | ||
$this->addOption('set-prop', 'p', | ||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, | ||
'Set node property on nodes use foo=bar' | ||
); | ||
$this->addOption('remove-prop', 'r', | ||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, | ||
'Remove property from nodes' | ||
); | ||
$this->addOption('add-mixin', null, | ||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, | ||
'Add a mixin to the nodes' | ||
); | ||
$this->addOption('remove-mixin', null, | ||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, | ||
'Remove mixin from the nodes' | ||
); | ||
$this->addOption('apply-closure', null, | ||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, | ||
'Apply a closure to each node, closures are passed PHPCR\Session and PHPCR\NodeInterface' | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class NodeMoveCommand extends Command | ||
class NodeMoveCommand extends BaseCommand | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
|
@@ -45,7 +45,7 @@ protected function configure() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$session = $this->getHelper('phpcr')->getSession(); | ||
$session = $this->getPhpcrSession(); | ||
|
||
$sourcePath = $input->getArgument('source'); | ||
$destPath = $input->getArgument('destination'); | ||
|
@@ -57,6 +57,8 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
$session->move($sourcePath, $destPath); | ||
$session->save(); | ||
|
||
return 0; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
* @author Daniel Barsotti <[email protected]> | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class NodeRemoveCommand extends Command | ||
class NodeRemoveCommand extends BaseCommand | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
|
@@ -57,8 +57,7 @@ protected function configure() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
/** @var $session SessionInterface*/ | ||
$session = $this->getHelper('phpcr')->getSession(); | ||
$session = $this->getPhpcrSession(); | ||
|
||
$path = $input->getArgument('path'); | ||
$force = $input->getOption('force'); | ||
|
@@ -74,7 +73,8 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
} | ||
|
||
if (!$force) { | ||
$dialog = new DialogHelper(); | ||
/** @var $dialog DialogHelper */ | ||
$dialog = $this->getHelperSet()->get('dialog'); | ||
$workspaceName = $session->getWorkspace()->getName(); | ||
|
||
if ($onlyChildren) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class NodeTouchCommand extends BaseCommand | ||
class NodeTouchCommand extends BaseNodeManipulationCommand | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
|
@@ -71,7 +71,7 @@ protected function configure() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$helper = $this->getPhpcrCliHelper(); | ||
$helper = $this->getPhpcrHelper(); | ||
$session = $this->getPhpcrSession(); | ||
|
||
$path = $input->getArgument('path'); | ||
|
@@ -98,13 +98,14 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
)); | ||
|
||
if ($nodeType != $type) { | ||
throw new \Exception(sprintf( | ||
'You have specified node type "%s" but the existing node is of type "%s"', | ||
$output->writeln(sprintf( | ||
'<error>You have specified node type "%s" but the existing node is of type "%s"</error>', | ||
$type, $nodeType | ||
)); | ||
|
||
return 1; | ||
} | ||
} else { | ||
|
||
$nodeName = PathHelper::getNodeName($path); | ||
$parentPath = PathHelper::getParentPath($path); | ||
|
||
|
@@ -116,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
$parentPath | ||
)); | ||
|
||
return; | ||
return 2; | ||
} | ||
|
||
$output->writeln(sprintf( | ||
|
@@ -135,5 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
)); | ||
|
||
$session->save(); | ||
|
||
return 0; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Helper\DialogHelper; | ||
use PHPCR\Util\Console\Command\BaseCommand; | ||
|
||
/** | ||
* Command which can update the properties of nodes found | ||
|
@@ -17,7 +16,7 @@ | |
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class NodesUpdateCommand extends BaseCommand | ||
class NodesUpdateCommand extends BaseNodeManipulationCommand | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
|
@@ -82,8 +81,6 @@ protected function configure() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->dialog = new DialogHelper(); | ||
|
||
$query = $input->getOption('query'); | ||
$queryLanguage = strtoupper($input->getOption('query-language')); | ||
$persistCounter = intval($input->getOption('persist-counter')); | ||
|
@@ -93,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
$removeMixins = $input->getOption('remove-mixin'); | ||
$applyClosures = $input->getOption('apply-closure'); | ||
$noInteraction = $input->getOption('no-interaction'); | ||
$helper = $this->getPhpcrCliHelper(); | ||
$helper = $this->getPhpcrHelper(); | ||
$session = $this->getPhpcrSession(); | ||
|
||
if (!$query) { | ||
|
@@ -154,7 +151,9 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
protected function getAction($output, $result) | ||
{ | ||
$response = strtoupper($this->dialog->ask($output, sprintf( | ||
/** @var $dialog DialogHelper */ | ||
$dialog = $this->getHelperSet()->get('dialog'); | ||
$response = strtoupper($dialog->ask($output, sprintf( | ||
'<question>About to update %d nodes. Enter "Y" to continue, "N" to cancel or "L" to list.</question>', | ||
count($result->getRows()) | ||
), false)); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,9 @@ | |
* @license http://opensource.org/licenses/MIT MIT License | ||
* | ||
* @author Lukas Kahwe Smith <[email protected]> | ||
* @author David Buchmann <david@liip.ch> | ||
* @author David Buchmann <mail@davidbu.ch> | ||
*/ | ||
class WorkspaceCreateCommand extends Command | ||
class WorkspaceCreateCommand extends BaseCommand | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
|
@@ -43,8 +43,7 @@ protected function configure() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
/** @var $session SessionInterface */ | ||
$session = $this->getHelper('phpcr')->getSession(); | ||
$session = $this->getPhpcrSession(); | ||
|
||
$workspaceName = $input->getArgument('name'); | ||
|
||
|
@@ -61,9 +60,17 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
return 1; | ||
} | ||
|
||
if (array_search($workspaceName, $workspace->getAccessibleWorkspaceNames())) { | ||
$output->writeln( | ||
sprintf('<comment>This repository already has a workspace called "%s"</comment>', $workspaceName) | ||
); | ||
|
||
return 2; | ||
} | ||
|
||
$workspace->createWorkspace($workspaceName); | ||
|
||
$output->writeln("Created workspace '$workspaceName'."); | ||
$output->writeln(sprintf('<info>Created workspace "%s".</info>', $workspaceName)); | ||
|
||
return 0; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity - why 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a non
0
return code of a linux binary means an error state. i just counted up the return statements so a calling programm could distinguish the states if it cares.