jolicode/castor

由PHP构建的面向DX的任务运行器和命令启动器

安装次数: 29,939

依赖关系: 2

建议者: 0

安全性: 0

星标: 397

关注者: 15

分支: 20

公开问题: 6

类型:项目

v0.18.2 2024-09-03 12:23 UTC

README

castor logo

Castor是一个基于PHP构建的面向DX的任务运行器,具有一系列用于常见任务处理的函数。

它可以被视为Makefile、Fabric、Invoke、Shell脚本等的替代品,但它利用了PHP的脚本功能和其庞大的库生态系统。

它包含许多功能,使您的使用更加便捷

  • 无缝解析强参数和选项,简化输入处理
  • 自动完成支持快速且无错误的输入
  • 内置实用函数列表
    • run(): 运行外部进程,使外部工具的无缝集成成为可能
    • io(): 显示美观的输出并与终端交互
    • watch(): 监视文件并在文件修改时自动触发操作
    • fs(): 创建、删除和操作文件和目录
    • 以及更多高级功能

注意

Castor仍处于早期开发阶段,API尚未稳定。即使可能性不大,它仍可能在将来发生变化。

使用方法

在Castor中,任务以带有#[AsTask()]属性的典型PHP函数的形式设置,这些函数位于castor.php文件中。

这些任务可以运行任何PHP代码,还可以使用Castor预先打包的多种标准操作函数

例如

<?php

namespace greetings;

use Castor\Attribute\AsTask;
use function Castor\io;

#[AsTask()]
function hello(): void
{
    io()->writeln('Hello from castor');
}

将公开一个greetings:hello任务,您可以使用castor greetings:hello运行它

$ castor greetings:hello
Hello from castor

然后,您可以自由创建更复杂的任务

#[AsTask(description: 'Clean the infrastructure (remove container, volume, networks)')]
function destroy(bool $force = false)
{
    if (!$force) {
        io()->warning('This will permanently remove all containers, volumes, networks... created for this project.');
        io()->comment('You can use the --force option to avoid this confirmation.');

        if (!io()->confirm('Are you sure?', false)) {
            io()->comment('Aborted.');

            return;
        }
    }

    run('docker-compose down -v --remove-orphans --volumes --rmi=local');

    notify('The infrastructure has been destroyed.')
}

如果您想了解更多关于使用方法的信息,可以阅读基本使用文档,或查看一些示例

安装

使用安装程序

提示

这是在Linux和macOS上安装Castor的推荐方式。它需要PHP >= 8.1。

curl "https://castor.jolicode.com/install" | bash

还有其他安装Castor的方法,请参阅文档

进一步文档

阅读文档了解更多信息