garden-cli icon indicating copy to clipboard operation
garden-cli copied to clipboard

Add a way to get registered commands

Open miile7 opened this issue 4 years ago • 4 comments

Currently there is no way to get the commands registered by the CLI::command() method.

miile7 avatar Jun 23 '21 05:06 miile7

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jun 23 '21 05:06 CLAassistant

My use case is the following: I have a program performing some routines. There I have a "all" command performing all (major) routines, just to save some typing and thinking time and to prevent errors by forgotten routine executions.

For executing all commands, I need to have an array containing the commands that should be executed when executing "all". Therefore I am missing a CLI::getCommands() function.

miile7 avatar Jun 23 '21 05:06 miile7

I would also like to have this functionality please and it seems like the pull request was never accepted. Here is my use case:

I have cron.php script that is executed with various commands to execute various jobs. One of these jobs is to check if any of the other jobs have been running for too long and it requires a list of all the available Cli commands to know which jobs it should check for. There are other ways to do this of course but it would make sense to have a function to retrieve all the available commands.

Donatello-za avatar Feb 23 '22 06:02 Donatello-za

@Donatello-za Sadly I'm still waiting for my PR getting accepted. In the mean time I created a custom class that extends CLI and adds the command:

class MyCli extends Cli {
   /**
     * Returns all available commands.
     *
     * @return string[] Returns the available commands as an array.
     */
    public function getCommands() {
        return array_filter(array_keys($this->commandSchemas), ["self", "isCommand"]);
    }
}

It works but it's kind of unsatisfying.

miile7 avatar Feb 24 '22 11:02 miile7