Skip to content

Commit

Permalink
add some new commands
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 28, 2020
1 parent 0d2b86d commit 656385f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
5 changes: 5 additions & 0 deletions app/Console/Command/MarkdownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class MarkdownCommand extends Command

protected static $description = 'render markdown file on terminal';

public static function aliases(): array
{
return ['md', 'md:read'];
}

/**
* do execute
* @param Input $input
Expand Down
23 changes: 13 additions & 10 deletions app/Console/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
use Inhere\Console\Command;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Toolkit\Cli\Color;
use Toolkit\Sys\Sys;
use Inhere\PTool\Helper\SysCmd;
use function is_array;
use function is_string;

Expand All @@ -31,14 +30,14 @@ class RunCommand extends Command
*/
public static function aliases(): array
{
return ['exec'];
return ['exec', 'script'];
}

/**
* Do execute
*
* @options
* -l, --list List all script names
* -l, --list List all script names
*
* @param Input $input
* @param Output $output
Expand Down Expand Up @@ -71,20 +70,24 @@ protected function execute($input, $output)

$commands = $scripts[$name];
if (is_string($commands)) {
Color::println("run > $commands", 'comment');
Sys::execute($commands, false);
// Color::println("run > $commands", 'comment');
// Sys::execute($commands, false);
$ret = SysCmd::exec($commands);
echo $ret['output'];
return;
}

if (is_array($commands)) {
foreach ($commands as $index => $command) {
if (is_string($command)) {
$output->liteWarning("The {$name}.{$index} command is not string, skip run");
if (!is_string($command)) {
$output->liteError("The {$name}.{$index} command is not string, skip run");
continue;
}

Color::println("run > $command", 'comment');
Sys::execute($command, false);
// Color::println("run > $command", 'comment');
// Sys::execute($command, false);
$ret = SysCmd::exec($command);
echo $ret['output'];
}
return;
}
Expand Down
34 changes: 33 additions & 1 deletion app/Console/Group/GitGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\PTool\Helper\GitUtil;
use Inhere\PTool\Helper\SysCmd;
use Toolkit\Cli\Color;
use function sprintf;

/**
* Class GitGroup
Expand Down Expand Up @@ -131,7 +133,7 @@ public function tagPushCommand(Input $input, Output $output): void
}

/**
* run a php built-in server for development(is alias of the command 'server:dev')
* delete an remote tag by git
*
* @usage
* {command} [-S HOST:PORT]
Expand All @@ -147,7 +149,37 @@ public function tagPushCommand(Input $input, Output $output): void
public function tagDeleteCommand(Input $input, Output $output): void
{
$remote = $input->getSameOpt(['r', 'remote'], 'origin');
$tag = $input->getSameOpt(['v', 'tag']);

GitUtil::delRemoteTag($remote, $tag);

$output->info('Complete');
}

/**
* run git add/commit/push at once command
*
* @options
* -m, --message The commit message
*
* @param Input $input
* @param Output $output
*/
public function ampCommand(Input $input, Output $output): void
{
$message = $input->getSameOpt(['m', 'message'], '');
if (!$message) {
$output->liteError('please input commit message');
return;
}

$output->info('Work Dir: ' . $input->getPwd());
SysCmd::exec('git add .');

SysCmd::exec(sprintf('git commit -m "%s"', $message));

SysCmd::exec('git push');

$output->info('Complete');
}
}
20 changes: 20 additions & 0 deletions app/Console/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,28 @@
* @license MIT
*/

use Inhere\PTool\Console\Application;

/** @var Application $app */
$app->registerCommands('Inhere\PTool\\Console\\Command', __DIR__ . '/Command');
$app->registerGroups('Inhere\PTool\\Console\\Group', __DIR__ . '/Group');

// $app->addCommand(\Inhere\Console\BuiltIn\DevServerCommand::class);
$app->addController(\Inhere\Console\BuiltIn\PharController::class);

$app->addCommand('cur:time', static function ($in, $out) {
$time = time();
$out->println([
date('Y-m-d H:i:s', $time),
]);
}, [
'aliases' => ['curtime'],
'description' => 'print current time',
]);

$app->addCommand('calc', static function ($in, $out) {
$out->println('TODO');
}, [
// 'aliases' => ['curtime'],
'description' => 'simple expr execute',
]);

0 comments on commit 656385f

Please sign in to comment.