-
Notifications
You must be signed in to change notification settings - Fork 132
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
Changes from 20 commits
a28223f
d002b33
232d99f
e445722
07fbb0c
502f473
be60ecb
b5235e9
92f5a70
49c52d8
fbc507d
422f282
30fdb1f
4f21efd
6525177
6584dd4
a0bce01
5d2f1b4
1fdb6b7
48ad2d8
0c0a6bb
247030b
004405f
192d45f
d57f892
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
[package] | ||
name = "jcli-lib" | ||
version = "0.11.1" | ||
authors = [ "[email protected]" ] | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/input-output-hk/jormungandr" | ||
homepage = "https://github.com/input-output-hk/jormungandr#README.md" | ||
documentation = "https://github.com/input-output-hk/jormungandr#USAGE.md" | ||
description = """ | ||
Midgard Serpent | ||
""" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
rand = "0.8" | ||
rand_chacha = "0.3" | ||
serde = "1.0" | ||
serde_derive = "1.0" | ||
serde_json = "1.0.59" | ||
serde_yaml = "0.8" | ||
bincode = "1.3.3" | ||
mime = "^0.3.7" | ||
bech32 = "0.7" | ||
hex = "0.4.2" | ||
rayon = "1.5" | ||
base64 = "0.13.0" | ||
chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } | ||
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } | ||
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } | ||
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } | ||
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } | ||
chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = ["p256k1"] } | ||
jormungandr-lib = { path = "../jormungandr-lib" } | ||
gtmpl = "0.6.0" | ||
valico = "3.5.0" | ||
ed25519-bip32 = "0.3" | ||
thiserror = "1.0" | ||
bytes = "1.0" | ||
|
||
[dependencies.structopt] | ||
version = "^0.3" | ||
optional = true | ||
|
||
[dependencies.clap] | ||
version = "2.33" | ||
default-features = false | ||
features = [ "suggestions", "color", "wrap_help" ] | ||
|
||
[dependencies.reqwest] | ||
version = "0.11" | ||
default-features = false | ||
features = ["blocking", "rustls-tls", "json"] | ||
|
||
[dev-dependencies] | ||
assert_fs = "1.0" | ||
predicates = "1.0" | ||
|
||
[build-dependencies] | ||
versionisator = "1.0.2" | ||
|
||
[features] | ||
default = ["structopt"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fn main() { | ||
let pkg_version = if let Ok(date) = std::env::var("DATE") { | ||
format!("{}.{}", env!("CARGO_PKG_VERSION"), date) | ||
} else { | ||
env!("CARGO_PKG_VERSION").to_string() | ||
}; | ||
|
||
println!("cargo:rustc-env=CARGO_PKG_VERSION={}", pkg_version); | ||
|
||
let version = versionisator::Version::new( | ||
env!("CARGO_MANIFEST_DIR"), | ||
env!("CARGO_PKG_NAME").to_string(), | ||
pkg_version, | ||
); | ||
|
||
println!("cargo:rustc-env=FULL_VERSION={}", version.full()); | ||
println!("cargo:rustc-env=SIMPLE_VERSION={}", version.simple()); | ||
println!("cargo:rustc-env=SOURCE_VERSION={}", version.hash()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
use crate::jcli_lib::utils::key_parser::parse_pub_key; | ||
use crate::utils::key_parser::parse_pub_key; | ||
use chain_addr::{AddressReadable, Discrimination, Kind}; | ||
use chain_crypto::{bech32::Bech32 as _, AsymmetricPublicKey, Ed25519, PublicKey}; | ||
#[cfg(feature = "structopt")] | ||
use structopt::StructOpt; | ||
use thiserror::Error; | ||
|
||
#[derive(StructOpt)] | ||
#[structopt(name = "address", rename_all = "kebab-case")] | ||
#[cfg_attr( | ||
filip-dulic-bloxico marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. ;)
Need to look at the amount. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In this case, it is both. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
feature = "structopt", | ||
derive(StructOpt), | ||
structopt(name = "address", rename_all = "kebab-case") | ||
)] | ||
pub enum Address { | ||
/// Display the content and info of a bech32 formatted address. | ||
Info(InfoArgs), | ||
|
@@ -18,48 +22,51 @@ pub enum Address { | |
Account(AccountArgs), | ||
} | ||
|
||
#[derive(StructOpt)] | ||
#[cfg_attr(feature = "structopt", derive(StructOpt))] | ||
pub struct InfoArgs { | ||
/// An address, in bech32 format, to display the content | ||
/// and info that can be extracted from. | ||
#[structopt(name = "ADDRESS")] | ||
#[cfg_attr(feature = "structopt", structopt(name = "ADDRESS"))] | ||
address: AddressReadable, | ||
} | ||
|
||
#[derive(StructOpt)] | ||
#[cfg_attr(feature = "structopt", derive(StructOpt))] | ||
pub struct DiscriminationData { | ||
/// Set the discrimination type to testing (default is production). | ||
#[structopt(long = "testing")] | ||
#[cfg_attr(feature = "structopt", structopt(long = "testing"))] | ||
testing: bool, | ||
|
||
/// Set the prefix to use to describe the address. This is only available | ||
/// on the human readable representation of the address and will not be | ||
/// used or checked by the node. | ||
#[structopt(long = "prefix", default_value = "ca")] | ||
#[cfg_attr( | ||
feature = "structopt", | ||
structopt(long = "prefix", default_value = "ca") | ||
)] | ||
prefix: String, | ||
} | ||
|
||
#[derive(StructOpt)] | ||
#[cfg_attr(feature = "structopt", derive(StructOpt))] | ||
pub struct SingleArgs { | ||
/// A public key in bech32 encoding with the key type prefix. | ||
#[structopt(name = "PUBLIC_KEY", parse(try_from_str = parse_pub_key))] | ||
#[cfg_attr(feature = "structopt", structopt(name = "PUBLIC_KEY", parse(try_from_str = parse_pub_key)))] | ||
key: PublicKey<Ed25519>, | ||
|
||
/// A public key in bech32 encoding with the key type prefix. | ||
#[structopt(name = "DELEGATION_KEY", parse(try_from_str = parse_pub_key))] | ||
#[cfg_attr(feature = "structopt", structopt(name = "DELEGATION_KEY", parse(try_from_str = parse_pub_key)))] | ||
delegation: Option<PublicKey<Ed25519>>, | ||
|
||
#[structopt(flatten)] | ||
#[cfg_attr(feature = "structopt", structopt(flatten))] | ||
discrimination_data: DiscriminationData, | ||
} | ||
|
||
#[derive(StructOpt)] | ||
#[cfg_attr(feature = "structopt", derive(StructOpt))] | ||
pub struct AccountArgs { | ||
/// A public key in bech32 encoding with the key type prefix. | ||
#[structopt(name = "PUBLIC_KEY", parse(try_from_str = parse_pub_key))] | ||
#[cfg_attr(feature = "structopt", structopt(name = "PUBLIC_KEY", parse(try_from_str = parse_pub_key)))] | ||
key: PublicKey<Ed25519>, | ||
|
||
#[structopt(flatten)] | ||
#[cfg_attr(feature = "structopt", structopt(flatten))] | ||
discrimination_data: DiscriminationData, | ||
} | ||
|
||
|
There was a problem hiding this comment.
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.