2024-06-20 02:07:34 +09:00
|
|
|
mod command;
|
2024-06-20 05:08:33 +09:00
|
|
|
mod config;
|
2024-06-20 02:07:34 +09:00
|
|
|
|
|
|
|
use clap::{Parser, Subcommand};
|
2024-06-21 03:18:21 +09:00
|
|
|
use color_print::cprintln;
|
2024-06-20 02:07:34 +09:00
|
|
|
|
|
|
|
/// latest Firefish version as of this fishctl release
|
|
|
|
const FIREFISH_VERSION: &str = "20240613";
|
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
struct Args {
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: Commands,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
enum Commands {
|
|
|
|
/// Print fishctl version and the corresponding Firefish version
|
|
|
|
Version,
|
|
|
|
/// Modify or validate the config files
|
|
|
|
#[command(subcommand)]
|
|
|
|
Config(command::config::Commands),
|
|
|
|
}
|
|
|
|
|
2024-06-20 03:19:20 +09:00
|
|
|
async fn run() -> Result<(), command::Error> {
|
2024-06-20 02:07:34 +09:00
|
|
|
let args = Args::parse();
|
|
|
|
|
|
|
|
match args.command {
|
|
|
|
Commands::Version => command::version::run(),
|
2024-06-20 03:19:20 +09:00
|
|
|
Commands::Config(subcommand) => command::config::run(subcommand).await?,
|
2024-06-20 02:07:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-06-20 02:33:01 +09:00
|
|
|
|
2024-06-20 03:19:20 +09:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
let res = run().await;
|
2024-06-20 02:33:01 +09:00
|
|
|
|
2024-06-20 02:42:33 +09:00
|
|
|
if let Err(err) = res {
|
2024-06-21 03:18:21 +09:00
|
|
|
cprintln!("<r!><bold>Error:</></>");
|
2024-06-20 02:33:01 +09:00
|
|
|
println!(" raw: {:?}", err);
|
|
|
|
println!(" message: {}", err);
|
|
|
|
|
|
|
|
let mut err: &dyn std::error::Error = &err;
|
|
|
|
|
|
|
|
while let Some(src) = err.source() {
|
|
|
|
println!("caused by: {}", src);
|
|
|
|
err = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
}
|