Skip to content

Commit

Permalink
Improved CLI usage
Browse files Browse the repository at this point in the history
- bin: do not print user instructions when the terminal isn't attached
  • Loading branch information
alfred-hodler committed Jun 4, 2024
1 parent 008133e commit 90ad6b9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pushtx-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use pushtx::*;

use core::panic;
use std::collections::HashSet;
use std::io::Read;
use std::io::{IsTerminal, Read};
use std::path::PathBuf;

use clap::Parser;
Expand Down Expand Up @@ -74,8 +74,11 @@ fn main() -> anyhow::Result<()> {
.collect()
}
None => {
eprintln!("Go ahead and paste some hex-encoded transactions (one per line) ... ");
std::io::stdin()
let stdin = std::io::stdin();
if stdin.is_terminal() {
eprintln!("Enter some hex-encoded transactions (one per line, Ctrl + {EOF_CHR} when done) ... ");
}
stdin
.lines()
.filter_map(|line| match line {
Ok(line) if !line.trim().is_empty() => {
Expand Down Expand Up @@ -229,3 +232,9 @@ impl std::fmt::Display for Network {
write!(f, "{}", name)
}
}

const EOF_CHR: char = if cfg!(target_family = "windows") {
'Z'
} else {
'D'
};

0 comments on commit 90ad6b9

Please sign in to comment.