innmind/cli-framework

该包已被废弃,不再维护。作者建议使用 innmind/framework 包。

命令行框架

1.4.0 2021-02-20 10:19 UTC

This package is auto-updated.

Last update: 2023-01-01 15:05:15 UTC


README

codecov Build Status Type Coverage

innmind/cli 之上构建的小型库,可自动启用某些功能。

安装

composer require innmind/cli-framework

使用

<?php

use Innmind\CLI\{
    Environment,
    Command,
};
use Innmind\CLI\Framework\{
    Application,
    Main,
};
use Innmind\OperatingSystem\OperatingSystem;
use Innmind\Url\Path;

new class extends Main {
    protected function configure(Application $app): Application
    {
        return $app
            ->configAt(Path::of('/path/to/config/directory/'))
            ->commands(fn(Environment $env, OperatingSystem $os): array => [
                // a list of objects implementing Command
            ]);
    }
}

以下简单示例将尝试在提供的目录中查找名为 .env 的文件,并将变量添加到 commands 可调用返回的映射中。

默认情况下,它启用 innmind/silent-cartographer 的使用,但可以通过调用 ->disableSilentCartographer() 来禁用。

当声明了 PROFILER 环境变量时,它将启用 innmind/debug,您可以通过调用 ->disableProfilerSection(...$sectionsClassNameToDisable) 来禁用特定的分析器部分。

当您的 CLI 应用程序与外部服务通信时,应调用 ->useResilientOperatingSystem() 以适应由于不可靠的网络导致的不一致性。