summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-07-24 19:47:07 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-07-24 19:47:07 -0400
commit3fbc6b94c7e4cad06902d01d5b14694d23fa71c9 (patch)
tree17fac79a5dc606e27c640b23172e9e0af3206f1d /src
parentf2d288fd5d1054075374f3f7229f8a9332adf61c (diff)
Legibility improvements to main.
The explicit panic is a conscious decision; clap doesn't have a better way to represent mutually-exclusive options, so we have to use two boolean fields, but it will actually prevent the user from passing both options and triggering that code path. Since it's one of the rare situations where design choices converge on a truly unreachable case, I thought I'd make it easier to discover when I'm wrong and it is actually reachable. The old logic treated (true, true) like (false, false).
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 96758be..0362b5e 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -42,20 +42,18 @@ pub struct Args {
impl Args {
pub async fn run(self) -> Result<()> {
let args = Args::parse();
- let name = args.autoscaling_group;
let aws_context = AwsContext::from_env().await;
- let apply_mode = if args.dry_run {
- ApplyMode::DryRun
- } else if args.apply {
- ApplyMode::Apply
- } else {
- ApplyMode::DryRun
- };
+ let changes = named_asg_changes(
+ &aws_context,
+ &args.autoscaling_group,
+ &args.dns_name,
+ args.dns_ttl,
+ )
+ .await?;
- let changes = named_asg_changes(&aws_context, &name, &args.dns_name, args.dns_ttl).await?;
- apply_mode
+ self.apply_mode()
.apply(
&aws_context,
&changes.zone_id,
@@ -66,4 +64,14 @@ impl Args {
Ok(())
}
+
+ fn apply_mode(&self) -> ApplyMode {
+ use ApplyMode::*;
+ match (self.dry_run, self.apply) {
+ (true, false) => DryRun,
+ (false, true) => Apply,
+ (false, false) => DryRun,
+ (true, true) => unreachable!("Cannot set --apply and --dry-run together"),
+ }
+ }
}