Skip to content

Commit 1768676

Browse files
authored
Initial commit
0 parents  commit 1768676

File tree

7 files changed

+167
-0
lines changed

7 files changed

+167
-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/Demo/DefaultController.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Vendor\Demo;
4+
5+
use Minicli\Command\CommandController;
6+
7+
class DefaultController extends CommandController
8+
{
9+
public function handle(): void
10+
{
11+
$name = $this->hasParam('user') ? $this->getParam('user') : 'World';
12+
$this->getPrinter()->display(sprintf("Hello, %s!", $name));
13+
14+
print_r($this->getParams());
15+
}
16+
}

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": "minicli/command-demo",
3+
"type": "library",
4+
"description": "A demo shareable command for Minicli",
5+
"license": "MIT",
6+
"homepage": "https://github.com/minicli/command-demo",
7+
"keywords": ["cli","command-line", "template"],
8+
"autoload": {
9+
"psr-4": {
10+
"Vendor\\": "Command/"
11+
}
12+
},
13+
"require": {
14+
"minicli/minicli": "^3.0"
15+
}
16+
}

composer.lock

Lines changed: 73 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 demo param1=value1 param2=value2');
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)