Skip to content

Commit

Permalink
Add a timeout CLI option
Browse files Browse the repository at this point in the history
Adds a way to change the client's timeout on the command line.

Signed-off-by: Hugues de Valon <[email protected]>
  • Loading branch information
hug-dev committed Feb 16, 2021
1 parent 45da0e8 commit 918cba3
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 19 deletions.
115 changes: 97 additions & 18 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ documentation = "https://docs.rs/crate/parsec-tool"
ansi_term = "0.12.1"
atty = "0.2.14"
clap = "3.0.0-beta.1"
parsec-client = { git = "https://github.com/parallaxsecond/parsec-client-rust", rev = "a915d9aacb9eed868b1afb4f206086561aa58e1f" }
parsec-client = { git = "https://github.com/parallaxsecond/parsec-client-rust", rev = "2d71624a6fd4a5fdf9ee2eaef34eb94751313442" }
structopt = "0.3.17"
thiserror = "1.0.20"
env_logger = "0.8.2"
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
This repository contains a tool to communicate with the [Parsec
service](https://github.com/parallaxsecond/parsec) on the command-line.

For demos and to test the Parsec service, you might want to change the Parsec endpoint location.
For that, set the `PARSEC_SERVICE_ENDPOINT` environment variable to correction endpoint.

To set a Unix Domain Socket Listener endpoint at `/tmp/parsec.sock`:

```
$ export PARSEC_SERVICE_ENDPOINT=unix:/tmp/parsec.sock
```

# Demo

[![asciicast](https://asciinema.org/a/bGRK4lFZnCq3UZQSWa7vQfuT5.svg)](https://asciinema.org/a/bGRK4lFZnCq3UZQSWa7vQfuT5)
Expand Down
5 changes: 5 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pub struct ParsecToolApp {
#[structopt(short = "p", long = "provider")]
pub provider: Option<u8>,

/// The timeout time used for all commands in seconds. Will use the client's default if not specified. If
/// set to 0, will not use any timeout and will block indefinitely.
#[structopt(short = "t", long = "timeout")]
pub timeout: Option<u32>,

/// The subcommand -- e.g., ping.
#[structopt(subcommand)]
pub subcommand: Subcommand,
Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ fn main() -> std::io::Result<()> {
client.set_implicit_provider(provider);
}

if let Some(timeout) = matches.timeout {
let timeout = if timeout == 0 {
None
} else {
Some(std::time::Duration::from_secs(timeout.into()))
};
client.set_timeout(timeout);
}

matches.subcommand.run(client).map_err(|e| {
err!("{:?}", e);
std::io::Error::new(std::io::ErrorKind::Other, "Executing subcommand failed.")
Expand Down

0 comments on commit 918cba3

Please sign in to comment.