Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to get registered commands #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

miile7
Copy link

@miile7 miile7 commented Jun 23, 2021

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

Adding CLI::getCommands() function returning an array containing all command names as strings.
@CLAassistant
Copy link

CLAassistant commented Jun 23, 2021

CLA assistant check
All committers have signed the CLA.

@miile7
Copy link
Author

miile7 commented Jun 23, 2021

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.

@Donatello-za
Copy link

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.

@miile7
Copy link
Author

miile7 commented Feb 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants