User tests: Successful: Unsuccessful:
This PR introduces a new CLI class for the CMS which functions as a CLI command runner. This deprecates the present methodology of new CLI commands being implemented always as JApplicationCli objects.
A JoomlaCmsCli class is added at cli/cms.php and is the command line entry point to the command runner system. The first argument given to this script represents the CLI command to be executed.
CLI commands are namespaced with a : separator with the component's name being required to be the first part of this (for example, finder:index triggers a command in com_finder). A command with no separator is assumed to be a "core" command and is processed as such.
Core commands live in the cli/commands folder and have a class name prefix of CliCommand. The command name finishes the class name as well as defines the file name. So the updatecheck command uses a class name of CliCommandUpdatecheck and the file path is cli/commands/updatecheck.php.
Component commands must have at least one : separator, however additional separators are supported and processed. Component commands must live in the component's administrator folder in a commands subfolder. The class name uses the component as the first part (similar to the MVC layer) followed by Command and the command name part(s). The : separator acts as a directory separator for the filesystem and each part uses an uppercase character for the first character when the class name is created. So, the finder:index command would use the FinderCommandIndex class name and the file path is administrator/components/com_finder/commands/index.php. If a content:category:delete command existed, the class name would be ContentCommandCategoryDelete and its file path would be administrator/components/com_content/commands/category/delete.php.
Commands follow the single task methodology already in place by their structure. The new command classes extend JControllerBase from the "new" MVC and are triggered from the CLI runner via the interface's execute method.
Third party extensions may immediately use this feature by adding CLI commands to their admin component folder in a commands folder. The only manifest change necessary is to ensure the folder is installed. This is different from the existing "practice" of using an install script to place CLI files in the CLI folder.
These scripts should be considered deprecated and removed at 4.0.
| Status | New | ⇒ | Pending |
| Labels |
Added:
?
|
||
| Labels |
Added:
?
|
||
Very cool
just curious, it is complicated to implement the suggestion on push Tab key?
example if finder has couple commands I type finder: push Tab key and I get list of possible commands
just curious, it is complicated to implement the suggestion on push Tab key?
I'd guess that depends highly on the operating system/shell/IDE you use, but it shouldn't be too complicated to set something up.
E.g. we have something in this direction set up for the JTracker here: https://github.com/joomla/jissues/blob/master/cli/Custom_jtracker.xml
EDIT This file is, of course, generated by one of our intelligent scripts https://github.com/joomla/jissues/blob/master/cli/Application/Command/Make/Autocomplete.php
Added the constant.
hm, http://www.php.net/manual/en/function.readline-completion-function.php looks not so dificult
in theory if each subcommand it just a filename, then we can make some method that return file names on Tab key press...
example component1 has command1.php and command2.php .. then user can type
component1: push Tab and the script return command1, command2
in theory ![]()
test good now
hm, http://www.php.net/manual/en/function.readline-completion-function.php looks not so dificult
IIRC per default PHP isn't compiled with readline support :(
If someone wants to give the readline support a go, they're more than welcome. I made a quick attempt and the function never got triggered.
@elkuku is right .. it is not so trivial as I thought https://github.com/MetalGuardian/yii2-bash-completion https://gist.github.com/cebe/1141050
I have tested this item successfully
I would add some default message if no arguments are supplied and, of course, colors and other nifty stuff we got implemented in JIssues and that a user would expect from a "modern" CLI application but - It's a great start - please commit soonish :)
@Fedik on the completion thingy: I found this: http://tech.zumba.com/2012/08/20/creating-bash-completion/
Seems like a neat idea - but only for bash users of course...
so there two way:
/etc/bash_completion.d ... it only for Unix system, and require "additional move" from the User php app/console --shell ... here is used readline_completion_function()
well, maybe in some day, in the future ...
I went ahead and configured the default output object for the CLI class to support our color processor, so you can do something like this in a CLI command:
$this->getApplication()->out('<info>Give me some style!</info>');Through the JApplicationCli API, you should also be able to fetch the output object and add in additional styles (or completely replace the output handler if you wanted).
| Category | ⇒ | CLI |
| Status | Pending | ⇒ | Ready to Commit |
RTC based on testing.
These scripts should be considered deprecated and removed at 4.0.
@mbabker so this will be a follow up PR if this gets merged?
| Labels |
Added:
?
|
||
| Milestone |
Added: |
||
| Milestone |
Removed: |
||
| Milestone |
Added: |
||
| Status | Ready to Commit | ⇒ | Closed |
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-10-30 18:00:46 |
| Closed_By | ⇒ | mbabker |
| Labels |
Removed:
?
|
||
| Milestone |
Removed: |
||
or I am alone here?
You're not. ;(
may i join in ?
something similar was done in the past GSOC edition
https://www.youtube.com/watch?v=fIUYdzVvgzA
Just skimming through that video, the approach in place there is similar to what exists today with every CLI class directly extending JApplicationCli. This approach created a single application entry point and a dumbed down version of a router to handle the implementation. This PR doesn't stop folks from doing that, but instead makes a half hearted attempt to start a JApplicationCms like class for the CLI interface and make it a little easier to integrate CLI routines into components.
very good idea, and make CLI script install a lot simpler, thanks @mbabker !