cav-s-a/nova-advanced-command-runner

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

v3.0.1.7 2020-12-03 16:46 UTC

This package is auto-updated.

Last update: 2024-09-29 05:49:42 UTC


README

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

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

功能

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

screenshot of the command runner tool

安装

您可以通过 composer 将 nova 工具安装到使用 Nova 的 Laravel 应用中。

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,并详细说明您所提出的更改。

安全漏洞

如果您在此包中发现安全漏洞,请勿使用问题跟踪器。相反,请发送电子邮件至 srinathreddydudi@gmail.com。所有安全漏洞都将得到及时处理。

许可协议

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