Skip to content

Introducing the FOSSBilling CLI#1021

Merged
admdly merged 1 commit intomainfrom
console
Jul 3, 2024
Merged

Introducing the FOSSBilling CLI#1021
admdly merged 1 commit intomainfrom
console

Conversation

@yagiz-dev
Copy link
Copy Markdown
Member

@yagiz-dev yagiz-dev commented Mar 29, 2023

This PR starts working on a basic console application made with Symfony's console component.

I've also added three commands to begin with:

  • cache:clear
  • cron:run
  • system:version
  • system:releasenotes
  • theme:list

Keeping this as a draft while I'm still experimenting with it. Reviews and suggestions appreciated.

It's pretty easy to write commands. Modules now can have a /Commands subdirectory. I'll also update the example modules once this is merged.

The component also has great helpers for tables, progress bars and asking for user information.

image
image

@yagiz-dev yagiz-dev self-assigned this Mar 29, 2023
@yagiz-dev
Copy link
Copy Markdown
Member Author

yagiz-dev commented Mar 29, 2023

In the future, I might implement commands for modules. Modules would be able to define their own commands. Would be great for extensibility and maintainability.

Edit: In fact it would be better to do it before merging this and creating a whole new directory under /library.
Edit2: Done.

@yagiz-dev yagiz-dev added the enhancement New feature or request label Mar 29, 2023
@yagiz-dev
Copy link
Copy Markdown
Member Author

Here is how the tables look. They can also be tweaked to look different:

image

@admdly admdly force-pushed the main branch 3 times, most recently from b08f65b to b94d932 Compare November 29, 2023 00:28
@BelleNottelling
Copy link
Copy Markdown
Member

@evrifaessa any plans to get this to a mergeable state?

@ChristianGabs
Copy link
Copy Markdown

ChristianGabs commented Jun 19, 2024

I think this is really old

Few suggestion
Rebuild the console.php

<?php
if (php_sapi_name() !== 'cli') {
    die('This script can only be run from the command line.');
}

require_once __DIR__.'/load.php';
$di = include __DIR__.'/di.php';

$di['translate']();

$di->register(new \CristianG\PimpleConsole\ServiceProvider(), [
    /**
     * Set the console application name. Defaults to 'Console'
     * @param  string
     */
    'console.name'    => 'FossBilling Console Commands',
    /**
     * Set the console application version. Defaults to '1.0'
     * @param  string
     */
    'console.version' => $di['mod_service']('system')->getVersion(),
    /**
     * Set console application list
     * @param  array
     */
    'console.classes' => function ($di) {
        try {
            $modules = $di['mod_service']('extension')->getCoreAndActiveModules();
        } catch (Exception $e) {
            $modules = $di['mod']('extension')->getCoreModules();
        }
        $fullyQualifiedClassName = [];
        // Dynamically load the commands from the modules
        foreach ($modules as $module) {
            $cap = ucfirst($module);
            $commands = glob(__DIR__.'/modules/'.$cap.'/Commands/*.php');
            foreach ($commands as $command) {
                $commandClass = basename($command, '.php');
                // Construct the fully qualified class name
                $fullyQualifiedClassName[] = "\\Box\\Mod\\$cap\\Commands\\$commandClass";
            }
        }
        return $fullyQualifiedClassName;
    },
    'console.allow_namespace' => true,
    'console.di' => $di
]);

$console = $di['console'];

$console->run();

That will give ability to do

php console.php cron:run

or

php console.php --namespace="\Box\Mod\Cron\Commands\Run" cron:run

I need to review the Commands and I will give more feedback

image

cron:run both side

image

@admdly admdly force-pushed the console branch 7 times, most recently from 3e4bf32 to 97ba570 Compare July 3, 2024 03:17
Die when accessed through a browser

Move the commands under the modules

Added system:version

Added system:releasenotes

Added theme:list

Styling
@admdly admdly marked this pull request as ready for review July 3, 2024 03:21
@admdly
Copy link
Copy Markdown
Contributor

admdly commented Jul 3, 2024

I've updated this to fix any issues with main. I see no reason why this shouldn't be merged - it is an initial implementation, but serves as an excellent example going forward.

Huge thanks to @evrifaessa 🙂.

@admdly admdly merged commit d190414 into main Jul 3, 2024
@admdly admdly deleted the console branch July 3, 2024 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants