diff --git a/src/cli.rs b/src/cli.rs index 9e1f972..97f7764 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -11,6 +11,7 @@ use clap::{Parser, ValueEnum}; )] pub struct Opts { /// Domain name to query + #[arg(value_parser = is_domain)] pub domain: String, /// Record Type @@ -33,3 +34,11 @@ pub enum RecordType { SOA, TXT, } + +fn is_domain(domain: &str) -> Result { + if domain.contains('.') { + Ok(domain.to_string()) + } else { + Err(format!("{} isn't a valid domain", domain)) + } +} diff --git a/src/error.rs b/src/error.rs index 33f6be4..0b27fe1 100755 --- a/src/error.rs +++ b/src/error.rs @@ -12,9 +12,6 @@ pub enum Error { #[error("{0}")] InvalidArgument(String), - #[error("Invalid domain {0:?}")] - InvalidDomain(String), - #[error("Configuration file is not found `{path}`")] #[diagnostic( code(digs::no_config), diff --git a/src/main.rs b/src/main.rs index e98aff5..e9b9b42 100755 --- a/src/main.rs +++ b/src/main.rs @@ -4,12 +4,11 @@ use trust_dns_client::rr::RecordType; use clap::Parser; use miette::Result; -use digs::{cli, cli::Opts, error::Error, output::Printer}; +use digs::{cli, cli::Opts, output::Printer}; fn run() -> Result<()> { let opts = Opts::parse(); - let domain = is_domain(&opts.domain)?; let record_type = match opts.rtype { cli::RecordType::A => RecordType::A, cli::RecordType::AAAA => RecordType::AAAA, @@ -21,19 +20,11 @@ fn run() -> Result<()> { }; let config_file = opts.config; - let printer = Printer::new(domain, record_type, config_file); + let printer = Printer::new(opts.domain, record_type, config_file); printer.print()?; Ok(()) } -fn is_domain(domain: &str) -> Result { - if domain.contains('.') { - Ok(domain.to_string()) - } else { - Err(Error::InvalidDomain(domain.to_string())) - } -} - fn main() { if let Err(err) = run() { eprintln!("Error: {:?}", err); diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 5734149..504db46 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -124,7 +124,7 @@ fn domain_invalid() -> Result<(), Box> { cmd.arg("example"); cmd.assert() .failure() - .stderr(predicate::str::contains(r#"Invalid domain "example""#)); + .stderr(predicate::str::contains(r#"example isn't a valid domain"#)); Ok(()) }