19declare(strict_types=1);
28use Symfony\Component\Console\Input\InputInterface;
29use Symfony\Component\Console\Input\InputOption;
30use Symfony\Component\Console\Output\OutputInterface;
31use Symfony\Component\Console\Input\InputArgument;
36use InvalidArgumentException;
63 $this->agent_finder = $agent_finder;
64 $this->config_reader = $config_reader;
71 $this->setDescription(
"Achieve a named objective from an agent.");
74 InputArgument::OPTIONAL,
75 "Objective to be execute from an agent. Format: \$AGENT::\$OBJECTIVE"
77 $this->addArgument(
"config", InputArgument::OPTIONAL,
"Configuration file for the installation");
81 InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
82 "Define fields in the configuration file that should be overwritten, e.g. \"a.b.c=foo\"",
85 $this->addOption(
"yes",
"y", InputOption::VALUE_NONE,
"Confirm every message of the objective.");
86 $this->addOption(
"list",
null, InputOption::VALUE_NONE,
"Lists all achievable objectives");
89 protected function execute(InputInterface $input, OutputInterface $output):
int
92 $io->printLicenseMessage();
108 $input->getOption(
"list") !==
null
109 && is_bool($input->getOption(
"list"))
110 && $input->getOption(
"list")
114 $input->getArgument(
"objective") ===
""
115 || $input->getArgument(
"objective") === null
121 $io->
title(
"Listing available objectives");
123 $agentCollection = $this->agent_finder->getAgents();
124 foreach ($agentCollection->getNamedObjectives(
null) as $cmd => $objectiveCollection) {
126 $output->writeln($objectiveCollection->getDescription());
128 $output->writeln(
"");
134 $objective_name = $input->getArgument(
'objective');
136 $io->
title(
"Achieve objective: $objective_name");
139 if ($input->getArgument(
"config")) {
143 $namedObjectives = $agent->getNamedObjectives($config);
145 if (isset($namedObjectives[$objective_name])) {
146 $objective = $namedObjectives[$objective_name];
148 throw new InvalidArgumentException(
149 "There is no named objective '$objective_name'"
153 if ($this->preconditions !== []) {
155 $objective->create(),
156 ...$this->preconditions
159 $objective = $objective->create();
165 if ($config !==
null) {
170 $this->achieveObjective($objective, $environment, $io);
171 $io->
success(
"Achieved objective '$objective_name'. Thanks and have fun!");
173 $io->
error(
"Aborted the attempt to achieve '$objective_name', a necessary confirmation is missing:\n\n" .
$e->getRequestedConfirmation());
execute(InputInterface $input, OutputInterface $output)
executeAchieveObjective(IOWrapper $io, InputInterface $input)
shouldListNamedObjectives(InputInterface $input)
executeListNamedObjectives(IOWrapper $io, OutputInterface $output)
__construct(AgentFinder $agent_finder, ConfigReader $config_reader, array $preconditions, Refinery $refinery)
Read a json-formatted config from a file and overwrite some fields.
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
Signals that a necessary confirmation from the admin is missing.
A configuration with no content.
A wrapper around an objective that adds some preconditions.
An environment holds resources to be used in the setup process.
const RESOURCE_ADMIN_INTERACTION
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addAgentConfigsToEnvironment(Agent $agent, Config $config, Environment $environment)
trait HasAgent
Add this to an Command that has an agent.
getRelevantAgent(InputInterface $input)
readAgentConfig(Agent $agent, InputInterface $input, ?string $use_config_field=null)
trait HasConfigReader
Add this to an Command that has an config reader.