binarybuilds/nova-advanced-command-runner

Laravel Nova 工具,用于运行 Artisan 和 bash (shell) 命令。

v3.0.1 2020-08-14 15:08 UTC

This package is auto-updated.

Last update: 2024-09-20 00:05:58 UTC


README

这个 Nova 工具允许您直接从 nova 运行 artisan 和 bash 命令。

这是由 guratr 开发的原始包 Nova Command Runner 的扩展版本。

功能

  • 运行预定义的 artisan 和 shell 命令
  • 运行自定义 artisan 和 shell 命令
  • 运行命令时使用变量
  • 在运行命令时提示用户指定可选标志
  • 使用下拉框或提示用户输入变量值来为变量使用预定义值。
  • 跟踪命令运行历史
  • 无需数据库更改。一切均由单个配置文件管理。
  • 排队执行长时间运行的命令

screenshot of the command runner tool

安装

您可以使用 composer 在使用 Nova 的 Laravel 应用中安装 nova 工具。

composer require binarybuilds/nova-advanced-command-runner

接下来,您必须将工具注册到 Nova。通常在 NovaServiceProvidertools 方法中完成。

// in app/Providers/NovaServiceProvder.php

// ...

public function tools()
{
    return [
        // ...
        new \BinaryBuilds\NovaAdvancedCommandRunner\CommandRunner,
    ];
}

发布配置文件

php artisan vendor:publish --provider="BinaryBuilds\NovaAdvancedCommandRunner\ToolServiceProvider"

将您的命令添加到 config/nova-advanced-command-runner.php

用法

点击您的 Nova 应用中的 "命令运行器" 菜单项以查看工具。

配置

所有配置均通过位于 config/nova-advanced-command-runner.php 的单个配置文件管理。

添加命令

需要轻松访问的所有命令都应在配置文件中的 commands 数组中定义。

命令选项

  • run : 要运行的命令(例如:route:cache)
  • type : 按钮类(primary, secondary, success, danger, warning, info, light, dark, link)
  • group: 分组名称(可选)
  • variables : 命令中使用的变量数组(可选)
  • command_type : 命令类型。(artisan 或 bash。默认为 artisan)
  • flags : 命令的可选标志数组(可选)

示例

'commands' => [


    // Basic command
     'Clear Cache' => [
         'run' => 'cache:clear', 
         'type' => 'danger', 
         'group' => 'Cache',
     ],
     
     
     
     // Bash command
      'Disk Usage' => [
          'run' => 'df -h', 
          'type' => 'danger', 
          'group' => 'Statistics',
          'command_type' => 'bash'
      ],
     
     
     
     
     // Command with variable   
     'Clear Cache' => [
         'run' => 'cache:forget {cache key}', 
         'type' => 'danger', 
         'group' => 'Cache'
     ],
     
     
     
     
    // Command with advanced variable customization
    'Clear Cache' => [
        'run' => 'cache:forget {cache key}', 
        'type' => 'danger', 
        'group' => 'Cache',
        'variables' => [
            [
                'label' =>  'cache key' // This needs to match with variable defined in the command,
                'field' => 'select' // Allowed values (text,number,tel,select,date,email,password),
                'options' => [
                    'blog-cache' => 'Clear Blog Cache', 
                    'app-cache' => 'Clear Application Cache'
                ],
                'placeholder' => 'Select An Option'
            ]
        ]
    ],
    
    
    
    
    // Command with flags
    'Run Migrations' => [
        'run' => 'migrate --force', 
        'type' => 'danger', 
        'group' => 'Migration',
    ],
    
    
    
    
    // Command with optional flags
    'Run Migrations' => [
        'run' => 'migrate', 
        'type' => 'danger', 
        'group' => 'Migration',
        'flags' => [ 
        
            // These optional flags will be prompted as a checkbox for the user
            // And will be appended to the command if the user checks the checkbox
            
            '--force' => 'Force running in production' 
        ]
    ],
    
    
    
    
    // Command with help text
    'Run Migrations' => [
        'run' => 'migrate --force', 
        'type' => 'danger', 
        'group' => 'Migration',
        
        // You can also add html for help text.
        'help' => 'This is a destructive operation. Proceed only if you really know what you are doing.'
    ],
    
    
    
    // Queueing commands
    'Clear Cache' => [ 'run' => 'cache:clear --should-queue', 'type' => 'danger', 'group' => 'Cache' ],
    
        
        
    // Queueing commands on custom queue and connection
    'Clear Cache' => [ 'run' => 'cache:clear --should-queue --cr-queue=high --cr-connection=database', 'type' => 'danger', 'group' => 'Cache' ],
]

其他自定义

    
    // Limit the command run history to latest 10 runs
    'history'  => 10,
  
    
    
    // Tool name displayed in the navigation menu
    'navigation_label' => 'Command Runner',
    
    
    
    // Any additional info to display on the tool page. Can contain string and html.
    'help' => '',
   
    
    
    // Allow running of custom artisan and bash(shell) commands
    'custom_commands' => ['artisan','bash'],
  
  
  
    // Allow running of custom artisan commands only(disable custom bash(shell) commands)
    'custom_commands' => ['artisan'],
  
  
  
    // Allow running of custom bash(shell) commands only(disable custom artisan commands)
    'custom_commands' => ['bash'],
  
  
  
      // Disable running of custom commands.
    'custom_commands' => [],

截图

screenshot of the command runner tool

screenshot of the command runner tool

screenshot of the command runner tool

screenshot of the command runner tool

screenshot of the command runner tool

鸣谢

贡献

感谢您考虑为此包做出贡献!请创建一个 pull request 并详细说明您提出的更改。

许可

此包是开源软件,许可协议为 MIT 许可