Writing A CLI Application

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
dannypsilon
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sun Nov 28, 2010 4:32 pm

Writing A CLI Application

Post by dannypsilon » Fri Mar 31, 2023 11:59 am

Hello,
can someone please tell me what I'm doing wrong.
I had CliApplication scripts in Joomla3 and now I want to make them Joomla4/5 compatible.
I already tried following this method https://docs.joomla.org/J4.x:Writing_A_CLI_Application and also tried following this one https://www.dionysopoulos.me/book/com-cli.html.
But whenever I call php cli/joomla.php list I don't see my command in the list.
Do I have to do something else, for example clear a cache?

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2677
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Writing A CLI Application

Post by ceford » Fri Mar 31, 2023 4:59 pm

Did you enable your plugin? Here is another example to look at:

https://docs.joomla.org/J4.x:CLI_example_-_Onoffbydate

dannypsilon
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sun Nov 28, 2010 4:32 pm

Re: Writing A CLI Application

Post by dannypsilon » Fri Mar 31, 2023 6:07 pm

I have now installed and activated the plugin https://github.com/ceford/j4xdemos-plg-onoffbydate but the php cli/joomla.php list shows no onoffbydate.
Do I need to do anything other than install and activate the plugin?

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2677
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Writing A CLI Application

Post by ceford » Fri Mar 31, 2023 6:49 pm

I just downloaded the zip file and installed it via System / Install / Extensions and it worked fine. I see it in the list with this command from the cli folder (using a terminal):

Code: Select all

ceford@cliff cli % php joomla.php                   
 finder
  finder:index                    Purges and rebuild the index
 onoffbydate
  onoffbydate:action              Called by cron to set the enabled state of a module.
 scheduler
  scheduler:list                  List all scheduled tasks
And this:

Code: Select all

ceford@cliff cli % php joomla.php --help onoffbydate:action
Usage:
  onoffbydate:action <action> <module_id>

Arguments:
  action                       name of action
  module_id                    module id

Options:
      --live-site[=LIVE-SITE]  The URL to your site, e.g. https://www.example.com
  -h, --help                   Display the help information
  -q, --quiet                  Flag indicating that all output should be silenced
  -V, --version                Displays the application version
      --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

Help:
  onoffbydate:action Toggles module Enabled/Disabled state
  			
  Usage: php joomla.php onoffbydate:action action_id module_id
  			
  where action_id is one of winter or weekend
I did not actually toggle a module because you said you do not see the command in the list.

dannypsilon
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sun Nov 28, 2010 4:32 pm

Re: Writing A CLI Application

Post by dannypsilon » Fri Mar 31, 2023 7:23 pm

Thanks, but the command really isn't in the list.
What version do you see when you type php joomla.php -V?
For me, Joomla! 4.2.6 displayed.

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2677
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Writing A CLI Application

Post by ceford » Fri Mar 31, 2023 7:58 pm

I see Joomla! 4.2.9. I think you should double check that the plugin is enabled. If I disable the plugin the command disappears from the list.


Locked

Return to “Joomla! 4.x Coding”