use clap::Parser; mod rewriter; use env_logger::Env; use log::info; use rewriter::Rewriter; /// Implements a HTTP server which allows clients to 'register' /// themselves. Their IP address will be used to replace a /// needle in a set of config files. This is intended to be /// used as a low-cost way of enabling Kubernetes ingress /// using nginx running on a machine that has a public port. /// /// The needle is expected to be a dummy IP address; something /// fairly unique. The goal is to replace nginx files, where /// we often repeat lines if we want nginx to load balance between /// multiple destination IPs. #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Args { /// The needle that will be replaced. Anytime a line /// is encountered with this needle, the line is dropped /// and instead N lines (one per replacement) is added to /// the output. #[arg(short, long)] rewrite_string: String, /// The folder which contains the templates that /// will be be searched for the needle. #[arg(short, long)] source_folder: String, /// Where to write the replaced lines. #[arg(short, long)] dest_folder: String, } fn main() { // Log info and above by default env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); let args = Args::parse(); let mut rewriter = Rewriter::new(args.rewrite_string); rewriter.add_replacement(String::from("abc")); rewriter .rewrite_folder(&args.source_folder, &args.dest_folder) .unwrap(); info!("Finished writing new config to {}", args.dest_folder); }