Skip to content

Commit

Permalink
Merge pull request #20 from nrdxp/ip-flags
Browse files Browse the repository at this point in the history
Ip flags
  • Loading branch information
nrdxp authored Sep 20, 2023
2 parents a85a20e + 42a14f7 commit d402f33
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// deprecated: The CloudFlare API key to authenticate with, also requires email
#[clap(
long,
short,
Expand All @@ -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<String>,
/// deprecated: The CloudFlare email to authenticate with, also requires API key
#[clap(
long,
short,
Expand All @@ -51,6 +51,12 @@ pub struct Cli {

#[clap(flatten)]
pub verbose: Verbosity<InfoLevel>,
/// 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<Client> {
Expand Down
37 changes: 23 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -23,23 +24,31 @@ async fn main() -> Result<()> {
let mut handles: Vec<JoinHandle<Result<()>>> =
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);
}
}
}
}
Expand Down

0 comments on commit d402f33

Please sign in to comment.