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 BasicClient to ParsecToolApp #35

Merged
merged 1 commit into from
Feb 5, 2021

Conversation

ionut-arm
Copy link
Member

This commit adds an instance of BasicClient to the ParsecToolApp so that
all subcommands can simply use this one instead of spinning up their
own.

Signed-off-by: Ionut Mihalcea [email protected]

@ionut-arm ionut-arm added the enhancement New feature or request label Feb 5, 2021
@ionut-arm ionut-arm requested a review from hug-dev February 5, 2021 15:19
@ionut-arm ionut-arm self-assigned this Feb 5, 2021
src/main.rs Outdated
matches.init_client().map_err(|e| {
err!("{:?}", e);
std::io::Error::new(std::io::ErrorKind::Other, "Spinning up BasicClient failed.")
})?;
matches.subcommand.run(&matches).map_err(|e| {
Copy link
Member

Choose a reason for hiding this comment

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

I think it's very good to spin up the BasicClient before but couldn't it be cleaner if we do it directly in the main function and pass the reference to the run method? It seems cleaner than having it in the structopt structure, even though we can skip it. That way we keep both things separate (CLI and client)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, that works for me - we can pass the whole client like that, not just a reference, since we only run one subcommand anyway. I'll update

This commit changes the Subcommand trait to accept a BasicClient when
the command is run. The client can then be freely used during the
subcommand processing.

Signed-off-by: Ionut Mihalcea <[email protected]>
Copy link
Member

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

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

Thanks!

use structopt::StructOpt;

fn main() -> std::io::Result<()> {
env_logger::init();

let matches = cli::ParsecToolApp::from_args();
matches.subcommand.run(&matches).map_err(|e| {
let client = BasicClient::new(matches.app_name.clone()).map_err(|e| {
Copy link
Member

Choose a reason for hiding this comment

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

👌 looks nice!

@ionut-arm ionut-arm merged commit 8f150c0 into parallaxsecond:master Feb 5, 2021
@ionut-arm ionut-arm deleted the basic-client branch February 5, 2021 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants