hai/src/main.rs

92 lines
2.2 KiB
Rust
Raw Normal View History

2025-02-20 22:18:14 +01:00
/*
* SPDX-FileCopyrightText: 2025 April Faye John <april.john@denic.de> & Contributors
2025-02-19 00:08:36 +01:00
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
2020-08-21 02:47:38 +02:00
2025-02-19 00:08:36 +01:00
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
2020-08-21 02:47:38 +02:00
2025-02-19 00:08:36 +01:00
mod bininfo;
2025-02-20 22:18:14 +01:00
mod gui;
2025-02-20 14:04:16 +01:00
mod pman;
2020-08-21 02:47:38 +02:00
2025-02-20 22:18:14 +01:00
use bunt::println;
use clap::{Parser, Subcommand};
use log::info;
use pman::{init_process_manager, ProcessCommand, ProcessManager};
2025-02-19 00:08:36 +01:00
use shadow_rs::shadow;
2025-02-20 22:18:14 +01:00
use std::sync::{Arc, Mutex, OnceLock};
use tokio::{signal, sync::mpsc::Sender};
2020-08-21 02:47:38 +02:00
2025-02-19 00:08:36 +01:00
shadow!(build);
2020-08-21 02:47:38 +02:00
2025-02-20 22:18:14 +01:00
static PMAN_SENDER: OnceLock<Sender<ProcessCommand>> = OnceLock::new();
2025-02-19 00:08:36 +01:00
/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Name of the person to greet
//#[arg(short, long)]
//name: String,
2020-08-21 02:47:38 +02:00
2025-02-19 00:08:36 +01:00
/// Number of times to greet
//#[arg(short, long, default_value_t = 1)]
//count: u8,
2020-08-21 02:47:38 +02:00
2025-02-19 00:08:36 +01:00
#[command(subcommand)]
command: Commands,
}
2020-08-21 02:47:38 +02:00
2025-02-19 00:08:36 +01:00
#[derive(Debug, Subcommand)]
enum Commands {
#[command(arg_required_else_help = true, about = "todo replace this cmd")]
Clone {
/// The remote to clone
remote: String,
},
#[command(about = "List compile time backed info to audit binary")]
2025-02-20 22:18:14 +01:00
Shadow { outfile: Option<String> },
2025-02-20 14:04:16 +01:00
#[command(about = "Show test gui")]
Gui,
2025-02-20 22:18:14 +01:00
Devtest,
2020-08-21 02:47:38 +02:00
}
2025-02-20 22:18:14 +01:00
#[tokio::main]
async fn main() {
2020-08-21 02:47:38 +02:00
2025-02-20 22:18:14 +01:00
env_logger::init();
2025-02-19 00:08:36 +01:00
let args = Args::parse();
2020-08-21 02:47:38 +02:00
2025-02-20 22:18:14 +01:00
let _ = init_process_manager();
2025-02-20 14:04:16 +01:00
2025-02-19 00:08:36 +01:00
match args.command {
2025-02-20 22:18:14 +01:00
Commands::Clone { remote } => {}
2020-08-21 02:47:38 +02:00
2025-02-19 00:08:36 +01:00
Commands::Shadow { outfile } => {
bininfo::print_info();
return;
}
2025-02-20 14:04:16 +01:00
Commands::Gui => {
let res = gui::gui_main();
if let Err(e) = res {
println!("{}", e);
}
2025-02-20 22:18:14 +01:00
return;
2025-02-20 14:04:16 +01:00
}
2025-02-19 00:08:36 +01:00
2025-02-20 22:18:14 +01:00
Commands::Devtest => {
tokio::select! {
_ = signal::ctrl_c() => {
info!("Ctrl-c received");
let sender = PMAN_SENDER.get().unwrap();
let _ = sender.send(ProcessCommand::Shutdown).await;
}
}
}
2025-02-20 14:04:16 +01:00
};
2025-02-20 22:18:14 +01:00
//handling anything here for gui wont work
println!("exit");
2020-08-21 02:47:38 +02:00
}