diff --git a/src/api.rs b/src/api.rs index e0abc92..5cce203 100644 --- a/src/api.rs +++ b/src/api.rs @@ -26,8 +26,8 @@ pub struct Cli { value_name = "TOKEN", required_unless_present_all(["key", "email"]) )] - /// deprecated: The CloudFlare API key to authenticate with, also requires email pub token: Option, + /// deprecated: The CloudFlare API key to authenticate with, also requires email #[clap( long, short, @@ -37,8 +37,8 @@ pub struct Cli { required_unless_present("token"), requires("email") )] - /// deprecated: The CloudFlare email to authenticate with, also requires API key pub key: Option, + /// deprecated: The CloudFlare email to authenticate with, also requires API key #[clap( long, short, @@ -51,6 +51,12 @@ pub struct Cli { #[clap(flatten)] pub verbose: Verbosity, + /// set an AAAA record to the host's ipv6 address + #[clap(short = '6')] + pub ipv6: bool, + /// set an A record to the host's ipv4 address + #[clap(short = '4')] + pub ipv4: bool, } pub fn get_client(cli: &Cli) -> Result { diff --git a/src/main.rs b/src/main.rs index d308174..4d917c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use tokio::task::JoinHandle; #[tokio::main] async fn main() -> Result<()> { let cli = Cli::parse(); + let (mut set_v4, mut set_v6) = (cli.ipv4, cli.ipv6); pretty_env_logger::formatted_builder() .filter_level(cli.verbose.log_level_filter()) @@ -23,23 +24,31 @@ async fn main() -> Result<()> { let mut handles: Vec>> = Vec::with_capacity(cli.records.len()); + if (false, false) == (cli.ipv4, cli.ipv6) { + (set_v4, set_v6) = (true, true); + } + for (name, id, a, aaaa) in records { if let Some(id) = id { - if let Some(handle) = public_ipv4.update( - api_client.clone(), - a, - name.clone(), - id.clone(), - ) { - handles.push(handle); + if set_v4 { + if let Some(handle) = public_ipv4.update( + api_client.clone(), + a, + name.clone(), + id.clone(), + ) { + handles.push(handle); + } } - if let Some(handle) = public_ipv6.update( - api_client.clone(), - aaaa, - name.clone(), - id.clone(), - ) { - handles.push(handle); + if set_v6 { + if let Some(handle) = public_ipv6.update( + api_client.clone(), + aaaa, + name.clone(), + id.clone(), + ) { + handles.push(handle); + } } } }