mod cli;
mod commands;
mod context;
mod fix;
mod git;
mod hosts;
mod model;
mod paths;
mod report;
mod rules;
mod scan;
mod sources;
mod state;
mod time;
#[cfg(feature = "tui")]
mod tui;
mod update;
use clap::Parser;
use cli::{Cli, Command, Filter, Output};
use std::process::ExitCode;
fn main() -> ExitCode {
let cli = Cli::parse();
let is_update = matches!(cli.command, Some(Command::Update { .. }));
if let Ok(paths) = paths::Paths::from_env() {
if !is_update {
update::on_startup(&paths);
}
}
match run(cli) {
Ok(code) => code,
Err(error) => {
eprintln!("egrix: {error:#}");
ExitCode::from(2)
}
}
}
fn run(cli: Cli) -> anyhow::Result<ExitCode> {
match cli.command {
None => default_command(),
Some(Command::Scan { filter, output }) => commands::scan(&filter, &output),
Some(Command::Secrets { filter, output, group, show }) => commands::secrets(&filter, &output, group, show.as_deref()),
Some(Command::Egress { filter, output, show, all }) => commands::egress(&filter, &output, show.as_deref(), all),
Some(Command::Fix { filter, id, undo, yes }) => commands::fix(&filter, id.as_deref(), undo, yes),
Some(Command::Mark { id, rotated, ignored, clear }) => commands::mark(&id, rotated, ignored, clear),
Some(Command::Hosts { action }) => commands::hosts(&action),
Some(Command::Rules { action }) => commands::rules(&action),
Some(Command::Baseline { filter }) => commands::baseline(&filter),
Some(Command::Update { check, enable_auto, disable_auto, check_background }) => {
let paths = paths::Paths::from_env()?;
let opts = update::Options { check, enable_auto, disable_auto };
update::run(&paths, opts, check_background)?;
Ok(ExitCode::SUCCESS)
}
}
}
fn default_command() -> anyhow::Result<ExitCode> {
#[cfg(feature = "tui")]
{
use std::io::IsTerminal;
if std::io::stdout().is_terminal() && std::io::stdin().is_terminal() {
return tui::run();
}
}
commands::scan(&Filter::default(), &Output::default())
}