Skip to content

Commit

Permalink
some update. begin add generate auto-complete script
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 22, 2017
1 parent fee4d91 commit 66e12bb
Show file tree
Hide file tree
Showing 15 changed files with 383 additions and 14 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
}
},
"suggest": {
"symfony/process": "php process operation"
"symfony/process": "php process operation",
"text/template": "Single-Class string template engine for PHP5/7 supporting if/loops/filters"
}
}
12 changes: 11 additions & 1 deletion examples/Controllers/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ protected static function commandAliases()
];
}

/**
* simple process example for child-process
*/
public function runScriptCommand()
{
$script = '<?php echo "foo"; ?>';


}

/**
* simple process example for child-process
*/
Expand Down Expand Up @@ -69,4 +79,4 @@ public function multiProcessCommand()
{

}
}
}
41 changes: 41 additions & 0 deletions src/BuiltIn/Resources/auto-complete-scripts/phalcon.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

#
# +------------------------------------------------------------------------+
# | Phalcon Developer Tools |
# +------------------------------------------------------------------------+
# | Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com) |
# +------------------------------------------------------------------------+
# | This source file is subject to the New BSD License that is bundled |
# | with this package in the file LICENSE.txt. |
# | |
# | If you did not receive a copy of the license and are unable to |
# | obtain it through the world-wide-web, please send an email |
# | to license@phalconphp.com so we can send you a copy immediately. |
# +------------------------------------------------------------------------+
# | Authors: Andres Gutierrez <andres@phalconphp.com> |
# | Eduar Carvajal <eduar@phalconphp.com> |
# | Jakob <@jamurko> |
# +------------------------------------------------------------------------+
#

_phalcon()
{
local cur prev
_get_comp_words_by_ref -n = cur prev

commands="commands list enumerate controller create-controller model \
create-model all-models create-all-models project create-project scaffold \
create-scaffold migration create-migration webtools create-webtools"

case "$prev" in
project|create-project)
COMPREPLY=($(compgen -W "--name --webtools --directory --type --template-path --use-config-ini --trace --help --namespace" -- "$cur"))
return 0
;;
esac

COMPREPLY=($(compgen -W "$commands" -- "$cur"))

} &&
complete -F _phalcon phalcon
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* Time: 17:56
*/

namespace Inhere\Console\Components;
namespace Inhere\Console\Components\AutoComplete;

/**
* Class AutoCompletion - a simple command auto-completion tool
*
* @todo not available
* @package Inhere\Console\Components
* @package Inhere\Console\Components\AutoComplete
*/
class AutoCompletion
{
Expand Down Expand Up @@ -57,9 +57,9 @@ public function register()
*/
public function completionHandler($input, $index)
{
$info = readline_info();
$line = substr($info['line_buffer'], 0, $info['end']);
$tokens = token_get_all('<?php ' . $line);
// $info = readline_info();
// $line = substr($info['line_buffer'], 0, $info['end']);
// $tokens = token_get_all('<?php ' . $line);
$input = trim($input);

if (!$input) {
Expand Down
83 changes: 83 additions & 0 deletions src/Components/AutoComplete/ScriptGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Created by PhpStorm.
* User: Inhere
* Date: 2017/12/22 0022
* Time: 23:13
*/

namespace Inhere\Console\Components\AutoComplete;

/**
* Class ScriptGenerator
* - generate bash/zsh auto complete script for current console application.
* @package Inhere\Console\Components\AutoComplete
* @link http://www.linuxidc.com/Linux/2016-10/136201.htm
*/
class ScriptGenerator
{
const TYPE_BASH = 1;
const TYPE_ZSH = 1;

// simple: only commands. full: contains command description.
const MODE_SIMPLE = 1;
const MODE_FULL = 2;

/** @var int The type */
private $type = 1;

/** @var int The mode */
private $mode = 1;

/**
* @return array
*/
public static function typeList()
{
return [self::TYPE_BASH, self::TYPE_ZSH];
}

/**
* @return array
*/
public static function modeList()
{
return [self::MODE_SIMPLE, self::MODE_FULL];
}

/**
* @return int
*/
public function getType(): int
{
return $this->type;
}

/**
* @param int $type
*/
public function setType(int $type)
{
if (\in_array($type, self::typeList(), 1)) {
$this->type = $type;
}
}

/**
* @return int
*/
public function getMode(): int
{
return $this->mode;
}

/**
* @param int $mode
*/
public function setMode(int $mode)
{
if (\in_array($mode, self::modeList(), 1)) {
$this->mode = $mode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace Inhere\Console\Components;

/**
* Class CodeExecComparator - PHP code exec speed comparator
* Class ExecComparator - PHP code exec speed comparator
* @package Inhere\Console\Components
*/
class CodeExecComparator
class ExecComparator
{
/**
* @var array
Expand All @@ -39,4 +39,4 @@ public function setVars(array $vars)
{
$this->vars = $vars;
}
}
}
18 changes: 18 additions & 0 deletions src/Components/Formatter/Formatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: Inhere
* Date: 2017/12/22 0022
* Time: 21:44
*/

namespace Inhere\Console\Components\Formatter;

/**
* Class Formatter - message formatter
* @package Inhere\Console\Components\Formatter
*/
class Formatter
{

}
19 changes: 19 additions & 0 deletions src/Components/Formatter/HelpPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: Inhere
* Date: 2017/12/22 0022
* Time: 21:45
*/

namespace Inhere\Console\Components\Formatter;

/**
* Class HelpPanel
* - method version please {@see \Inhere\Console\Utils\Show::helpPanel()}
* @package Inhere\Console\Components\Formatter
*/
class HelpPanel extends Formatter
{

}
19 changes: 19 additions & 0 deletions src/Components/Formatter/Panel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: Inhere
* Date: 2017/12/22 0022
* Time: 21:48
*/

namespace Inhere\Console\Components\Formatter;

/**
* Class Panel
* - method version please {@see \Inhere\Console\Utils\Show::panel()}
* @package Inhere\Console\Components\Formatter
*/
class Panel extends Formatter
{

}
19 changes: 19 additions & 0 deletions src/Components/Formatter/Table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: Inhere
* Date: 2017/12/22 0022
* Time: 21:43
*/

namespace Inhere\Console\Components\Formatter;

/**
* Class Table
* - method version please {@see \Inhere\Console\Utils\Show::table()}
* @package Inhere\Console\Components\Formatter
*/
class Table extends Formatter
{

}
5 changes: 2 additions & 3 deletions src/Components/Notify/Pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
*/
class Pending extends NotifyMessage
{
/** @var int Speed value. allow 1 - 100 */
private $speed = 20;
}

}
20 changes: 19 additions & 1 deletion src/Components/NotifyMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,23 @@
*/
class NotifyMessage
{
/** @var int Speed value. allow 1 - 10 */
protected $speed = 2;

}
/**
* @return int
*/
public function getSpeed(): int
{
return $this->speed;
}

/**
* @param int $speed
*/
public function setSpeed($speed)
{
$this->speed = (int)$speed;
}

}
Loading

0 comments on commit 66e12bb

Please sign in to comment.