CodeIgniter4
CodeIgniter4 copied to clipboard
Add new method `promptByMultipleKeys()` in CLI class
Description I make this method because method promptByKey() just can read one value.
Checklist:
- [x] Securely signed commits
- [x] Component(s) with PHPDoc blocks, only if necessary or adds value
- [x] Unit testing, with >80% coverage
- [x] User guide updated
- [x] Conforms to style guide
Sorry, this branch has conflicts. Can you rebase and solve the conflicts?
And now we can write test for CLI::input(). See #6335 Could you try to add a test if possible?
Sorry, this branch has conflicts. Can you rebase and solve the conflicts?
And now we can write test for CLI::input(). See #6335 Could you try to add a test if possible?
okay. i will write the test
promptByKey():
$ php public/index.php
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
[0, 1, 2]: x
The temp field must be one of: 0, 1, 2.
[0, 1, 2]:
promptByMultipleKeys():
$ php public/index.php
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
[0, 1, 2]
x
Please select correctly
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
[0, 1, 2]
The output format is a bit different from promptByKey().
- Can you make the same?
- I did not know how to input multiple values.
For example:
$ php public/index.php
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
You can specify multiple values separated by commas.
[0, 1, 2]: x
Please select correctly.
You can specify multiple values separated by commas.
[0, 1, 2]:
The output format is a bit different from
promptByKey().
- Can you make the same?
- I did not know how to input multiple values.
For example:
$ php public/index.php Select your hobbies: [0] Playing game [1] Sleep [2] Badminton You can specify multiple values separated by commas. [0, 1, 2]: x Please select correctly. You can specify multiple values separated by commas. [0, 1, 2]:
- So, the output should only return the value of the selected key?
- There is an example in the documentation. see here
So, the output should only return the value of the selected key?
I think key value pair is okay.
There is an example in the documentation.
End users don't know whether promptByKey() or promptByMultipleKeys() is used.
Please select correctly. You can specify multiple values separated by commas. [0, 1, 2]:
In promptByKey, when a user fails in validation input, the return is:
The temp field must be one of: 0, 1, 2, 3.
[0, 1, 2, 3]:
But in promptByMultipleKeys, when a user fails in validation input, the return is:
Please select correctly.
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
[0, 1, 2]:
Is it fine? or should I replace the return in promptByMultipleKeys?
My opinion is the following:
$ php public/index.php
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
You can specify multiple values separated by commas.
[0, 1, 2]: x
Please select correctly.
You can specify multiple values separated by commas.
[0, 1, 2]:
It seems the input validation is not correct.
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
You can specify multiple values separated by commas.
[0, 1, 2] : ^,2
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ $hobbies │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
array (2) [
0 => string (12) "Playing game"
2 => string (9) "Badminton"
]
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Called from .../app/Controllers/Home.php:13 [dd()]
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
You can specify multiple values separated by commas.
[0, 1, 2] : ,
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ $hobbies │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
array (1) [
0 => string (12) "Playing game"
]
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Called from .../app/Controllers/Home.php:13 [dd()]
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
You can specify multiple values separated by commas.
[0, 1, 2] : |^
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ $hobbies │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
array (1) [
0 => string (12) "Playing game"
]
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Called from .../app/Controllers/Home.php:13 [dd()]
You have two while (true). It seems they have the different validation rules.
They should be combined into one.
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
You can specify multiple values separated by commas.
[0, 1, 2] : 1,2,5
Please select correctly.
You can specify multiple values separated by commas.
[0, 1, 2] : 2.5
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ $hobbies │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
array (1) [
2 => string (9) "Badminton"
]
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Called from .../app/Controllers/Home.php:13 [dd()]
Select your hobbies:
[0] Playing game
[1] Sleep
[2] Badminton
You can specify multiple values separated by commas.
[0, 1, 2] : 1,2,5
Please select correctly.
You can specify multiple values separated by commas.
[0, 1, 2] : ^
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ $hobbies │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
array (1) [
0 => string (12) "Playing game"
]
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Called from .../app/Controllers/Home.php:13 [dd()]
@rifalarya-2 I put two inline comments. That's all.
@rifalarya-2 I put two inline comments. That's all.
Thank you