0.2.0: job engine, VM actions, theme-aware styling

This commit is contained in:
Claw committed 2026-11-17 19:23:28 +01:00
1 parent c62de24cc0
commit 485a267ffe
14 files changed
+901 -71

No files matched your search

+69
View File
@@ -122,6 +122,75 @@ switch ($cmd) {
}
);
case 'action':
$verb = $argv[1] ?? '';
$name = $argv[2] ?? '';
$confirm = '';
foreach ($argv as $a) {
if (str_starts_with($a, '--confirm=')) {
$confirm = substr($a, 10);
}
}
$check = vmm_action_check($verb, $name, $confirm);
if (!$check['ok']) {
if ($json) {
vmm_json(['ok' => false, 'error' => $check['error']], 1);
}
fwrite(STDERR, 'refused: ' . $check['error'] . "\n");
exit(1);
}
$job = vmm_job_new($verb, $name);
out(
['ok' => true, 'job' => $job],
$json,
static function (array $d): void {
printf("job %s queued: %s %s\n", $d['job']['id'], $d['job']['verb'], $d['job']['vm']);
}
);
case 'job':
$job = vmm_job_get($arg);
if ($job === null) {
if ($json) {
vmm_json(['ok' => false, 'error' => 'job not found'], 404);
}
fwrite(STDERR, "job not found\n");
exit(1);
}
$job['log'] = vmm_job_log($arg);
out(
['ok' => true, 'job' => $job],
$json,
static function (array $d): void {
printf("job %s %s %s state=%s rc=%s\n", $d['job']['id'], $d['job']['verb'], $d['job']['vm'], $d['job']['state'], $d['job']['rc'] ?? '-');
echo $d['job']['log'];
}
);
case 'jobs':
$jobs = vmm_job_list(50, $arg);
out(
['ok' => true, 'jobs' => $jobs],
$json,
static function (array $d): void {
foreach ($d['jobs'] as $j) {
printf("%-32s %-8s %-8s %-10s rc=%s\n", $j['id'], $j['verb'], $j['vm'], $j['state'], $j['rc'] ?? '-');
}
}
);
case 'cancel':
$res = vmm_job_cancel($arg);
out($res, $json, static function (array $d): void {
echo $d['ok'] ? "cancel requested\n" : ('error: ' . $d['error'] . "\n");
});
case 'recover':
$fixed = vmm_job_recover();
out(['ok' => true, 'fixed' => $fixed], $json, static function (array $d): void {
printf("%d interrupted job(s) marked failed\n", $d['fixed']);
});
case 'json':
vmm_json(vmm_selfcheck());
// no break