User tests: Successful: Unsuccessful:
added a CLI command to retrieve the installed version of the Joomla CMS
Added an option -V or --version to display the CMS version
make sure you have this one joomla-framework/console@6727b2b
apply the patch go to the terminal
run php cli\joomla.php
you'll see a new option
you'll see a new entry on the available cli commands core:version
no core:version command listed
core:version command is listed
and if you run
php cli/joomla.php -V
this is the result
yes
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
I have tested this item
Before patch applied:
Joomla! 4.0.0-beta2-dev Development [ Mañana ] 30-May-2020 21:13 GMT
[OK]
Status | Pending | ⇒ | Ready to Commit |
RTC
it is difficult to notice what the version is
IMO this is because of the bug I noted previously. When the console integration first landed, it correctly printed “Joomla! version” but through changes to make CLI fit the web application interface it now prints “cli version” which does make it difficult to discover in the default output.
I don’t think a dedicated command is necessary here. To me, it’s extra junk. Fix the default list command output and what you have there is good enough.
If you REALLY want a dedicated version output, the convention in CLI applications is to use a -- version
option flag and not a full command. I’ve added this to the console package (the app already supported printing the version, but the option was missing from the definition, hence the bugfix to add the option being necessary otherwise it wouldn’t work right). So we’re back to needing the bugfix I mentioned before of making the CMS’ extended console application print the correct thing.
I'm in a good mood today. Here's a diff for you that solves the output problem, plus raises a warning if trying to use the console's name API (which conflicts with the CMS application interface's name API):
diff --git a/libraries/src/Application/ConsoleApplication.php b/libraries/src/Application/ConsoleApplication.php
index 64197d921b..aaf530388f 100644
--- a/libraries/src/Application/ConsoleApplication.php
+++ b/libraries/src/Application/ConsoleApplication.php
@@ -40,7 +40,7 @@ class ConsoleApplication extends Application implements DispatcherAwareInterface
/**
* The input.
*
- * @var \Joomla\Input\Input
+ * @var Input
* @since 4.0.0
*/
protected $input = null;
@@ -113,7 +113,6 @@ class ConsoleApplication extends Application implements DispatcherAwareInterface
parent::__construct($input, $output, $config);
- $this->setName('Joomla!');
$this->setVersion(JVERSION);
// Register the client name as cli
@@ -246,6 +245,21 @@ class ConsoleApplication extends Application implements DispatcherAwareInterface
$this->messages[$type][] = $msg;
}
+ /**
+ * Get the long version string for the application.
+ *
+ * Overrides the parent method due to conflicting use of the getName method between the console application and
+ * the CMS application interface.
+ *
+ * @return string
+ *
+ * @since 4.0.0
+ */
+ public function getLongVersion(): string
+ {
+ return sprintf('Joomla! <info>%s</info> (debug: %s)', (new Version)->getShortVersion(), (defined('JDEBUG') && JDEBUG ? 'Yes' : 'No'));
+ }
+
/**
* Gets the name of the current running application.
*
@@ -372,6 +386,21 @@ class ConsoleApplication extends Application implements DispatcherAwareInterface
return true;
}
+ /**
+ * Set the name of the application.
+ *
+ * @param string $name The new application name.
+ *
+ * @return void
+ *
+ * @since 4.0.0
+ * @throws \RuntimeException because the application name cannot be changed
+ */
+ public function setName(string $name): void
+ {
+ throw new \RuntimeException('The console application name cannot be changed');
+ }
+
/**
* Sets the session for the application to use, if required.
*
And the resulting output (includes joomla-framework/console@6727b2b to show the option is available). IMO the command is not necessary with the application corrected.
Status | Ready to Commit | ⇒ | Pending |
Labels |
Added:
?
|
finally found the time to apply @mbabker suggestion #29789 (comment)
Title |
|
I have tested this item
Tested successfully, but with a side issue that is not part of the pull request.
RELATED ISSUE
As discussed with @alikon while testing during BFH today,
libraries/vendor/joomla/console/src/Application.php around line 728 needs to have:
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Displays the application version'),
to appear in the options list when you run php cli/joomla.php
Possible improvements
if you forget a hyphen and enter php cli/joomla.php -version
, you see an error message (see below). Perhaps we can catch this message.
I am not sure but i think (and read) we need to change the import in line 24 of libraries/src/Application/ConsoleApplication.php
from
use Joomla\Input\Input;
to
use Joomla\Input\Input as Input;
so that the change in the doc-block in line 42 is correct.
And I spotted the related issue form the previous test, too.
$ git checkout 4.0-dev
Switched to branch '4.0-dev'
Your branch is up-to-date with 'origin/4.0-dev'.
$ php cli/joomla.php
cli 4.0.0-beta3-dev
Usage:
command [options] [arguments]
Options:
-h, --help Display the help information
-q, --quiet Flag indicating that all output should be silenced
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Flag to disable interacting with the user
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Show the help for a command
list List the application's available commands
cache
cache:clean Clean expired cache entries
config
config:get Display the current value of a configuration option
config:set Set a value for a configuration option
core
core:check-updates Check for Joomla updates
core:update Update Joomla
database
database:export Export the database
database:import Import the database
extension
extension:install Install an extension from a URL or from a path
extension:list List installed extensions
extension:remove Remove an extension
session
session:gc Perform session garbage collection
session:metadata:gc Perform session metadata garbage collection
site
site:down Put the site into offline mode
site:up Put the site into online mode
update
update:extensions:check Check for pending extension updates
update:joomla:remove-old-files Remove old system files
user
user:add Add a user
user:addtogroup Add a user to a group
user:delete Delete a user
user:list List all users
user:removefromgroup Remove a user from a group
user:reset-password Change a user's password
$ php cli/joomla.php -V
cli 4.0.0-beta3-dev
$ git status
On branch 4.0-dev
Your branch is up-to-date with 'origin/4.0-dev'.
Then I applied the patch via
git fetch origin pull/29789/head:patch-81
git checkout patch-81
After that:
---
$ git fetch origin pull/29789/head:patch-81
remote: Enumerating objects: 35, done.
remote: Counting objects: 100% (35/35), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 47 (delta 33), reused 32 (delta 32), pack-reused 12
Unpacking objects: 100% (47/47), done.
From https://github.com/joomla/joomla-cms
* [new ref] refs/pull/29789/head -> patch-81
$ git checkout patch-81
Switched to branch 'patch-81'
$ php cli/joomla.php
Joomla! 4.0.0-beta2-dev (debug: No)
Usage:
command [options] [arguments]
Options:
-h, --help Display the help information
-q, --quiet Flag indicating that all output should be silenced
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Flag to disable interacting with the user
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Show the help for a command
list List the application's available commands
cache
cache:clean Clean expired cache entries
config
config:get Displays the current value of a configuration option
config:set Sets a value for a configuration option
core
core:check-updates Checks for Joomla updates
core:update Updates joomla core
database
database:export Export the database
database:import Import the database
extension
extension:install Installs an extension from a URL or from a Path.
extension:list List installed extensions
extension:remove Removes an extension
session
session:gc Perform session garbage collection
session:metadata:gc Perform session metadata garbage collection
site
site:down Puts the site into offline mode
site:up Puts the site into online mode
update
update:extensions:check Check for pending extension updates
update:joomla:remove-old-files Remove old system files
user
user:add Add a user
user:addtogroup Add a user to group
user:delete Delete a user
user:list List all users
user:removefromgroup Remove a user from a group
user:reset-password Changes a user's password
$ php cli/joomla.php -V
Joomla! 4.0.0-beta2-dev (debug: No)
$ php cli/joomla.php -version
Symfony\Component\ErrorHandler\Error\ClassNotFoundError^ {#622
#message: """
Attempted to load class "Helper" from namespace "Joomla\Console".\n
Did you forget a "use" statement for another namespace?
"""
#code: 0
#file: "./libraries/vendor/joomla/console/src/Application.php"
#line: 955
trace: {
./libraries/vendor/joomla/console/src/Application.php:955 { …}
./libraries/vendor/joomla/console/src/Application.php:918 { …}
./libraries/vendor/joomla/console/src/Application.php:416 { …}
./libraries/vendor/joomla/console/src/Application.php:449 { …}
./libraries/src/Application/ConsoleApplication.php:225 {
Joomla\CMS\Application\ConsoleApplication->execute()^
›
› \tparent::execute();
› }
}
./cli/joomla.php:69 { …}
}
}
astrid@astrid-TravelMate-5760G:/var/www/html/joomla-cms4$ php cli/joomla.php --version
Joomla! 4.0.0-beta2-dev (debug: No)
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC
thanks for testing
the CLI needs a little bit more of care
Please see: joomla-framework/console#5
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-07-25 22:55:44 |
Closed_By | ⇒ | wilsonge | |
Labels |
Added:
?
|
Thanks!
You shouldn’t need a dedicated version command. The version is shown at the top of the output of the
list
command (which is the default command if you don’t even provide a command name, i.e. just runphp cli/joomla.php
).There is a bug though in this output. Right now it prints “cli 4.0.0-beta2-dev”, the CMS application interface is overloading the console application’s intended use of the
getName()
method, so the CMS’ console application class should probably extend thegetLongVersion
method to get it to print out “Joomla! 4.0.0-beta2-dev”.