Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
erikaheidi committed Jun 1, 2022
1 parent b5cd23f commit 96a0e8a
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.phpunit.result.cache
.composer/
vendor/
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "minicli/command-demo",
"type": "library",
"description": "A demo shareable command for Minicli",
"license": "MIT",
"homepage": "https://github.com/minicli/command-demo",
"keywords": ["cli","command-line", "template"],
"autoload": {
"psr-4": {
"Minicli\\": "src/"
}
},
"require": {
"minicli/minicli": "^3.0"
}
}
73 changes: 73 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions minicli
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env php
<?php

if (php_sapi_name() !== 'cli') {
exit;
}

require __DIR__ . '/vendor/autoload.php';

use Minicli\App;
use Minicli\Exception\CommandNotFoundException;

$app = new App([
'app_path' => [
__DIR__ . '/src'
],
'debug' => true
]);

$app->setSignature('./minicli demo param1=value1 param2=value2');

try {
$app->runCommand($argv);
} catch (CommandNotFoundException $notFoundException) {
$app->getPrinter()->error("Command Not Found.");
return 1;
} catch (Exception $exception) {
if ($app->config->debug) {
$app->getPrinter()->error("An error occurred:");
$app->getPrinter()->error($exception->getMessage());
}
return 1;
}

return 0;
16 changes: 16 additions & 0 deletions src/Demo/DefaultController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Minicli\Demo;

use Minicli\Command\CommandController;

class DefaultController extends CommandController
{
public function handle(): void
{
$name = $this->hasParam('user') ? $this->getParam('user') : 'World';
$this->getPrinter()->display(sprintf("Hello, %s!", $name));

print_r($this->getParams());
}
}

0 comments on commit 96a0e8a

Please sign in to comment.