From 2e6930cdb54c398ae9a72ef65942b15232f3b251 Mon Sep 17 00:00:00 2001 From: dantleech Date: Sun, 8 Jun 2014 11:19:33 +0200 Subject: [PATCH 1/2] Autocomplete, fixed segfault, include properties --- CHANGELOG.md | 4 +- src/PHPCR/Shell/Console/Application/Shell.php | 24 ---------- src/PHPCR/Shell/PhpcrSession.php | 47 +++++-------------- 3 files changed, 14 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24834a41..483e1fc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,14 @@ - New command: `file:import`: - import files into the repository. - `node:list`: Added `--level` option to rescursively show children nodes and properties +- Autocomplete completes property names in addition to node names in current path ## Improvements - `session:export:view`: Added `--pretty` option to `session:export:view` command to output formatted XML. - `session:export:view`: Ask confirmation before overwriting file. -## Bug Fixes +## Bugs - Aliases: Allow quoted arguments +- Fixed autocomplete segfault diff --git a/src/PHPCR/Shell/Console/Application/Shell.php b/src/PHPCR/Shell/Console/Application/Shell.php index 29d52d18..4636987e 100644 --- a/src/PHPCR/Shell/Console/Application/Shell.php +++ b/src/PHPCR/Shell/Console/Application/Shell.php @@ -103,33 +103,9 @@ private function autocompleter($text) { $info = readline_info(); $text = substr($info['line_buffer'], 0, $info['end']); - $list = $this->application->getHelperSet()->get('phpcr')->getSession()->autocomplete($text); return $list; - - if ($info['point'] !== $info['end']) { - return false; - } - - // task name? - if (false === strpos($text, ' ') || !$text) { - return array_keys($this->application->all()); - } - - // options and arguments? - try { - $command = $this->application->find(substr($text, 0, strpos($text, ' '))); - } catch (\Exception $e) { - return false; - } - - $list = array('--help'); - foreach ($command->getDefinition()->getOptions() as $option) { - $list[] = '--' . $option->getName(); - } - - return $list; } /** diff --git a/src/PHPCR/Shell/PhpcrSession.php b/src/PHPCR/Shell/PhpcrSession.php index 318e09f0..25d9c4ef 100644 --- a/src/PHPCR/Shell/PhpcrSession.php +++ b/src/PHPCR/Shell/PhpcrSession.php @@ -48,43 +48,18 @@ public function setCwd($cwd) */ public function autocomplete($text) { - // get last string - if (!preg_match('&^(.+) &', $text, $matches)) { - return false; - } - - $path = $matches[1]; - - if (substr($path, 0, 1) == '/') { - $parentPath = PathHelper::getParentPath($path); - try { - $node = $this->getNode($parentPath); - $list = array(); - foreach ($node->getNodes() as $path => $node) { - $list[] = substr($parentPath, 1) . '/' . $path; - } - - return $list; - } catch (PathNotFoundException $e) { - return false; - } - } else { - $cwd = $this->getCwd(); - try { - $node = $this->getNode($cwd); - $list = array(); - foreach ($node->getNodes() as $path => $node) { - if ($this->getCwd() == '/') { - $list[] = $path; - } else { - $list[] = $path; - } - } - - return $list; - } catch (PathNotFoundException $e) { - return false; + // return autocompletions for current path + $cwd = $this->getCwd(); + try { + $node = $this->getNode($cwd); + $list = (array) $node->getNodeNames(); + foreach ($node->getProperties() as $name => $v) { + $list[] = $name; } + + return $list; + } catch (PathNotFoundException $e) { + return false; } } From f0def3c0f9b7effab631ebe4b08c37e9f62d23c8 Mon Sep 17 00:00:00 2001 From: dantleech Date: Sun, 8 Jun 2014 12:05:41 +0200 Subject: [PATCH 2/2] Show template nodes / properties --- .../Console/Application/ShellApplication.php | 6 +++ .../Console/Command/Phpcr/NodeListCommand.php | 48 +++++++++++++++++++ .../Shell/Resources/config.dist/alias.yml | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/PHPCR/Shell/Console/Application/ShellApplication.php b/src/PHPCR/Shell/Console/Application/ShellApplication.php index 0febc116..35829a81 100644 --- a/src/PHPCR/Shell/Console/Application/ShellApplication.php +++ b/src/PHPCR/Shell/Console/Application/ShellApplication.php @@ -250,6 +250,12 @@ private function configureFormatter(OutputFormatter $formatter) $style = new OutputFormatterStyle(null, null, array('bold')); $formatter->setStyle('node', $style); + $style = new OutputFormatterStyle('blue', null, array('bold')); + $formatter->setStyle('templatenode', $style); + + $style = new OutputFormatterStyle('blue', null, array()); + $formatter->setStyle('templateproperty', $style); + $style = new OutputFormatterStyle(null, null, array()); $formatter->setStyle('property', $style); diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php index d7ab4933..f39fda0c 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use PHPCR\PropertyType; class NodeListCommand extends Command { @@ -24,8 +25,14 @@ protected function configure() $this->addOption('properties', null, InputOption::VALUE_NONE, 'List only the properties of this node'); $this->addOption('filter', 'f', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Optional filter to apply'); $this->addOption('level', 'L', InputOption::VALUE_REQUIRED, 'Depth of tree to show'); + $this->addOption('no-template', 'T', InputOption::VALUE_REQUIRED, 'Do not show template nodes and properties'); $this->setHelp(<<--level option. + +The node:list command also shows template nodes and properties as defined a nodes node-type. +These can be suppressed using the --no-template option. HERE ); } @@ -72,9 +79,20 @@ private function renderChildren($currentNode, $table, $spacers) { $children = $currentNode->getNodes($this->filters ? : null); + $nodeType = $currentNode->getPrimaryNodeType(); + $childNodeDefinitions = $nodeType->getDeclaredChildNodeDefinitions(); + $childNodeNames = array(); + foreach ($childNodeDefinitions as $childNodeDefinition) { + $childNodeNames[$childNodeDefinition->getName()] = $childNodeDefinition; + } + $i = 0; foreach ($children as $child) { $i++; + if (isset($childNodeNames[$child->getName()])) { + unset($childNodeNames[$child->getName()]); + } + $isLast = count($children) === $i; $table->addRow(array( @@ -94,20 +112,50 @@ private function renderChildren($currentNode, $table, $spacers) $this->renderNode($child, $table, $newSpacers); } } + + // render empty schematic children + foreach ($childNodeNames as $childNodeName => $childNodeDefinition) { + // @todo: Determine and show cardinality, 1..*, *..*, 0..1, etc. + $table->addRow(array( + '' . implode('', $spacers) . '@' . $childNodeName . '', + implode('|', $childNodeDefinition->getRequiredPrimaryTypeNames()), + '', + )); + } } private function renderProperties($currentNode, $table, $spacers) { $properties = $currentNode->getProperties($this->filters ? : null); + $nodeType = $currentNode->getPrimaryNodeType(); + $propertyDefinitions = $nodeType->getDeclaredPropertyDefinitions(); + + $propertyNames = array(); + foreach ($propertyDefinitions as $name => $propertyDefinition) { + $propertyNames[$propertyDefinition->getName()] = $propertyDefinition; + } + $i = 0; foreach ($properties as $name => $property) { $i++; + if (isset($propertyNames[$name])) { + unset($propertyNames[$name]); + } + $table->addRow(array( '' . implode('', $spacers). $name . '', '' . $this->formatter->getPropertyTypeName($property->getType()) . '', $this->textHelper->truncate($this->formatter->formatValue($property), 55), )); } + + foreach ($propertyNames as $propertyName => $property) { + $table->addRow(array( + '' . implode('', $spacers). '@' . $propertyName . '', + '' . strtoupper(PropertyType::nameFromValue($property->getRequiredType())) . '', + '' + )); + } } } diff --git a/src/PHPCR/Shell/Resources/config.dist/alias.yml b/src/PHPCR/Shell/Resources/config.dist/alias.yml index 63b70de9..e8b60829 100644 --- a/src/PHPCR/Shell/Resources/config.dist/alias.yml +++ b/src/PHPCR/Shell/Resources/config.dist/alias.yml @@ -16,7 +16,7 @@ exit: shell:exit # Node commands ls: node:list {arg1} -sl: node:clone {arg1} {arg2} # symlink, as in ln -s +ln: node:clone {arg1} {arg2} # symlink, as in ln -s cp: node:copy {arg1} {arg2} cat: node:property:show {arg1} touch: node:property:set {arg1} {arg2} {arg3}