Skip to content

Commit

Permalink
updated flag retrieval so that it does not always return true
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyshazam authored and rtyler committed Dec 7, 2023
1 parent 3eac101 commit 2aa6749
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ async fn main() -> anyhow::Result<()> {
.unwrap()
.to_string();

let end_at_last_offsets = ingest_matches.contains_id("end");
let end_at_last_offsets = ingest_matches.get_flag("end");

// ingest_matches.get_flag("end")
let format = convert_matches_to_message_format(ingest_matches).unwrap();

let options = IngestOptions {
Expand Down Expand Up @@ -427,6 +428,7 @@ This can be used to provide TLS configuration as in:
.long("ends_at_latest_offsets")
.required(false)
.num_args(0)
.action(ArgAction::SetTrue)
.help(""))
)
.arg_required_else_help(true)
Expand All @@ -450,6 +452,7 @@ fn convert_matches_to_message_format(

#[cfg(test)]
mod test {
use clap::ArgMatches;
use kafka_delta_ingest::{MessageFormat, SchemaSource};

use crate::{
Expand Down Expand Up @@ -526,7 +529,26 @@ mod test {
));
}

#[test]
fn get_end_at_last_offset() {
let values = ["-e", "--ends_at_latest_offsets"];
for value in values {
let subcommand = get_subcommand_matches_raw(vec![value]);
assert_eq!(true, subcommand.contains_id("end"));
assert_eq!(true, subcommand.get_flag("end"));
}

let subcommand = get_subcommand_matches_raw(vec![]);
assert_eq!(true, subcommand.contains_id("end"));
assert_eq!(false, subcommand.get_flag("end"));
}

fn get_subcommand_matches(args: Vec<&str>) -> Result<MessageFormat, SchemaSourceError> {
let arg_matches = get_subcommand_matches_raw(args);
return convert_matches_to_message_format(&arg_matches);
}

fn get_subcommand_matches_raw(args: Vec<&str>) -> ArgMatches {
let base_args = vec![
"app",
"ingest",
Expand All @@ -536,8 +558,8 @@ mod test {
"test",
];
let try_matches = build_app().try_get_matches_from([base_args, args].concat());
let matches = try_matches.unwrap();
let (_, subcommand) = matches.subcommand().unwrap();
return convert_matches_to_message_format(subcommand);
let mut matches = try_matches.unwrap();
let (_, subcommand) = matches.remove_subcommand().unwrap();
subcommand
}
}

0 comments on commit 2aa6749

Please sign in to comment.