#![doc = include_str!("../README.md")]
use std::io;
use clap::Parser;
pub mod app;
pub mod config;
pub mod events;
pub mod key_bindings;
pub mod service;
pub mod service_groups;
pub mod ui;
use crate::app::App;
pub fn main() -> io::Result<()> {
let args = Cli::parse();
let mut app = App::init()?;
if args.cli() {
args.run_cli(&mut app)
} else {
ratatui::run(|terminal| app.run(terminal))
}
}
#[derive(Parser)]
#[command(author, version, about)]
pub struct Cli {
#[arg(short = 'a', long = "activate", value_name = "SERVICE_GROUP")]
activate: Option<String>,
#[arg(short = 'e', long = "enable", value_name = "SERVICE_GROUP")]
enable: Option<String>,
#[arg(short = 'l', long = "list")]
list: bool,
}
impl Cli {
fn cli(&self) -> bool {
self.activate.is_some() || self.enable.is_some() || self.list
}
fn run_cli(&self, app: &mut App) -> io::Result<()> {
if self.list {
app.list_service_groups();
}
if let Some(service) = &self.activate {
let active = app.toggle_activate(Some(service.clone()));
if let Ok(active) = active {
let active = if active { "active" } else { "inactive" };
println!("Services {} is {}", service, active)
} else {
println!("Failed to toggle activate for service: {}", service)
}
}
if let Some(service) = &self.enable {
let enabled = app.toggle_enabled(Some(service.clone()));
if let Ok(enabled) = enabled {
let enabled = if enabled { "enabled" } else { "disabled" };
println!("Services {} is {}", service, enabled)
} else {
println!("Failed to toggle enable for service: {}", service)
}
}
app.save()
}
}