Skip to content

Commit 0d00a70

Browse files
committed
update readme, add new method: askHiddenInput() for read password
1 parent 163afd2 commit 0d00a70

File tree

14 files changed

+391
-60
lines changed

14 files changed

+391
-60
lines changed

README.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ $app->run();
8080

8181
然后在命令行里执行 `php examples/app`, 立即就可以看到如下输出了:
8282

83-
!['output-commands-info'](images/output-commands-info.jpg)
83+
!['output-commands-info'](images/example-app.png)
8484

8585
> `Independent Commands` 中的 demo 就是我们上面添加的命令
8686
@@ -194,7 +194,7 @@ class HomeController extends Controller
194194
195195
- 运行效果(by `php examples/app home`):
196196

197-
![command-group-example](./images/command-group-example.jpg)
197+
![command-group-example](./images/example-for-group.png)
198198

199199
更多请查看 [examples](./examples) 中的示例代码和在目录下运行示例 `php examples/app` 来查看效果
200200

@@ -527,6 +527,8 @@ Show::table($data, 'a table', $opts);
527527

528528
> 渲染效果请看下面的预览
529529
530+
![table-show](images/table-show.png)
531+
530532
### 快速的渲染一个帮助信息面板
531533

532534
```php
@@ -558,7 +560,41 @@ Show::helpPanel([
558560

559561
## 用户交互方法
560562

561-
需引入类 `Inhere\Console\Utils\Interact`
563+
> 要独立使用的话需引入类 `Inhere\Console\Utils\Interact``Controller``Command` 里可以直接调用相关方法
564+
565+
### 读取用户输入
566+
567+
```php
568+
public static function read($message = null, $nl = false, array $opts = []): string
569+
```
570+
571+
- 使用
572+
573+
```php
574+
$userInput = Interact::read();
575+
576+
// 先输出消息,再读取
577+
$userInput = Interact::read('Your name:');
578+
579+
// 在 Controller/Command 中
580+
$userInput = $this->read('Your name:');
581+
```
582+
583+
### 读取密码输入(隐藏输入文字)
584+
585+
```php
586+
public static function askHiddenInput(string $prompt = 'Enter Password:'): string
587+
public static function askPassword(string $prompt = 'Enter Password:'): string
588+
```
589+
590+
- 使用
591+
592+
```php
593+
$pwd = Interact::askPassword();
594+
595+
// 在 Controller/Command 中
596+
$pwd = $this->askPassword();
597+
```
562598

563599
### 从给出的列表中选择一项
564600

README_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ $app->run();
6868

6969
now, you can see:
7070

71-
!['output-commands-info'](images/output-commands-info.jpg)
71+
!['output-commands-info'](images/example-app.png)
7272

7373
## input
7474

examples/HomeController.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,20 @@ public function indexCommand()
3737
$this->write('hello, welcome!! this is ' . __METHOD__);
3838
}
3939

40+
/**
41+
* a example for input password on command line
42+
* @usage {fullCommand}
43+
*/
44+
public function passwdCommand()
45+
{
46+
$pwd = $this->askPassword();
47+
48+
$this->write('Your input is:' . $pwd);
49+
}
50+
4051
/**
4152
* a example for use color text output on command
42-
* @usage ./bin/app home/color
53+
* @usage {fullCommand}
4354
*/
4455
public function colorCommand()
4556
{
@@ -67,7 +78,7 @@ public function blockMsgCommand()
6778
{
6879
$this->write('block message:');
6980

70-
foreach (Interact::getBlockMethods() as $type) {
81+
foreach (Show::getBlockMethods() as $type) {
7182
$this->output->$type("$type style message text");
7283
}
7384

images/command-group-example.jpg

-79.8 KB
Binary file not shown.

images/example-app.png

359 KB
Loading

images/example-for-group.png

282 KB
Loading

images/output-color-text.png

-107 KB
Loading

images/output-commands-info.jpg

-71.5 KB
Binary file not shown.

src/Base/AbstractCommand.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ protected function createDefinition()
105105
return $this->definition;
106106
}
107107

108+
/**
109+
* 为命令注解提供可解析解析变量. 可以在命令的注释中使用
110+
* @return array
111+
*/
112+
public function annotationVars()
113+
{
114+
// e.g: `more info see {name}/index`
115+
return [
116+
'script' => $this->input->getScript(),
117+
'command' => $this->input->getCommand(),
118+
'fullCommand' => $this->input->getScript() . ' ' . $this->input->getCommand(),
119+
'name' => self::getName(),
120+
];
121+
}
122+
108123
/**************************************************************************
109124
* running a command
110125
**************************************************************************/
@@ -283,20 +298,6 @@ public function validateInput()
283298
* helper methods
284299
**************************************************************************/
285300

286-
/**
287-
* 为命令注解提供可解析解析变量. 可以在命令的注释中使用
288-
* @return array
289-
*/
290-
protected function annotationVars()
291-
{
292-
// e.g: `more info see {name}/index`
293-
return [
294-
'script' => $this->input->getScript(),
295-
'command' => $this->input->getCommand(),
296-
'name' => self::getName(),
297-
];
298-
}
299-
300301
/**
301302
* 为命令注解提供可解析解析变量. 可以在命令的注释中使用
302303
* @param string $str
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# exe file
2+
3+
## Hidden Input
4+
5+
From https://github.com/Seldaek/hidden-input

0 commit comments

Comments
 (0)