1pub mod cmds;2pub mod command;3pub mod host;4pub mod keys;56mod fleetdata;78use std::io;910use anyhow::{anyhow, Result};11use clap::Parser;1213use cmds::{build_systems::BuildSystems, info::Info, secrets::Secrets};14use host::{Config, FleetOpts};15use tracing::{info, metadata::LevelFilter};16use tracing_subscriber::EnvFilter;1718#[derive(Parser)]19enum Opts {20 21 BuildSystems(BuildSystems),22 23 #[clap(subcommand)]24 Secrets(Secrets),25 26 Info(Info),27}2829#[derive(Parser)]30#[clap(version = "1.0", author)]31struct RootOpts {32 #[clap(flatten)]33 fleet_opts: FleetOpts,34 #[clap(subcommand)]35 command: Opts,36}3738async fn run_command(config: &Config, command: Opts) -> Result<()> {39 match command {40 Opts::BuildSystems(c) => c.run(config).await?,41 Opts::Secrets(s) => s.run(config).await?,42 Opts::Info(i) => i.run(config).await?,43 };44 Ok(())45}4647#[tokio::main]48async fn main() -> Result<()> {49 let filter = EnvFilter::from_default_env().add_directive(LevelFilter::INFO.into());50 tracing_subscriber::FmtSubscriber::builder()51 .with_env_filter(filter)52 .without_time()53 .with_target(false)54 .with_writer(|| {55 56 io::stderr()57 })58 .try_init()59 .map_err(|e| anyhow!("Failed to initialize logger: {}", e))?;6061 info!("Starting");62 let opts = RootOpts::parse();63 let config = opts.fleet_opts.build()?;6465 match run_command(&config, opts.command).await {66 Ok(()) => {67 config.save()?;68 Ok(())69 }70 Err(e) => {71 let _ = config.save();72 Err(e)73 }74 }75}