Package ready

This commit is contained in:
Maurice
2025-07-25 19:31:55 +02:00
parent 3d600026c5
commit 5bcd4bdca2
5 changed files with 299 additions and 54 deletions
+22 -6
View File
@@ -1,10 +1,12 @@
use std::fs;
use clap::Parser;
use crate::service::ServiceConfig;
mod service;
pub fn generate_openrc(config: &ServiceConfig) {
pub fn generate_openrc(config: &ServiceConfig) -> String {
let mut script = String::from("#!/sbin/openrc-run\n# !!! AUTO GENERATED - DO NOT EDIT !!!\n\n");
let wrap = |cmd: &str| {
if let Some(user) = config.user.as_ref() {
@@ -113,13 +115,27 @@ pub fn generate_openrc(config: &ServiceConfig) {
script.push_str("\n}\n\n");
// }
println!("\n\n{}", script);
script
}
/// Program to generate OpenRC scripts from Podman service definitions in TOML format.
#[derive(Debug, Parser)]
struct Args {
/// Definition file in TOML format
definition: String,
/// Output file for the OpenRC script
out: String,
}
fn main() {
let file = fs::read_to_string("example.toml").unwrap();
let service: ServiceConfig = toml::from_str(&file).unwrap();
println!("{:?}", service);
let args = Args::parse();
let input = fs::read_to_string(&args.definition)
.expect("Failed to read definition file");
let config: ServiceConfig = toml::from_str(&input)
.expect("Failed to parse definition file");
generate_openrc(&service);
let output = generate_openrc(&config);
fs::write(&args.out, output)
.expect("Failed to write OpenRC script to output file");
}