? ? Pending

User tests: Successful: Unsuccessful:

avatar alikon
alikon
27 Jun 2020

Summary of Changes

added a CLI command to retrieve the installed version of the Joomla CMS

Added an option -V or --version to display the CMS version

Testing Instructions

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
Screenshot from 2020-07-18 08-35-13

Actual result BEFORE applying this Pull Request

no core:version command listed

Expected result AFTER applying this Pull Request

core:version command is listed
and if you run
php cli/joomla.php -V
this is the result
Screenshot from 2020-07-18 08-41-05

Documentation Changes Required

yes

avatar alikon alikon - open - 27 Jun 2020
avatar alikon alikon - change - 27 Jun 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 27 Jun 2020
Category Libraries
avatar alikon alikon - change - 27 Jun 2020
The description was changed
avatar alikon alikon - edited - 27 Jun 2020
avatar alikon alikon - change - 27 Jun 2020
The description was changed
avatar alikon alikon - edited - 27 Jun 2020
avatar alikon alikon - change - 27 Jun 2020
The description was changed
avatar alikon alikon - edited - 27 Jun 2020
avatar mbabker
mbabker - comment - 27 Jun 2020

?

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 run php 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 the getLongVersion method to get it to print out “Joomla! 4.0.0-beta2-dev”.

avatar particthistle particthistle - test_item - 28 Jun 2020 - Tested successfully
avatar particthistle
particthistle - comment - 28 Jun 2020

I have tested this item successfully on b6f5eca

Before patch applied:
image

After patch applied:
image


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/29789.
avatar ceford ceford - test_item - 28 Jun 2020 - Tested successfully
avatar ceford
ceford - comment - 28 Jun 2020

I have tested this item successfully on b6f5eca

Fetching current Joomla version

Joomla! 4.0.0-beta2-dev Development [ Mañana ] 30-May-2020 21:13 GMT
[OK]


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/29789.
avatar alikon
alikon - comment - 28 Jun 2020

@mbabker even if you run php cli/joomla.php it is difficult to notice what the version is
plus every cli command that i know have an option to only show the version

avatar alikon alikon - change - 28 Jun 2020
Status Pending Ready to Commit
avatar alikon
alikon - comment - 28 Jun 2020

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/29789.
avatar mbabker
mbabker - comment - 28 Jun 2020

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.

avatar mbabker
mbabker - comment - 28 Jun 2020

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.

Screen Shot 2020-06-28 at 10 13 16 AM

avatar Quy Quy - change - 29 Jun 2020
Status Ready to Commit Pending
avatar alikon alikon - change - 18 Jul 2020
Labels Added: ?
avatar alikon
alikon - comment - 18 Jul 2020

finally found the time to apply @mbabker suggestion #29789 (comment)

avatar alikon alikon - change - 18 Jul 2020
The description was changed
avatar alikon alikon - edited - 18 Jul 2020
avatar alikon alikon - change - 18 Jul 2020
Title
[4.0][CLI] version command
[4.0][CLI] version option
avatar alikon alikon - edited - 18 Jul 2020
avatar alikon alikon - change - 18 Jul 2020
The description was changed
avatar alikon alikon - edited - 18 Jul 2020
avatar particthistle particthistle - test_item - 18 Jul 2020 - Tested successfully
avatar particthistle
particthistle - comment - 18 Jul 2020

I have tested this item successfully on 0356fe9

Tested successfully, but with a side issue that is not part of the pull request.


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

BEFORE Patch applied:
image
image

AFTER Patch applied:
image
image

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

avatar astridx
astridx - comment - 25 Jul 2020

Possible improvements

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

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

  3. And I spotted the related issue form the previous test, too.

My test

$ 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)
avatar astridx astridx - test_item - 25 Jul 2020 - Tested successfully
avatar astridx
astridx - comment - 25 Jul 2020

I have tested this item successfully on 0356fe9


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

avatar richard67 richard67 - change - 25 Jul 2020
Status Pending Ready to Commit
avatar richard67
richard67 - comment - 25 Jul 2020

RTC


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

avatar alikon
alikon - comment - 25 Jul 2020

thanks for testing
the CLI needs a little bit more of care

avatar astridx
astridx - comment - 25 Jul 2020
avatar wilsonge wilsonge - close - 25 Jul 2020
avatar wilsonge wilsonge - merge - 25 Jul 2020
avatar wilsonge wilsonge - change - 25 Jul 2020
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: ?
avatar wilsonge
wilsonge - comment - 25 Jul 2020

Thanks!

Add a Comment

Login with GitHub to post a comment