From 97dc3fe23acf2c35053aced7b34918bab7778c35 Mon Sep 17 00:00:00 2001 From: "Max P." Date: Wed, 21 May 2025 03:01:21 +0200 Subject: [PATCH] feat(cli): add command to generate systemd unit files - Introduces a CLI tool for creating systemd .timer and .service units - Adds options for configuring unit names, commands, scheduling, and more - Supports dry-run mode and user-level unit file generation --- src/cli/create.ts | 39 +++++++++++++++++++++++++++++++++++++++ src/cli/main.ts | 9 +++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/cli/create.ts create mode 100644 src/cli/main.ts diff --git a/src/cli/create.ts b/src/cli/create.ts new file mode 100644 index 0000000..20820f6 --- /dev/null +++ b/src/cli/create.ts @@ -0,0 +1,39 @@ +import { Command } from '@cliffy/command'; +import { generateUnitFiles } from '../templates/unit-generator.ts'; +import { TimerOptions } from '../types/options.ts'; + +export const createCommand = new Command() + .description('Erzeugt eine systemd .service und .timer Unit') + .option( + '--name ', + 'Name der Unit-Dateien (optional, wird sonst aus dem Exec generiert)', + ) + .option( + '--exec ', + 'Kommando, das durch systemd ausgeführt werden soll', + { required: true }, + ) + .option('--calendar ', 'OnCalendar-Ausdruck für den Timer', { + required: true, + }) + .option('--description ', 'Beschreibung des Timers') + .option('--user', 'Erstellt die Unit als User-Timer') + .option('--output ', 'Zielverzeichnis der Unit-Dateien') + .option( + '--after ', + 'Optionales After= für die Service-Unit', + { collect: true }, + ) + .option( + '--environment ', + 'Environment-Variablen im Format KEY=VALUE', + { collect: true }, + ) + .option( + '--logfile ', + 'Dateipfad für Log-Ausgabe (stdout/stderr)', + ) + .option('--dry-run', 'Gibt die Unit-Dateien nur aus, ohne sie zu schreiben') + .action(async (options: TimerOptions) => { + await generateUnitFiles(options); + }); diff --git a/src/cli/main.ts b/src/cli/main.ts new file mode 100644 index 0000000..20381bb --- /dev/null +++ b/src/cli/main.ts @@ -0,0 +1,9 @@ +import { Command } from '@cliffy/command'; +import { createCommand } from './create.ts'; + +await new Command() + .name('systemd-timer') + .version('0.1.0') + .description('CLI Tool zum Erzeugen von systemd .timer und .service Units') + .command('create', createCommand) + .parse(Deno.args);