承接 getkirby/cli 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

getkirby/cli

Composer 安装命令:

composer require getkirby/cli

包简介

Kirby command line interface

README 文档

README

The Kirby command line interface helps simplifying common tasks with your Kirby installations.

Installation

Via Composer

composer global require getkirby/cli

Make sure to add your composer bin directory to your ~/.bash_profile (Mac OS users) or into your ~/.bashrc (Linux users).

Your global composer directory is normally either ~/.composer/vendor/bin or ~/.config/composer/vendor/bin. You can find the correct path by running …

composer -n config --global home

Afterwards, add the result to your bash profile …

export PATH=~/.composer/vendor/bin:$PATH

Did it work?

Check if the installation worked by running the following in your terminal.

kirby

This should print the Kirby CLI version and a list of available commands

Available core commands

- kirby backup
- kirby clean:content
- kirby clear:cache
- kirby clear:lock
- kirby clear:logins
- kirby clear:media
- kirby clear:sessions
- kirby download
- kirby help
- kirby install
- kirby install:kit
- kirby install:repo
- kirby license:info
- kirby license:renewal
- kirby make:blueprint
- kirby make:collection
- kirby make:command
- kirby make:config
- kirby make:controller
- kirby make:language
- kirby make:model
- kirby make:plugin
- kirby make:snippet
- kirby make:template
- kirby make:user
- kirby migrate:to:public-folder
- kirby migrate:to:root-folder
- kirby plugin:install
- kirby plugin:remove
- kirby plugin:upgrade
- kirby register
- kirby remove:command
- kirby roots
- kirby security
- kirby unzip
- kirby upgrade
- kirby uuid:duplicates
- kirby uuid:generate
- kirby uuid:populate
- kirby uuid:remove
- kirby version

Writing commands

You can create a new command via the CLI:

kirby make:command hello

This will create a new site/commands folder in your installation with a new hello.php file

The CLI will already put the basic scaffolding into the file:

<?php

return [
    'description' => 'Nice command',
    'args' => [],
    'command' => static function ($cli): void {
        $cli->success('Nice command!');
    }
];

You can define your command logic in the command callback. The $cli object comes with a set of handy tools to create output, parse command arguments, create prompts and more.

Global commands

You might have some commands that you need for all your local Kirby installations. This is where global commands come in handy. You can create a new global command with the --global flag:

kirby make:command hello --global

The command file will then be place in ~/.kirby/commands/hello.php and is automatically available everywhere.

Command environment

To load a custom environment config for a particular host, you can set an env variable

env KIRBY_HOST=production.com kirby mycommand

Command plugins

Your Kirby plugins can define their own set of commands: https://getkirby.com/docs/reference/plugins/extensions/commands

Kirby::plugin('your/plugin', [
  'commands' => [
    'your-plugin:test' => [
      'description' => 'Nice command',
      'args' => [],
      'command' => function ($cli) {
        $cli->success('My first plugin command');
      }
    ]
  ]
]);

Check for installed commands

You can always check back if your commands have been created properly by running kirby again

kirby

Removing commands

Once you no longer need a command, you can remove it with …

kirby remove:command hello

If you have a local and a global command, you can choose which one to delete.

Debugging

Use the -d or --debug argument to run the command in debug mode:

kirby make:command hello --debug

Formatting Output

Sending messages to the terminal is super easy.

$cli->out()

$cli->out('This is some simple text');

$cli->success()

$cli->success('This is text in a nice green box');

$cli->error()

$cli->error('This is red text for errors');

$cli->bold()

$cli->bold('This is some bold text');

$cli->br()

// this will create a line break
$cli->br();

For more available colors and formats, check out the CLImate docs: https://climate.thephpleague.com/styling/colors/

Arguments

Your commands can define a list of required and optional arguments that need to be provided by the user.

<?php

return [
    'description' => 'Hello world',
    'args' => [
        'name' => [
            'description' => 'The name for the greeting',
            'required'    => true
        ]
    ],
    'command' => static function ($cli): void {
        $cli->success('Hello ' . $cli->arg('name') . '!');
    }
];

The command can now be executed by providing the name …

kirby hello Joe

If no name is provided, an error will be shown.

Argument docs

Arguments can be required, can set a default value and more. Check out the CLImate docs for additional options: https://climate.thephpleague.com/arguments/

Prompts

Instead of taking arguments from the command, you can also ask for them in a prompt:

<?php

return [
    'description' => 'Hello world',
    'command' => static function ($cli): void {
        $name = $cli->prompt('Please enter a name:');
        $cli->success('Hello ' . $name . '!');
    }
];

As a third alternative you can either take the argument or ask for it if it is not provided:

<?php

return [
    'description' => 'Hello world',
    'args' => [
        'name' => [
            'description' => 'The name for the greeting',
        ]
    ],
    'command' => static function ($cli): void {
        $name = $cli->argOrPrompt('name', 'Please enter a name:');
        $cli->success('Hello ' . $name . '!');
    }
];

Checkboxes Radios and more

The CLI also supports more complex ways to get input from users. Check out the CLImate docs how to work with user input: https://climate.thephpleague.com/terminal-objects/input/

Combining commands

You can reuse all existing commands in your custom commands to create entire chains of actions.

<?php

return [
    'description' => 'Downloads the starterkit and the plainkit',
    'command' => static function ($cli): void {

        $cli->command('install:kit', 'starterkit');
        $cli->command('install:kit', 'plainkit');

        $cli->success('Starterkit and plainkit have been installed');
    }
];

What's Kirby?

  • getkirby.com – Get to know the CMS.
  • Try it – Take a test ride with our online demo. Or download one of our kits to get started.
  • Documentation – Read the official guide, reference and cookbook recipes.
  • Issues – Report bugs and other problems.
  • Feedback – You have an idea for Kirby? Share it.
  • Forum – Whenever you get stuck, don't hesitate to reach out for questions and support.
  • Discord – Hang out and meet the community.
  • YouTube - Watch the latest video tutorials visually with Bastian.
  • Mastodon – Spread the word.
  • Bluesky – Tell a friend.

© 2009 Bastian Allgeier getkirby.com · License agreement

getkirby/cli 适用场景与选型建议

getkirby/cli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 81.7k 次下载、GitHub Stars 达 65, 最近一次更新时间为 2016 年 02 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cli」 「cms」 「command」 「kirby」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 getkirby/cli 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 getkirby/cli 我们能提供哪些服务?
定制开发 / 二次开发

基于 getkirby/cli 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 81.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 65
  • 点击次数: 20
  • 依赖项目数: 28
  • 推荐数: 3

GitHub 信息

  • Stars: 65
  • Watchers: 5
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-27