minicli/command-stencil

Minicli 命令,用于根据 minicli/stencil 模板生成文件

0.1.0 2022-06-20 17:49 UTC

This package is auto-updated.

Last update: 2024-09-21 14:59:13 UTC


README

这是 minicli/stencil 的命令实现。此命令将根据 Stencil 模板生成文件。这对于创建遵循特定结构或模板的样板文件,如新类和其他文档非常有用。

用法

首先,使用 Composer 导入此命令

composer require minicli/command-stencil

然后,编辑您的应用程序配置以在 app_path 定义中包含 @minicli/command-help。您还需要设置 stencilDir 配置变量,并将其指向您的 Stencils 目录。例如

$app = new App([
    'app_path' => [
            __DIR__ . '/app/Command',
            '@minicli/command-stencil'
        ],
    'stencilDir' => __DIR__ . '/stencils',
    'debug' => true
]);

现在,您应该能够运行 ./minicli stencil 命令。

测试模板

您可以将示例模板从 vendor/minicli/command-stencil/stencils/example.tpl 复制出来进行测试

cp ./vendor/minicli/command-stencil/stencils/example.tpl ./stencils

然后,以 example 为模板运行 ./minicli stencil,提供预期的变量 name

./minicli stencil template=example name=YourName
Hello YourName!% 

将输出内容保存到文件

包含 output=full-path-to-file 以将解析后的内容保存到文件

./minicli stencil template=example name=YourName output=test.txt
Hello YourName!% 

您应该会看到一个名为 test.txt 的文件,其中包含与命令相同的输出。要抑制命令输出,请在应用程序配置中将 debug 设置为 false