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

Refactor into jcli-lib crate #3216

Closed
wants to merge 25 commits into from
Closed

Conversation

filip-dulic-bloxico
Copy link
Contributor

This is the beginning step for refactoring the jcli-lib crate out of the
jcli binary crate.

This is the beginning step for refactoring the jcli-lib crate from the
jcli binary crate. This is the starting commit for #3172
@filip-dulic-bloxico filip-dulic-bloxico linked an issue Apr 13, 2021 that may be closed by this pull request
5 tasks
@filip-dulic-bloxico filip-dulic-bloxico changed the title Refactor jcli-lib crate into workspace Refactor into jcli-lib crate Apr 13, 2021
@filip-dulic-bloxico filip-dulic-bloxico self-assigned this Apr 15, 2021
@filip-dulic-bloxico filip-dulic-bloxico marked this pull request as ready for review April 19, 2021 18:21
Copy link
Contributor

@eugene-babichenko eugene-babichenko left a comment

Choose a reason for hiding this comment

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

The idea itself is good, BUT. IMO what is being done currently defies the whole purpose of moving functionality into the library. This library includes things that should be there (argument parsing) since they are going to be used only in jcli and this is not what I would call a good API either.

See my review comment below: instead of moving everything into the library we should start to gradually separate the functionality, that is needed to be shared to other apps.

I don't even mind not having the full functionality of jcli in the library in the first version, I understand this is a gigantic piece of work. This is perfectly fine as long as it is usable in other apps.

That said, instead of doing what we have done currently I would suggest to:

  • Identify the current clients of this library (excluding jcli).
  • Design a proper API that would not bring in the whole dependency tree of jcli. Given the nature of this library I assume that this would be just a bunch functions.

@@ -0,0 +1,19 @@
fn main() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed for the library actually. We should be pretty much happy with what Cargo.toml provides.

use structopt::StructOpt;
use thiserror::Error;

#[derive(StructOpt)]
#[structopt(name = "address", rename_all = "kebab-case")]
#[cfg_attr(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would oppose that. Instead just "move the functionality to the library and optional command parser" we should implement an API that is intended for library users. By this I mean that the current approach, that is initially intended for "parse arguments and run a command" is not suitable here. Most commands could (and should) be made into functions receiving several arguments.

Let's reserve argument parsing for the actual CLI binary and think of a better approach here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, argument parsing could be reused too. Even inside jcli itself we have some duplicated code. Also some tools could reuse some of that code (it is being used for a tool now on catalyst-toolbox).

Copy link
Contributor

Choose a reason for hiding this comment

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

Even inside jcli itself we have some duplicated code

This is the problem of a client, not the problem of a library. ;)

Also some tools could reuse some of that code

Need to look at the amount.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the problem of a client, not the problem of a library

In this case, it is both.

Copy link
Contributor

Choose a reason for hiding this comment

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

The library could implement things like parsing common argument formats. Probably not the options and subcommand structures though, these should be defined in the CLI tool.

@danielSanchezQ
Copy link
Contributor

I don't even mind not having the full functionality of jcli in the library in the first version, I understand this is a gigantic piece of work. This is perfectly fine as long as it is usable in other apps.

+1

That said, instead of doing what we have done currently I would suggest to:

* Identify the current clients of this library (excluding **jcli**).

* Design a proper API that would not bring in the whole dependency tree of `jcli`. Given the nature of this library I assume that this would be just a bunch functions.

IMO we could make every (needed) module could have an IO part (args parsing that can be reusable, some of the modules already had it, but they were private), and extract and refactor the exec methods into functions

@eugene-babichenko
Copy link
Contributor

IMO we could make every (needed) module could have an IO part (args parsing that can be reusable, some of the modules already had it, but they were private), and extract and refactor the exec methods into functions

Sounds about right. I am still a bit skeptical about sharing structopt definitions, but if we really need them this is a cleaner approach. At least we can put all of them in a feature-gated module instead of playing around with cfg_attr which certainly doesn't contribute to readability.

@danielSanchezQ danielSanchezQ marked this pull request as draft April 21, 2021 08:33
@danielSanchezQ
Copy link
Contributor

I let it as a draft for now, while we discuss what we will finally do.

@danielSanchezQ danielSanchezQ added the DO NOT MERGE not to be merged until something else is done label Apr 22, 2021
@mzabaluev
Copy link
Contributor

jcli is currently used as a library in catalyst-toolbox, so it would make sense to check what is it used for and provide an API.

@minikin
Copy link
Collaborator

minikin commented Apr 4, 2022

@filip-dulic-bloxico Closing it. Feel free to reopen if we really need it.

@minikin minikin closed this Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE not to be merged until something else is done
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jcli lib refactor
5 participants