allapps2/shortcuts

命令集的快捷键控制台

1.4.1 2024-09-20 00:25 UTC

This package is auto-updated.

Last update: 2024-09-20 00:25:41 UTC


README

使用短别名调用命令集的控制台工具。

其独特之处在于它完全配置在 PHP 中,这意味着可以享受 代码自动完成、查找 使用、使用应用程序的 常量验证 等功能,实际上带来了整个 PHP 的可能性和你的 IDE 功能。

其缺点是,与 YAML 和其他简单格式相比,配置更加冗长,但与集成到宿主应用带来的好处相比,这是微不足道的。

安装

要求

  • PHP 8.2+
    php-cli 包足够了(例如,在 Alpine Linux 上可以通过 apk add php82-cli 安装)。

下载

https://github.com/allapps2/shortcuts/blob/main/bin/short.phar 下载 short.phar 并将其放入你的项目中(例如,放入 .for-auto-completion 文件夹,以便你的 IDE 如 PhpStorm 用于代码自动完成)。

全局安装

使 sc 别名在所有地方可用

sudo php short.phar setup-shortcuts-global

或任何自定义别名

sudo php short.phar setup-shortcuts-global myalias

用法

在包含 shortcuts.php 的文件夹中

sc [<shortcut> [<arguments>]]

shortcuts.php 的示例

use Shortcuts\Command\CommandsCollection;
use Shortcuts\IBuilder;
use Shortcuts\Shortcut;
use Shortcuts\ShortcutArg;
use Shortcuts\ShortcutsCollection;
use Shortcuts\ShortcutsCollectionFactory;

class Shortcuts extends ShortcutsCollection
{
    function shortcut1(): CommandsCollection
    {
        return (new CommandsCollection)->add('long command1');
    }

    #[Shortcut(description: 'Shortcut description')]
    function shortcut2(
        string $requiredArgument,
        #[ShortcutArg(description: 'Optional argument')]
        string $optionalArgument = 'default value'
    ): CommandsCollection
    {
        return (new CommandsCollection)
            ->add('long command2 ' . $requiredArgument)
            ->add('long command3 ' . $optionalArgument);
    }
}

return new class implements IBuilder {
    function build(ShortcutsCollectionFactory $factory): ShortcutsCollection {
        return $factory->create(Shortcuts::class);
    }
};

对于贡献者

克隆存储库并创建指向 index.php 的 sc 别名,而不是指向 short.phar

sudo php </path/to/clone>/app/index.php setup-shortcuts-global

这样,sc 将运行你的开发版本而不是分发版本,以便你可以测试你的更改。

重新编译 short.phar

./bin/compile.sh

创建 git 标签

设置常数 VERSION_* 中的版本号并重新编译 short.phar。
标签名称使用以下命令显示的版本号

php ./bin/short.phar