Added value autocompletion for servers:remote

This commit is contained in:
Abdulmhsen B. A. A
2022-05-20 23:08:55 +03:00
parent be788a5b0a
commit bb2bf852d7

View File

@@ -9,6 +9,8 @@ use App\Libs\Config;
use App\Libs\Servers\ServerInterface;
use JsonException;
use RuntimeException;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputArgument;
@@ -199,4 +201,35 @@ final class RemoteCommand extends Command
$output->writeln(Yaml::dump($result, 8, 2));
}
}
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestOptionValuesFor('search-output')) {
$currentValue = $input->getCompletionValue();
$suggest = [];
foreach (['yaml', 'json'] as $name) {
if (empty($currentValue) || str_starts_with($name, $currentValue)) {
$suggest[] = $name;
}
}
$suggestions->suggestValues($suggest);
}
if ($input->mustSuggestArgumentValuesFor('name')) {
$currentValue = $input->getCompletionValue();
$suggest = [];
foreach (array_keys(Config::get('servers', [])) as $name) {
if (empty($currentValue) || str_starts_with($name, $currentValue)) {
$suggest[] = $name;
}
}
$suggestions->suggestValues($suggest);
}
}
}