src/Environaut/Checks/ExecutableCheck.php
public function run()
    {
        $output = $this->getOutputStream();
        $dialog = $this->getDialogHelper();

        $command = $this->parameters->get('command', $this->getName());
        $setting = $this->parameters->get('setting', 'cmd.' . $command);
        $setting_group = $this->parameters->get('setting_group');
        $default = $this->parameters->get('default', '/usr/bin/' . $command);
        $choices = $this->parameters->get(
            'choices',
            array(
                '/bin/',
                '/usr/bin/',
                '/usr/sbin/',
                '/usr/local/bin/',
                '/usr/local/sbin/',
            )
        );
        $validator = $this->parameters->get('validator', array($this, 'validExecutable'));
        $max_attempts = $this->parameters->get('max_attempts', false);

        if ($this->cache->has($setting, $setting_group)) {
            $cached_setting = $this->cache->get($setting, $setting_group);
            $this->addInfo(
                "Setting [" . $cached_setting->getGroup() . "][$setting] already configured. Using " .
                'value: ' . var_export($cached_setting->getValue(), true)
            );
            $this->result->addSetting($cached_setting);
            return true;
        }

        $question = '<question>' . $this->parameters->get(
            'question',
            'Path to the executable "' . $command . '"'
        );

        // add default value to question if specified
        if (null !== $default) {
            $question .= "</question> (Default: which $default)";
        } else {
            $question .=  '</question>';
        }
        $question .= ': ';

        // ask for path to executable with validation and autocomplete of common executable directories like /usr/bin
        $absolute_executable_path = $dialog->askAndValidate(
            $output,
            $question,
            $validator,
            $max_attempts,
            $default,
            $choices
        );

        $this->addCachableSetting($setting, $absolute_executable_path, $setting_group);
        $this->addInfo('Got path to executable "' . $command . '": ' . $absolute_executable_path);

        return true;
    }
public function run()
    {
        $output = $this->getOutputStream();
        $dialog = $this->getDialogHelper();

        $command = $this->parameters->get('command', $this->getName());
        $setting = $this->parameters->get('setting', 'cmd.' . $command);
        $setting_group = $this->parameters->get('setting_group');
        $default = $this->parameters->get('default', '/usr/bin/' . $command);
        $choices = $this->parameters->get(
            'choices',
            array(
                '/bin/',
                '/usr/bin/',
                '/usr/sbin/',
                '/usr/local/bin/',
                '/usr/local/sbin/',
            )
        );
        $validator = $this->parameters->get('validator', array($this, 'validExecutable'));
        $max_attempts = $this->parameters->get('max_attempts', false);

        if ($this->cache->has($setting, $setting_group)) {
            $cached_setting = $this->cache->get($setting, $setting_group);
            $this->addInfo(
                "Setting [" . $cached_setting->getGroup() . "][$setting] already configured. Using " .
                'value: ' . var_export($cached_setting->getValue(), true)
            );
            $this->result->addSetting($cached_setting);
            return true;
        }

        $question = '<question>' . $this->parameters->get(
            'question',
            'Path to the executable "' . $command . '"'
        );

        // add default value to question if specified
        if (null !== $default) {
            $question .= "</question> (Default: which $default)";
        } else {
            $question .=  '</question>';
        }
        $question .= ': ';

        // ask for path to executable with validation and autocomplete of common executable directories like /usr/bin
        $absolute_executable_path = $dialog->askAndValidate(
            $output,
            $question,
            $validator,
            $max_attempts,
            $default,
            $choices
        );

        $this->addCachableSetting($setting, $absolute_executable_path, $setting_group);
        $this->addInfo('Got path to executable "' . $command . '": ' . $absolute_executable_path);

        return true;
    }
Ask user for an absolute path to the given executable or try to determine it
by itself using the default value (on confirmation).

@return boolean true

@throws \InvalidArgumentException on setup errors like "choices" can't be interpreted or parameters being wrong
@throws \RuntimeException if there is no data to read in the input stream
@throws \Exception when the maximum number of attempts has been reached and no valid response has been given