#[cfg(not(feature = "std"))]
compile_error!("asimov-http-fetcher requires the 'std' feature");
use asimov_module::SysexitsError::{self, *};
use clap::Parser;
use clientele::StandardOptions;
use std::error::Error;
#[derive(Debug, Parser)]
#[command(arg_required_else_help = true)]
struct Options {
#[clap(flatten)]
flags: StandardOptions,
url: String,
}
fn main() -> Result<SysexitsError, Box<dyn Error>> {
asimov_module::dotenv().ok();
let args = asimov_module::args_os()?;
let options = Options::parse_from(args);
if options.flags.version {
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
return Ok(EX_OK);
}
if options.flags.license {
print!("{}", include_str!("../../UNLICENSE"));
return Ok(EX_OK);
}
#[cfg(feature = "tracing")]
asimov_module::tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_max_level(&options.flags)
.with_level(options.flags.debug || options.flags.verbose > 0)
.with_target(options.flags.debug)
.with_file(false)
.without_time()
.init();
let mut output = std::io::stdout().lock();
let mut input = asimov_http_module::open(&options.url)?;
std::io::copy(&mut input, &mut output)?;
Ok(EX_OK)
}