summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-07-23 19:10:13 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-07-23 19:31:13 -0400
commit5429d2ab901380a92535e31c8cce6646e9b11c4f (patch)
tree760f274979c64185e6bc3710cc85030eb991cb0d
parentbd0ab7e0b9ed4584e2973f96c25799aada2b52e9 (diff)
Move CLI glue inside of the lib crate.
This allows me to stop exporting symbols that were only exported for the purposes of making the CLI work. This commit makes the minimum version for the next release 0.2.0, as it retires multiple symbols that are part of the lib crate's API in v0.1.x.
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/bin/aws-autoscaling-dns.rs9
-rw-r--r--src/cli.rs (renamed from src/bin/aws-autoscaling-dns/main.rs)56
-rw-r--r--src/lib.rs9
5 files changed, 45 insertions, 33 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7dd3223..233d7be 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -99,7 +99,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "aws-autoscaling-dns"
-version = "0.1.1-alpha.1"
+version = "0.2.0-alpha.1"
dependencies = [
"anyhow",
"aws-config",
diff --git a/Cargo.toml b/Cargo.toml
index 5478f39..2607a8f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "aws-autoscaling-dns"
-version = "0.1.1-alpha.1"
+version = "0.2.0-alpha.1"
authors = ["owen@grimoire.ca"]
readme = "README.md"
diff --git a/src/bin/aws-autoscaling-dns.rs b/src/bin/aws-autoscaling-dns.rs
new file mode 100644
index 0000000..6999b6b
--- /dev/null
+++ b/src/bin/aws-autoscaling-dns.rs
@@ -0,0 +1,9 @@
+use clap::Parser;
+
+use aws_autoscaling_dns::cli;
+
+#[tokio::main]
+async fn main() -> cli::Result {
+ let args = cli::Args::parse();
+ args.run().await
+}
diff --git a/src/bin/aws-autoscaling-dns/main.rs b/src/cli.rs
index 8da99b2..75bb5ef 100644
--- a/src/bin/aws-autoscaling-dns/main.rs
+++ b/src/cli.rs
@@ -3,10 +3,9 @@ use std::fmt::Debug;
use clap::Parser;
use trust_dns_proto::rr::Name;
-use aws_autoscaling_dns::apply::ApplyMode;
-use aws_autoscaling_dns::aws_context::AwsContext;
-use aws_autoscaling_dns::converge::named_asg_changes;
-use aws_autoscaling_dns::result::Result;
+use crate::apply::ApplyMode;
+use crate::aws_context::AwsContext;
+use crate::converge::named_asg_changes;
/// Synchronize a DNS entry with an autoscaling group's running instances.
///
@@ -16,7 +15,7 @@ use aws_autoscaling_dns::result::Result;
/// modified, so this can be used alongside DNS ACME verification, SPF, and other
/// DNS applications.
#[derive(Parser, Debug)]
-struct Args {
+pub struct Args {
/// The name of the autoscaling group to synchronize.
#[arg(long)]
autoscaling_group: String,
@@ -39,30 +38,33 @@ struct Args {
apply: bool,
}
-#[tokio::main]
-async fn main() -> Result<()> {
- let args = Args::parse();
- let name = args.autoscaling_group;
+pub type Result = crate::result::Result<()>;
- let aws_context = AwsContext::from_env().await;
+impl Args {
+ pub async fn run(self) -> Result {
+ let args = Args::parse();
+ let name = args.autoscaling_group;
- let apply_mode = if args.dry_run {
- ApplyMode::DryRun
- } else if args.apply {
- ApplyMode::Apply
- } else {
- ApplyMode::DryRun
- };
+ let aws_context = AwsContext::from_env().await;
- let changes = named_asg_changes(&aws_context, &name, &args.dns_name, args.dns_ttl).await?;
- apply_mode
- .apply(
- &aws_context,
- &changes.zone_id,
- changes.remove,
- changes.insert,
- )
- .await?;
+ let apply_mode = if args.dry_run {
+ ApplyMode::DryRun
+ } else if args.apply {
+ ApplyMode::Apply
+ } else {
+ ApplyMode::DryRun
+ };
- Ok(())
+ let changes = named_asg_changes(&aws_context, &name, &args.dns_name, args.dns_ttl).await?;
+ apply_mode
+ .apply(
+ &aws_context,
+ &changes.zone_id,
+ changes.remove,
+ changes.insert,
+ )
+ .await?;
+
+ Ok(())
+ }
}
diff --git a/src/lib.rs b/src/lib.rs
index ccfa2ac..7de39bd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,10 +1,11 @@
-pub mod apply;
+mod apply;
mod autoscaling;
-pub mod aws_context;
-pub mod converge;
+mod aws_context;
+pub mod cli;
+mod converge;
mod dns;
mod ec2;
mod hashable;
-pub mod result;
+mod result;
mod route53;
mod single;