-
Notifications
You must be signed in to change notification settings - Fork 49
v4 create command
Inhere edited this page Oct 18, 2021
·
9 revisions
使用之前的代码示例,来自我的项目 inhere/kite
<?php declare(strict_types=1);
namespace Inhere\Kite\Console\Command;
use Inhere\Console\Command;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Kite\Component\CliMarkdown;
use Toolkit\Cli\Color;
use function file_get_contents;
/**
* Class MarkdownCommand
*/
class MarkdownCommand extends Command
{
/** @var string */
protected static $name = 'markdown';
/**
* @var string
*/
protected static $description = 'render markdown file on terminal';
/**
* @return string[]
*/
public static function aliases(): array
{
return ['md', 'mkdown'];
}
/**
* @arguments
* mdfile string;The markdown file path;required
*
* @param Input $input
* @param Output $output
*/
protected function execute(Input $input, Output $output)
{
$filename = $this->flags->getArg('mdfile');
$text = file_get_contents($filename);
// parse content
$md = new CliMarkdown();
$doc = $md->parse($text);
$doc = Color::parseTag(rtrim($doc));
// $output->colored("Document for the #$nameString");
$output->writeRaw($doc);
}
}
我的其他PHP项目
- inhere/kite 方便本地开发和使用的个人CLI工具应用
- php-toolkit/pflag PHP编写的,通用的命令行标志(选项和参数)解析库
- phppkg/easytpl 使用简单且快速的 PHP 模板引擎
- inhere/php-validate 一个简洁小巧且功能完善的php验证库
- inhere/sroute 轻量且快速的HTTP请求路由库