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 to conditionally hide commands #1037

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

RyanNerd
Copy link

@RyanNerd RyanNerd commented Jul 4, 2021

Overview

This pull request:

  • Fixes a bug
  • Adds a feature
  • Breaks backwards compatibility
  • Has tests that cover changes
  • Adds or fixes documentation

Summary

If a command class has a public string|array $hiddenCommands property then any command listed in the property will not be added to Robo

Closes #1013

Description

For example:

<?php
class MyCommands
{
    public $hiddenCommands = [];

    public function __construct()
    {
        if (str_contains('window', strtolower(PHP_OS))) {
            // We're using Windows so hide the linux:example command
            $this->hiddenCommands[] = 'linux:example';
        } else {
            // We're not using Windows so hide the com command
            $this->hiddenCommands[] = 'com';
        }
    }

    /**
     * This command will always be available
     */
    public function hello()
    {
        $this->say('Hi!');
    }

    /**
     * @hidden This command will not be available because it has a hidden attribute
     */
    public function goodBye()
    {
        $this->say('Bye!');
    }

    /**
     * Command will not work in Windows
     * @link: https://www.php.net/manual/en/function.cli-set-process-title.php
     */
    public function linuxExample()
    {
        $title = "My Amazing PHP Script";
        $pid = getmypid(); // you can use this to see your process title in ps

        if (!cli_set_process_title($title)) {
            echo "Unable to set process title for PID $pid...\n";
            exit(1);
        } else {
            echo "The process title '$title' for PID $pid has been set for your process!\n";
            sleep(5);
        }
    }

    /**
     * COM is only available on Windows
     */
    public function com()
    {
        $domainObject = new COM("WinNT://Domain");
        foreach ($domainObject as $obj) {
            $this->say($obj->Name);
        }
    }
}

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

Feature request: Disabling/Hiding commands conditionally
1 participant