Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a timeout CLI option #41

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Comment on lines +34 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if let Some(timeout) = matches.timeout {
let timeout = if timeout == 0 {
if let Some(0) = matches.timeout {

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