Skip to content

Commit

Permalink
Merge pull request #20 from marcelom97/add_quiet_flag
Browse files Browse the repository at this point in the history
Add quiet flag
  • Loading branch information
Stavrospanakakis authored Apr 30, 2024
2 parents e3ed8e8 + d470178 commit 8fc6822
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Arguments:
Options:
-t, --timeout <TIMEOUT> [default: 30]
-a, --addr <ADDRESS>
-q, --quiet Suppress output
-h, --help Print help
-V, --version Print version

Expand Down Expand Up @@ -110,4 +111,4 @@ is_ready 1.0.0
## License
MIT
MIT
15 changes: 11 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@ struct Args {
value_name = "COMMAND"
)]
cmd: Vec<String>,

#[arg(short = 'q', long)]
quiet: bool,
}

async fn wait_for(addresses: Vec<String>) {
async fn wait_for(addresses: Vec<String>, quiet: bool) {
let mut threads = Vec::new();
for address in addresses {
let thread = tokio::spawn(async move {
loop {
match TcpStream::connect(&address) {
Ok(_) => {
println!("Connected to {} successfully", address);
if !quiet {
println!("Connected to {} successfully", address);
}
break;
}
Err(_) => {
println!("Waiting for {}", address)
if !quiet {
println!("Waiting for {}", address)
}
}
}
tokio::time::sleep(Duration::from_millis(500)).await;
Expand All @@ -53,7 +60,7 @@ pub async fn run() -> Result<(), &'static str> {

let thread = thread::spawn(move || async move {
let my_duration = tokio::time::Duration::from_secs(args.timeout);
timeout(my_duration, wait_for(args.addresses)).await
timeout(my_duration, wait_for(args.addresses, args.quiet)).await
});

if thread.join().unwrap().await.is_err() {
Expand Down

0 comments on commit 8fc6822

Please sign in to comment.