Skip to content

Commit 66e12bb

Browse files
committed
some update. begin add generate auto-complete script
1 parent fee4d91 commit 66e12bb

File tree

15 files changed

+383
-14
lines changed

15 files changed

+383
-14
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
}
2727
},
2828
"suggest": {
29-
"symfony/process": "php process operation"
29+
"symfony/process": "php process operation",
30+
"text/template": "Single-Class string template engine for PHP5/7 supporting if/loops/filters"
3031
}
3132
}

examples/Controllers/ProcessController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ protected static function commandAliases()
3030
];
3131
}
3232

33+
/**
34+
* simple process example for child-process
35+
*/
36+
public function runScriptCommand()
37+
{
38+
$script = '<?php echo "foo"; ?>';
39+
40+
41+
}
42+
3343
/**
3444
* simple process example for child-process
3545
*/
@@ -69,4 +79,4 @@ public function multiProcessCommand()
6979
{
7080

7181
}
72-
}
82+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# +------------------------------------------------------------------------+
5+
# | Phalcon Developer Tools |
6+
# +------------------------------------------------------------------------+
7+
# | Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com) |
8+
# +------------------------------------------------------------------------+
9+
# | This source file is subject to the New BSD License that is bundled |
10+
# | with this package in the file LICENSE.txt. |
11+
# | |
12+
# | If you did not receive a copy of the license and are unable to |
13+
# | obtain it through the world-wide-web, please send an email |
14+
# | to [email protected] so we can send you a copy immediately. |
15+
# +------------------------------------------------------------------------+
16+
# | Authors: Andres Gutierrez <[email protected]> |
17+
# | Eduar Carvajal <[email protected]> |
18+
# | Jakob <@jamurko> |
19+
# +------------------------------------------------------------------------+
20+
#
21+
22+
_phalcon()
23+
{
24+
local cur prev
25+
_get_comp_words_by_ref -n = cur prev
26+
27+
commands="commands list enumerate controller create-controller model \
28+
create-model all-models create-all-models project create-project scaffold \
29+
create-scaffold migration create-migration webtools create-webtools"
30+
31+
case "$prev" in
32+
project|create-project)
33+
COMPREPLY=($(compgen -W "--name --webtools --directory --type --template-path --use-config-ini --trace --help --namespace" -- "$cur"))
34+
return 0
35+
;;
36+
esac
37+
38+
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
39+
40+
} &&
41+
complete -F _phalcon phalcon

src/BuiltIn/Resources/templates/auto-complete-scripts.tpl

Whitespace-only changes.

src/Components/AutoCompletion.php renamed to src/Components/AutoComplete/AutoCompletion.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* Time: 17:56
77
*/
88

9-
namespace Inhere\Console\Components;
9+
namespace Inhere\Console\Components\AutoComplete;
1010

1111
/**
1212
* Class AutoCompletion - a simple command auto-completion tool
1313
*
1414
* @todo not available
15-
* @package Inhere\Console\Components
15+
* @package Inhere\Console\Components\AutoComplete
1616
*/
1717
class AutoCompletion
1818
{
@@ -57,9 +57,9 @@ public function register()
5757
*/
5858
public function completionHandler($input, $index)
5959
{
60-
$info = readline_info();
61-
$line = substr($info['line_buffer'], 0, $info['end']);
62-
$tokens = token_get_all('<?php ' . $line);
60+
// $info = readline_info();
61+
// $line = substr($info['line_buffer'], 0, $info['end']);
62+
// $tokens = token_get_all('<?php ' . $line);
6363
$input = trim($input);
6464

6565
if (!$input) {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Inhere
5+
* Date: 2017/12/22 0022
6+
* Time: 23:13
7+
*/
8+
9+
namespace Inhere\Console\Components\AutoComplete;
10+
11+
/**
12+
* Class ScriptGenerator
13+
* - generate bash/zsh auto complete script for current console application.
14+
* @package Inhere\Console\Components\AutoComplete
15+
* @link http://www.linuxidc.com/Linux/2016-10/136201.htm
16+
*/
17+
class ScriptGenerator
18+
{
19+
const TYPE_BASH = 1;
20+
const TYPE_ZSH = 1;
21+
22+
// simple: only commands. full: contains command description.
23+
const MODE_SIMPLE = 1;
24+
const MODE_FULL = 2;
25+
26+
/** @var int The type */
27+
private $type = 1;
28+
29+
/** @var int The mode */
30+
private $mode = 1;
31+
32+
/**
33+
* @return array
34+
*/
35+
public static function typeList()
36+
{
37+
return [self::TYPE_BASH, self::TYPE_ZSH];
38+
}
39+
40+
/**
41+
* @return array
42+
*/
43+
public static function modeList()
44+
{
45+
return [self::MODE_SIMPLE, self::MODE_FULL];
46+
}
47+
48+
/**
49+
* @return int
50+
*/
51+
public function getType(): int
52+
{
53+
return $this->type;
54+
}
55+
56+
/**
57+
* @param int $type
58+
*/
59+
public function setType(int $type)
60+
{
61+
if (\in_array($type, self::typeList(), 1)) {
62+
$this->type = $type;
63+
}
64+
}
65+
66+
/**
67+
* @return int
68+
*/
69+
public function getMode(): int
70+
{
71+
return $this->mode;
72+
}
73+
74+
/**
75+
* @param int $mode
76+
*/
77+
public function setMode(int $mode)
78+
{
79+
if (\in_array($mode, self::modeList(), 1)) {
80+
$this->mode = $mode;
81+
}
82+
}
83+
}

src/Components/CodeExecComparator.php renamed to src/Components/ExecComparator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
namespace Inhere\Console\Components;
1010

1111
/**
12-
* Class CodeExecComparator - PHP code exec speed comparator
12+
* Class ExecComparator - PHP code exec speed comparator
1313
* @package Inhere\Console\Components
1414
*/
15-
class CodeExecComparator
15+
class ExecComparator
1616
{
1717
/**
1818
* @var array
@@ -39,4 +39,4 @@ public function setVars(array $vars)
3939
{
4040
$this->vars = $vars;
4141
}
42-
}
42+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Inhere
5+
* Date: 2017/12/22 0022
6+
* Time: 21:44
7+
*/
8+
9+
namespace Inhere\Console\Components\Formatter;
10+
11+
/**
12+
* Class Formatter - message formatter
13+
* @package Inhere\Console\Components\Formatter
14+
*/
15+
class Formatter
16+
{
17+
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Inhere
5+
* Date: 2017/12/22 0022
6+
* Time: 21:45
7+
*/
8+
9+
namespace Inhere\Console\Components\Formatter;
10+
11+
/**
12+
* Class HelpPanel
13+
* - method version please {@see \Inhere\Console\Utils\Show::helpPanel()}
14+
* @package Inhere\Console\Components\Formatter
15+
*/
16+
class HelpPanel extends Formatter
17+
{
18+
19+
}

src/Components/Formatter/Panel.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Inhere
5+
* Date: 2017/12/22 0022
6+
* Time: 21:48
7+
*/
8+
9+
namespace Inhere\Console\Components\Formatter;
10+
11+
/**
12+
* Class Panel
13+
* - method version please {@see \Inhere\Console\Utils\Show::panel()}
14+
* @package Inhere\Console\Components\Formatter
15+
*/
16+
class Panel extends Formatter
17+
{
18+
19+
}

0 commit comments

Comments
 (0)