Skip to content

Commit bc55d60

Browse files
authored
Initial commit
0 parents  commit bc55d60

File tree

7 files changed

+194
-0
lines changed

7 files changed

+194
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
.phpunit.result.cache
3+
.composer/
4+
vendor/

Command/Help/DefaultController.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Librarian\Help;
4+
5+
use Minicli\App;
6+
use Minicli\Command\CommandController;
7+
use Minicli\Command\CommandRegistry;
8+
9+
class DefaultController extends CommandController
10+
{
11+
/** @var array */
12+
protected array $commandMap = [];
13+
14+
public function boot(App $app): void
15+
{
16+
parent::boot($app);
17+
$this->commandMap = $app->commandRegistry->getCommandMap();
18+
}
19+
20+
public function handle(): void
21+
{
22+
$this->getPrinter()->info($this->app->getSignature());
23+
24+
$print_table[] = [ 'Namespace', 'Command' ];
25+
26+
foreach ($this->commandMap as $command => $sub) {
27+
if ($command == 'web') {
28+
continue;
29+
}
30+
$print_table[] = [ $command, ''];
31+
if (is_array($sub)) {
32+
foreach ($sub as $subcommand) {
33+
if ($subcommand == 'default') {
34+
$row = "./librarian $command\n";
35+
} else {
36+
$row = "./librarian $command $subcommand\n";
37+
}
38+
39+
$print_table[] = [ '', $row ];
40+
}
41+
}
42+
}
43+
44+
$this->getPrinter()->printTable($print_table);
45+
}
46+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 minicli
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# command-demo
2+
demo command repository

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "librarianphp/command-help",
3+
"type": "library",
4+
"description": "Librarian's built-in help command",
5+
"license": "MIT",
6+
"homepage": "https://github.com/librarianphp/command-demo",
7+
"keywords": ["cli","command-line", "markdown"],
8+
"autoload": {
9+
"psr-4": {
10+
"Librarian\\": "Command/"
11+
}
12+
},
13+
"require": {
14+
"minicli/minicli": "^3.0"
15+
}
16+
}

composer.lock

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minicli

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (php_sapi_name() !== 'cli') {
5+
exit;
6+
}
7+
8+
require __DIR__ . '/vendor/autoload.php';
9+
10+
use Minicli\App;
11+
use Minicli\Exception\CommandNotFoundException;
12+
13+
$app = new App([
14+
'app_path' => [
15+
__DIR__ . '/Command'
16+
],
17+
'debug' => true
18+
]);
19+
20+
$app->setSignature('./minicli help');
21+
22+
try {
23+
$app->runCommand($argv);
24+
} catch (CommandNotFoundException $notFoundException) {
25+
$app->getPrinter()->error("Command Not Found.");
26+
return 1;
27+
} catch (Exception $exception) {
28+
if ($app->config->debug) {
29+
$app->getPrinter()->error("An error occurred:");
30+
$app->getPrinter()->error($exception->getMessage());
31+
}
32+
return 1;
33+
}
34+
35+
return 0;

0 commit comments

Comments
 (0)