caneco/artisan-aliases

节省键盘敲击,按你的方式运行Artisan命令

1.1.0 2019-01-29 23:37 UTC

This package is auto-updated.

Last update: 2024-09-29 05:28:08 UTC


README


Total Downloads Latest Stable Version License

Laravel Artisan别名

如果你经常使用命令行,节省一些键盘敲击总是好的,特别是对于你经常输入的命令。这个包可以帮助你为Artisan命令创建别名,以及更多...

安装

您可以通过composer安装此包

>_ composer require caneco/artisan-aliases

注册服务提供者

在Laravel 5.5中,服务提供者将自动注册。但如果需要,只需将服务提供者添加到config/app.php文件中

'providers' => [
    // ...
    Caneco\ArtisanAliases\ArtisanAliasesServiceProvider::class,
];

发布包资源

要发布配置文件和.laravel_alias,请执行以下命令并选择此服务提供者

>_ php artisan vendor:publish

 Which provider or tag's files would you like to publish?:
  [0 ] Publish files from all providers and tags listed below
  [1 ] Provider: Caneco\ArtisanAliasesExample:
  [… ] ...

或者用一个命令完成它

>_ php artisan vendor:publish --provider="Caneco\ArtisanAliases\ArtisanAliasesServiceProvider"

发布后,这是配置文件的内容

return [

    /*
    |--------------------------------------------------------------------------
    | Artisan Alias Master Switch
    |--------------------------------------------------------------------------
    | This option may be used to enable/disable all Artisan alias
    | defined in your local or global `.laravel_alias` file
    */
    'enabled' => env('ARTISAN_ALIAS_ENABLED', true),

    /*
    |--------------------------------------------------------------------------
    | Default Alias File
    |--------------------------------------------------------------------------
    | This option allows you to have three ways of load the list of alias. The
    | `global` option will only load the alias defined in your home directory,
    | while the `local` option, will limit the alias from the list in your
    | application. Finally, The `both` option, or anything else, will
    | load the alias from both locations.
    |
    | Supported: "global", "local", "both",
    */
    'use_only' => 'both',

];

用法

发布初始文件后,您的别名将存储在本地应用目录的文件夹中;或在您的家目录中全局存储。并且像任何其他bash别名文件一样,内容将具有以下格式

laravel="inspire"
# cc="clear-compiled"

列出现有别名

要列出当前可用的别名,您可以运行以下命令

>_ php artisan alias --list
Laravel `Artisan Aliases` 1.1.0

Usage:
 alias [-g|--global] [--] [<as>]

Available alias:
 laravel inspire
 cc      clear-compiled

此外,可用的别名也会出现在您的Artisan命令列表中

$ php artisan list
...
Available commands:
  alias                Create an alias of another command
  cc                   * Alias for the `clear-compiled` command
  clear-compiled       Remove the compiled class file
  down                 Put the application into maintenance mode
  ...
  inspire              Display an inspiring quote
  laravel              * Alias for the `inspire` command
  list                 Lists commands
  ...

添加新别名

直接在.laravel_alias文件中添加您的别名,或只需使用Artisan命令

>_ php artisan alias laravel "inspire"

并且,如果您传递了--global选项,别名将注册在您的家目录的.laravel_alias中。

>_ php artisan alias cc="clear-compiled" --global

如果您没有传递所需的参数,则将触发--list选项,您将看到命令信息;用法和可用别名列表。

注释

任何以字符#开始的文本都被视为注释,不会执行。

# https://twitter.com/davidhemphill/status/1083466919964041217
migrate:make="make:migration" # DOPE

引号包裹

命令前后加上引号不是必需的,但如果要别名的命令包含空格,则必须使用引号。

多个命令

别名可以通过使用操作符&&||与多个命令关联。并且,就像bash一样,在使用&&时,如果其中一个命令返回大于零的值,则命令序列将终止。而||将无论什么情况都会继续。

# EXAMPLE

tables-up=notifications:table && queue:table && queue:failed-table && ...

Shell命令

如果您在别名前加上感叹号,它将被视为Shell命令。

别名ception…

是的,您也可以创建别名的别名...

Artisan组

如果您使用命名空间设置别名,如boot:tablesboot:cache,Artisan列表将一起将您的别名分组。

# EXAMPLE

boot
 boot:cache    * Alias for the `config:cache || route:cache || view:cache command`
 boot:tables   * Alias for the `cache:table || notifications:table || queue:failed-table || queue:table || session:table command`

注意事项⚠️

  • 目前,要修改或删除任何别名,您需要打开.laravel_aliases并手动操作,但计划从终端进行操作。
  • 添加与现有别名相同的别名将导致异常。
  • .laravel_aliases中手动定义了两个别名,最后一个别名命令将生效。
  • 与Artisan命令具有相同名称的别名,Artisan将占优。

支持的版本

请查看下表以找出此包的哪个版本支持Laravel的哪个版本

路线图

Artisan别名是稳定的,但我还想在包中添加一些功能。

以下是即将到来的计划

  • 使用选项--d|delete删除现有的别名
  • 如果别名具有::class引用,则触发@handle方法
  • 当用户尝试在命令中添加sudo时提醒用户(有用?)
  • 添加注释
  • 使用选项--force替换现有的别名
  • 添加测试

贡献

欢迎所有贡献(包括拉取请求、问题和功能请求)。但请先阅读《贡献文件》,所有贡献者信息请参阅《贡献者页面》。

许可证

MIT 许可证(MIT)。更多详细信息请参阅《许可证文件》。