? ? Success

User tests: Successful: Unsuccessful:

avatar mbabker
mbabker
29 Aug 2015

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.

Summary

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.

Command Requirements

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.

Extension Use

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.

Existing CLI scripts

These scripts should be considered deprecated and removed at 4.0.

avatar mbabker mbabker - open - 29 Aug 2015
avatar mbabker mbabker - change - 29 Aug 2015
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 29 Aug 2015
Labels Added: ?
avatar wilsonge wilsonge - change - 29 Aug 2015
Labels Added: ?
avatar Fedik
Fedik - comment - 30 Aug 2015

very good idea, and make CLI script install a lot simpler, thanks @mbabker !

avatar elkuku
elkuku - comment - 30 Aug 2015

Very cool :+1:

avatar Fedik
Fedik - comment - 30 Aug 2015

test almost good,
something went wrong on finder:index --purge

screen 2015-08-30 17 38 54 1052x172

avatar Fedik
Fedik - comment - 30 Aug 2015

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

avatar elkuku
elkuku - comment - 30 Aug 2015

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 :wink:

avatar mbabker
mbabker - comment - 30 Aug 2015

Added the constant.

avatar Fedik
Fedik - comment - 30 Aug 2015

hm, http://www.php.net/manual/en/function.readline-completion-function.php looks not so dificult :wink:
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 :wink:

avatar Fedik Fedik - test_item - 30 Aug 2015 - Tested successfully
avatar Fedik
Fedik - comment - 30 Aug 2015

test good now :+1:

avatar elkuku
elkuku - comment - 30 Aug 2015

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 :(

avatar mbabker
mbabker - comment - 30 Aug 2015

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.

avatar Fedik
Fedik - comment - 30 Aug 2015
avatar elkuku elkuku - test_item - 30 Aug 2015 - Tested successfully
avatar elkuku
elkuku - comment - 30 Aug 2015

I have tested this item successfully :wink:

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 :)


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7783.

avatar elkuku
elkuku - comment - 31 Aug 2015

@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...

avatar Fedik
Fedik - comment - 31 Aug 2015

so there two way:

  • make bash script, and include it in .bashrc or place it in /etc/bash_completion.d ... it only for Unix system, and require "additional move" from the User
  • make Joomla Shell, similar like it is in Symfony Shell php app/console --shell ... here is used readline_completion_function()

well, maybe in some day, in the future ... :smile:

avatar mbabker
mbabker - comment - 31 Aug 2015

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).

avatar zero-24 zero-24 - change - 31 Aug 2015
Category CLI
avatar fastslack
fastslack - comment - 5 Sep 2015

@test ok

Very interesting Michael

cli-test

avatar zero-24 zero-24 - alter_testresult - 5 Sep 2015 - fastslack: Tested successfully
avatar zero-24 zero-24 - change - 5 Sep 2015
Status Pending Ready to Commit
avatar zero-24
zero-24 - comment - 5 Sep 2015

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?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7783.

avatar joomla-cms-bot joomla-cms-bot - change - 5 Sep 2015
Labels Added: ?
avatar zero-24 zero-24 - change - 5 Sep 2015
Milestone Added:
avatar zero-24 zero-24 - change - 6 Oct 2015
Milestone Removed:
avatar zero-24 zero-24 - change - 6 Oct 2015
Milestone Added:
avatar mbabker mbabker - change - 30 Oct 2015
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2015-10-30 18:00:46
Closed_By mbabker
avatar mbabker mbabker - close - 30 Oct 2015
avatar joomla-cms-bot joomla-cms-bot - close - 30 Oct 2015
avatar mbabker mbabker - close - 30 Oct 2015
avatar joomla-cms-bot joomla-cms-bot - change - 30 Oct 2015
Labels Removed: ?
avatar mbabker mbabker - head_ref_deleted - 30 Oct 2015
avatar zero-24 zero-24 - change - 30 Oct 2015
Milestone Removed:
avatar Fedik
Fedik - comment - 22 Nov 2015

I respect @mbabker decision to close it, but I still would like to see it (or similar solution) in Joomla, is there any chance, or I am alone here? :smiley:

avatar elkuku
elkuku - comment - 22 Nov 2015

or I am alone here?

You're not. ;(

avatar fastslack
fastslack - comment - 24 Nov 2015

@Fedik no, you are not alone. It would be very nice that there is a unique solution for CLI scripts

avatar alikon
alikon - comment - 24 Nov 2015

may i join in ?
something similar was done in the past GSOC edition
https://www.youtube.com/watch?v=fIUYdzVvgzA

avatar mbabker
mbabker - comment - 24 Nov 2015

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.

Add a Comment

Login with GitHub to post a comment