Skip to content

Commit

Permalink
use no-stream to disable streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ducaale committed Apr 12, 2024
1 parent 4fd1d9d commit 9de67a0
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ Example: --print=Hb"
pub quiet: bool,

/// Always stream the response body.
#[clap(short = 'S', long, default_missing_value = "true", num_args= 0..=1, require_equals = true)]
#[clap(short = 'S', long = "stream", name = "stream")]
pub stream_raw: bool,

#[clap(skip)]
pub stream: Option<bool>,

/// Save output to FILE instead of stdout.
Expand Down Expand Up @@ -555,6 +558,12 @@ impl Cli {
(false, true) => Some(false),
(false, false) => None,
};
self.stream = match (self.stream_raw, matches.get_flag("no-stream")) {
(true, true) => unreachable!(),
(true, false) => Some(true),
(false, true) => Some(false),
(false, false) => None,
};
if self.download {
self.follow = true;
self.check_status = Some(true);
Expand Down Expand Up @@ -1691,6 +1700,24 @@ mod tests {
assert_eq!(cli.check_status, Some(true));
}

#[test]
fn negating_stream() {
let cli = parse([":"]).unwrap();
assert_eq!(cli.stream, None);

let cli = parse(["--stream", ":"]).unwrap();
assert_eq!(cli.stream, Some(true));

let cli = parse(["--no-stream", ":"]).unwrap();
assert_eq!(cli.stream, Some(false));

let cli = parse(["--stream", "--no-stream", ":"]).unwrap();
assert_eq!(cli.stream, Some(false));

let cli = parse(["--no-stream", "--stream", ":"]).unwrap();
assert_eq!(cli.stream, Some(true));
}

#[test]
fn parse_encoding_label() {
let test_cases = vec![
Expand Down

0 comments on commit 9de67a0

Please sign in to comment.