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

Feature request: Disabling/Hiding commands conditionally #1013

Open
saitho opened this issue Jan 15, 2021 · 1 comment · May be fixed by #1037
Open

Feature request: Disabling/Hiding commands conditionally #1013

saitho opened this issue Jan 15, 2021 · 1 comment · May be fixed by #1037

Comments

@saitho
Copy link
Contributor

saitho commented Jan 15, 2021

Hi there,

I'd like to disable commands conditionally (e.g. when the system environment is not fulfilled).
Obviously I could just check the command and abort it if conditions are not met.
However I'd like those commands to not even show up in the command list.

This could work like this:

public mytask() {
  echo 'I only run on Windows, ugh';
}
protected mytask__enabled(): bool {
  return PHP_OS_FAMILY === 'Windows';
}

So when collecting the commands, Robo would check for a [commandname]__enabled method.
If it exists and returns false, the command will be ignored.

The naming could be made more dynamic by using annotations (but would also mean some performance cost!):

/**
* @enabled windows_only
**/
public mytask() {
  echo 'I only run on Windows, ugh';
}
protected windows_only(): bool {
  return PHP_OS_FAMILY === 'Windows';
}

What are your opinions on that? :)

@saitho saitho changed the title Feature request: Disabling commands conditionally Feature request: Disabling/Hiding commands conditionally Jan 15, 2021
RyanNerd added a commit to RyanNerd/Robo that referenced this issue Jul 4, 2021
If a commands class has a `public string|array $hiddenCommands` property then any command listed in the property will not be added to Robo

Closes consolidation#1013
@RyanNerd RyanNerd linked a pull request Jul 4, 2021 that will close this issue
5 tasks
@RyanNerd
Copy link

RyanNerd commented Jul 4, 2021

Created a PR for this. The condition is set in the constructor by including a public array|string $hiddenCommands property and populating it with commands you don't want to appear in Robo. You can also use the @hidden annotation on any public function you don't want to expose to Robo.

See #1037 for example code

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 a pull request may close this issue.

2 participants