Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ip flags #20

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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