From 1a307dfd2706cd1bff861ac7f8283c3d3060d5a1 Mon Sep 17 00:00:00 2001 From: quake wang Date: Tue, 7 Jan 2020 15:34:16 +0900 Subject: [PATCH 1/9] feat: generates completion scripts for shell --- src/main.rs | 2 +- src/subcommands/util.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index bb8fc7e2..b2cb7c5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -200,7 +200,7 @@ fn main() -> Result<(), io::Error> { Ok(()) } -fn get_version() -> Version { +pub fn get_version() -> Version { let major = env!("CARGO_PKG_VERSION_MAJOR") .parse::() .expect("CARGO_PKG_VERSION_MAJOR parse success"); diff --git a/src/subcommands/util.rs b/src/subcommands/util.rs index 607ca334..a3c39b6d 100644 --- a/src/subcommands/util.rs +++ b/src/subcommands/util.rs @@ -27,6 +27,7 @@ use crate::utils::{ other::get_address, printer::{OutputFormat, Printable}, }; +use crate::{build_cli, get_version}; const FLAG_SINCE_EPOCH_NUMBER: u64 = 0b010_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000; @@ -168,6 +169,14 @@ impl<'a> UtilSubCommand<'a> { .validator(|input| DateTime::parse_from_rfc3339(&input).map(|_| ()).map_err(|err| err.to_string())) .help("The locktime in RFC3339 format. Example: 2014-11-28T21:00:00+00:00") ), + SubCommand::with_name("completions") + .about("Generates completion scripts for your shell") + .arg( + Arg::with_name("shell") + .required(true) + .possible_values(&["bash", "fish", "zsh"]) + .help("The shell to generate the script for") + ), ]) } } @@ -346,6 +355,16 @@ message = "0x" }); Ok(resp.render(format, color)) } + ("completions", Some(m)) => { + let shell = m.value_of("shell").unwrap(); + let version = get_version(); + build_cli(&version.short(), &version.long()).gen_completions_to( + "ckb-cli", + shell.parse().unwrap(), + &mut std::io::stdout(), + ); + Ok("".to_string()) + } _ => Err(matches.usage().to_owned()), } } From fe790c2f487007111e8ed3936579b739c6ff33f4 Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Fri, 17 Apr 2020 12:08:57 +0800 Subject: [PATCH 2/9] feat: Allow hash(blake2b) from file --- src/subcommands/util.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/subcommands/util.rs b/src/subcommands/util.rs index 0cf21147..03144c38 100644 --- a/src/subcommands/util.rs +++ b/src/subcommands/util.rs @@ -19,13 +19,16 @@ use clap::{App, Arg, ArgMatches, SubCommand}; use eaglesong::EagleSongBuilder; use faster_hex::hex_string; use secp256k1::recovery::{RecoverableSignature, RecoveryId}; +use std::fs; +use std::io::Read; +use std::path::PathBuf; use super::CliSubCommand; use crate::utils::{ arg, arg_parser::{ - AddressParser, AddressPayloadOption, ArgParser, FixedHashParser, FromStrParser, HexParser, - PrivkeyPathParser, PrivkeyWrapper, PubkeyHexParser, + AddressParser, AddressPayloadOption, ArgParser, FilePathParser, FixedHashParser, + FromStrParser, HexParser, PrivkeyPathParser, PrivkeyWrapper, PubkeyHexParser, }, other::{get_address, read_password, serialize_signature}, printer::{OutputFormat, Printable}, @@ -150,10 +153,17 @@ impl<'a> UtilSubCommand<'a> { ), SubCommand::with_name("eaglesong") .about("Hash binary use eaglesong algorithm") - .arg(binary_hex_arg.clone()), + .arg(binary_hex_arg.clone().help("The binary in hex format to hash")), SubCommand::with_name("blake2b") .about("Hash binary use blake2b algorithm (personalization: 'ckb-default-hash')") - .arg(binary_hex_arg.clone()) + .arg(binary_hex_arg.clone().required(false).help("The binary in hex format to hash")) + .arg( + Arg::with_name("binary-path") + .long("binary-path") + .takes_value(true) + .validator(|input| FilePathParser::new(true).validate(input)) + .help("The binary file path") + ) .arg( Arg::with_name("prefix-160") .long("prefix-160") @@ -422,7 +432,20 @@ message = "0x" Ok(format!("{:#x}", H256::from(builder.finalize()))) } ("blake2b", Some(m)) => { - let binary: Vec = HexParser.from_matches(m, "binary-hex")?; + let binary: Vec = HexParser + .from_matches_opt(m, "binary-hex", false)? + .ok_or_else(String::new) + .or_else(|_| -> Result<_, String> { + let path: PathBuf = FilePathParser::new(true) + .from_matches(m, "binary-path") + .map_err(|err| { + format!(" or is required: {}", err) + })?; + let mut data = Vec::new(); + let mut file = fs::File::open(path).map_err(|err| err.to_string())?; + file.read_to_end(&mut data).map_err(|err| err.to_string())?; + Ok(data) + })?; let hash_data = blake2b_256(&binary); let slice = if m.is_present("prefix-160") { &hash_data[0..20] From 89b2424e1fea82a80e242c5d95d2359cb5faddeb Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 18 Apr 2020 13:49:28 +0800 Subject: [PATCH 3/9] chore: fix azure ci package script --- azure-pipelines.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ea58370f..52dee456 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -28,6 +28,7 @@ jobs: CI: true - job: Package + timeoutInMinutes: 0 condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/') pool: vmImage: 'VS2017-Win2016' @@ -45,7 +46,9 @@ jobs: inputs: rootFolderOrFile: 'ckb-cli_$(Build.SourceBranchName)_x86_64-pc-windows-msvc' archiveFile: '$(Build.ArtifactStagingDirectory)/ckb-cli_$(Build.SourceBranchName)_x86_64-pc-windows-msvc.zip' - - script: choco install -y gpg4win + - script: | + scoop bucket add extras + scoop install gpg4win displayName: Install GPG4Win - task: DownloadSecureFile@1 inputs: From ce5f77e3d2eb18030a39c3cea7b2d9aa9e248006 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 21 Apr 2020 21:24:29 +0000 Subject: [PATCH 4/9] chore(deps): bump regex from 1.3.6 to 1.3.7 Bumps [regex](https://github.com/rust-lang/regex) from 1.3.6 to 1.3.7. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.3.6...regex-1.3.7) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c5febed..119a8204 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2435,9 +2435,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.3.6" +version = "1.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3" +checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" dependencies = [ "aho-corasick", "memchr", From b33bb27718cdfbf5cf0958f53cbcd41410e19da8 Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Wed, 6 May 2020 13:50:45 +0800 Subject: [PATCH 5/9] chore: Update ckb to v0.32.0 --- Cargo.lock | 104 +++++++++++++++++++++------------------ Cargo.toml | 20 ++++---- Makefile | 2 +- ckb-index/Cargo.toml | 4 +- ckb-sdk-types/Cargo.toml | 14 +++--- ckb-sdk/Cargo.toml | 14 +++--- test/Cargo.toml | 12 ++--- 7 files changed, 89 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 119a8204..4aebf083 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -362,13 +362,13 @@ dependencies = [ [[package]] name = "ckb-build-info" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" [[package]] name = "ckb-chain-spec" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-crypto", "ckb-dao-utils", @@ -386,7 +386,7 @@ dependencies = [ [[package]] name = "ckb-cli" -version = "0.31.0" +version = "0.32.0" dependencies = [ "ansi_term 0.11.0", "atty", @@ -436,8 +436,8 @@ dependencies = [ [[package]] name = "ckb-crypto" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-fixed-hash", "failure", @@ -449,8 +449,8 @@ dependencies = [ [[package]] name = "ckb-dao-utils" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "byteorder", "ckb-error", @@ -461,8 +461,8 @@ dependencies = [ [[package]] name = "ckb-error" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-occupied-capacity", "enum-display-derive", @@ -472,8 +472,8 @@ dependencies = [ [[package]] name = "ckb-fixed-hash" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-fixed-hash-core", "ckb-fixed-hash-hack", @@ -482,8 +482,8 @@ dependencies = [ [[package]] name = "ckb-fixed-hash-core" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "failure", "faster-hex 0.4.1", @@ -492,8 +492,8 @@ dependencies = [ [[package]] name = "ckb-fixed-hash-hack" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-fixed-hash-core", "proc-macro-hack", @@ -504,15 +504,15 @@ dependencies = [ [[package]] name = "ckb-hash" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "blake2b-rs", ] [[package]] name = "ckb-index" -version = "0.31.0" +version = "0.32.0" dependencies = [ "bincode", "ckb-sdk", @@ -526,8 +526,8 @@ dependencies = [ [[package]] name = "ckb-jsonrpc-types" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-types", "faster-hex 0.4.1", @@ -538,8 +538,8 @@ dependencies = [ [[package]] name = "ckb-logger" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ansi_term 0.12.1", "backtrace", @@ -557,8 +557,8 @@ dependencies = [ [[package]] name = "ckb-occupied-capacity" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-occupied-capacity-core", "ckb-occupied-capacity-macros", @@ -567,16 +567,16 @@ dependencies = [ [[package]] name = "ckb-occupied-capacity-core" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "serde", ] [[package]] name = "ckb-occupied-capacity-macros" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-occupied-capacity-core", "proc-macro-hack", @@ -586,10 +586,11 @@ dependencies = [ [[package]] name = "ckb-pow" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "byteorder", + "ckb-hash", "ckb-types", "eaglesong", "serde", @@ -597,16 +598,16 @@ dependencies = [ [[package]] name = "ckb-rational" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "numext-fixed-uint", ] [[package]] name = "ckb-resource" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-system-scripts", "ckb-types", @@ -620,8 +621,8 @@ dependencies = [ [[package]] name = "ckb-script" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "byteorder", "ckb-chain-spec", @@ -640,15 +641,15 @@ dependencies = [ [[package]] name = "ckb-script-data-loader" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "ckb-types", ] [[package]] name = "ckb-sdk" -version = "0.31.0" +version = "0.32.0" dependencies = [ "aes-ctr", "bech32", @@ -679,7 +680,7 @@ dependencies = [ [[package]] name = "ckb-sdk-types" -version = "0.31.0" +version = "0.32.0" dependencies = [ "ckb-crypto", "ckb-error", @@ -706,8 +707,8 @@ dependencies = [ [[package]] name = "ckb-types" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "bit-vec", "bytes 0.5.4", @@ -721,12 +722,13 @@ dependencies = [ "merkle-cbt", "molecule", "numext-fixed-uint", + "once_cell", ] [[package]] name = "ckb-util" -version = "0.31.0-pre" -source = "git+https://github.com/nervosnetwork/ckb?tag=v0.31.0-rc1#c90043939b271844160397f5bd0b0bed2db7f7e9" +version = "0.32.0-pre" +source = "git+https://github.com/nervosnetwork/ckb?tag=v0.32.0-rc1#80e0bef47812c5fdcc6850085bd258210cb8735a" dependencies = [ "linked-hash-map 0.5.1", "parking_lot 0.7.1", @@ -1790,9 +1792,9 @@ dependencies = [ [[package]] name = "molecule" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5492f99b99e29ec28391edf446abfe10dbc3ebc401c978f7c8ac9c0ef3b7cd93" +checksum = "663f76cc52219e5957e2f5563cce9d89f98aa8503c9c898b5c412d97df663998" dependencies = [ "bytes 0.5.4", "cfg-if", @@ -1934,6 +1936,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +[[package]] +name = "once_cell" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" + [[package]] name = "opaque-debug" version = "0.2.3" diff --git a/Cargo.toml b/Cargo.toml index 81d3e982..ec917bad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,21 @@ [package] name = "ckb-cli" -version = "0.31.0" +version = "0.32.0" license = "MIT" authors = ["Linfeng Qian ", "Nervos Core Dev "] edition = "2018" [dependencies] -ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1", features = ["secp"] } -ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-util = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } +ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1", features = ["secp"] } +ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-util = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } ckb-sdk = { path = "ckb-sdk" } ckb-index = { path = "ckb-index" } -ckb-resource = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-dao-utils = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } +ckb-resource = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-dao-utils = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } jsonrpc-client-core = "0.5.0" jsonrpc-core = "10.1" @@ -55,7 +55,7 @@ tui = "0.6.0" termion = "1.5" [build-dependencies] -ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } +ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } [workspace] members = ["ckb-sdk", "ckb-index", "ckb-sdk-types"] diff --git a/Makefile b/Makefile index 1dd61058..26bd9431 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ ci: fmt clippy test security-audit git diff --exit-code Cargo.lock integration: - bash devtools/ci/integration.sh v0.31.0-rc1 + bash devtools/ci/integration.sh v0.32.0-rc1 prod: ## Build binary with release profile. cargo build --release diff --git a/ckb-index/Cargo.toml b/ckb-index/Cargo.toml index a894745c..189bf84e 100644 --- a/ckb-index/Cargo.toml +++ b/ckb-index/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-index" -version = "0.31.0" +version = "0.32.0" authors = ["Linfeng Qian ", "Nervos Core Dev "] edition = "2018" license = "MIT" @@ -11,7 +11,7 @@ serde_derive = "1.0" bincode = "1.1.4" log = "0.4.6" failure = "0.1.5" -ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } +ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } ckb-sdk = { path = "../ckb-sdk" } [dependencies.rocksdb] diff --git a/ckb-sdk-types/Cargo.toml b/ckb-sdk-types/Cargo.toml index fd3069fa..98f0d0a7 100644 --- a/ckb-sdk-types/Cargo.toml +++ b/ckb-sdk-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-sdk-types" -version = "0.31.0" +version = "0.32.0" authors = ["Linfeng Qian ", "Nervos Core Dev "] edition = "2018" license = "MIT" @@ -9,14 +9,14 @@ license = "MIT" serde = { version = "1.0", features = ["rc"] } serde_derive = "1.0" -ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-script = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1", default-features = false } -ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-error = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } +ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-script = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1", default-features = false } +ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-error = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } [dev-dependencies] -ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1", features = ["secp"] } +ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1", features = ["secp"] } [features] default = ["ckb-script/default"] diff --git a/ckb-sdk/Cargo.toml b/ckb-sdk/Cargo.toml index a66ae4ff..ea1ddcd2 100644 --- a/ckb-sdk/Cargo.toml +++ b/ckb-sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-sdk" -version = "0.31.0" +version = "0.32.0" authors = ["Linfeng Qian ", "Nervos Core Dev "] edition = "2018" license = "MIT" @@ -25,10 +25,10 @@ uuid = { version = "0.7.4", features = ["v4"] } chrono = "0.4.6" failure = "0.1.5" -ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-script = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-resource = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1", features = ["secp"] } +ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-script = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-resource = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1", features = ["secp"] } ckb-sdk-types = { path = "../ckb-sdk-types" } diff --git a/test/Cargo.toml b/test/Cargo.toml index 5cf20746..57b47024 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cli-test" -version = "0.31.0" +version = "0.32.0" authors = ["Linfeng Qian "] edition = "2018" @@ -14,11 +14,11 @@ env_logger = "0.6" toml = "0.5.0" serde_yaml = "0.8.9" ckb-sdk = { path = "../ckb-sdk" } -ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-app-config = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-chain-spec = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } -ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1", features = ["secp"] } -ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.31.0-rc1" } +ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-app-config = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-chain-spec = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } +ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1", features = ["secp"] } +ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.32.0-rc1" } regex = "1.1.6" # Prevent this from interfering with workspaces From de01048c167dc4441efd30b03f7d8d0b5d3793ff Mon Sep 17 00:00:00 2001 From: Boyu Yang Date: Thu, 7 May 2020 12:35:01 +0800 Subject: [PATCH 6/9] test: don't install msys2-installer for azure windows ci --- devtools/azure/windows-dependencies.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/devtools/azure/windows-dependencies.yml b/devtools/azure/windows-dependencies.yml index e14addfe..aa2bfa48 100644 --- a/devtools/azure/windows-dependencies.yml +++ b/devtools/azure/windows-dependencies.yml @@ -10,8 +10,6 @@ steps: displayName: Add scoop to path - script: scoop install llvm displayName: Install LLVM -- script: scoop install msys2 - displayName: Install msys2 - script: scoop install yasm displayName: Install yasm - script: | From b1863817eb4038d8547d708f339dd08bcc5f9180 Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Thu, 7 May 2020 13:28:31 +0800 Subject: [PATCH 7/9] chore: Bump up clap to 3.0.0-beta.1 --- Cargo.lock | 106 +++++++++++++++++++++++++++++- Cargo.toml | 3 +- src/interactive.rs | 4 +- src/main.rs | 36 +++++----- src/subcommands/account.rs | 46 ++++++------- src/subcommands/api_server.rs | 10 +-- src/subcommands/dao/command.rs | 26 ++++---- src/subcommands/mock_tx.rs | 24 +++---- src/subcommands/molecule.rs | 20 +++--- src/subcommands/rpc.rs | 116 ++++++++++++++++----------------- src/subcommands/tx.rs | 64 +++++++++--------- src/subcommands/util.rs | 107 ++++++++++++++++-------------- src/subcommands/wallet/mod.rs | 32 ++++----- src/utils/arg.rs | 98 ++++++++++++++-------------- src/utils/arg_parser.rs | 4 +- src/utils/completer.rs | 77 ++++++++-------------- test/Cargo.toml | 2 +- test/src/app.rs | 6 +- 18 files changed, 435 insertions(+), 346 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4aebf083..d8ba36f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,7 +175,7 @@ dependencies = [ "cexpr", "cfg-if", "clang-sys", - "clap", + "clap 2.33.0", "env_logger", "fxhash", "lazy_static", @@ -402,7 +402,8 @@ dependencies = [ "ckb-sdk", "ckb-types", "ckb-util", - "clap", + "clap 3.0.0-beta.1", + "clap_generate", "colored", "crossbeam-channel", "dirs", @@ -776,12 +777,53 @@ dependencies = [ "ansi_term 0.11.0", "atty", "bitflags", - "strsim", + "strsim 0.8.0", "textwrap", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.0.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "860643c53f980f0d38a5e25dfab6c3c93b2cb3aa1fe192643d17a293c6c41936" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim 0.10.0", + "termcolor", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "clap_derive" +version = "3.0.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb51c9e75b94452505acd21d929323f5a5c6c4735a852adbd39ef5fb1b014f30" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + +[[package]] +name = "clap_generate" +version = "3.0.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "188d8b137fa922515d549cf17ece165ddbc71bf21e723e81d84406958dcdef67" +dependencies = [ + "clap 3.0.0-beta.1", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -1276,6 +1318,15 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "hermit-abi" version = "0.1.10" @@ -1981,6 +2032,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "os_str_bytes" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced912e1439b63a8172b943887c33373f226a4a9cfab95d09c0e3c44851d04d4" + [[package]] name = "owning_ref" version = "0.4.1" @@ -2155,6 +2212,32 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +[[package]] +name = "proc-macro-error" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18f33027081eba0a6d8aba6d1b1c3a3be58cbb12106341c2d5759fcd9b5277e7" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", + "version_check 0.9.1", +] + +[[package]] +name = "proc-macro-error-attr" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a5b4b77fdb63c1eca72173d68d24501c54ab1269409f6b672c85deb18af69de" +dependencies = [ + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", + "syn-mid", + "version_check 0.9.1", +] + [[package]] name = "proc-macro-hack" version = "0.5.15" @@ -2911,6 +2994,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "1.0.0" @@ -2950,6 +3039,17 @@ dependencies = [ "unicode-xid 0.2.0", ] +[[package]] +name = "syn-mid" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" +dependencies = [ + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + [[package]] name = "synom" version = "0.11.3" diff --git a/Cargo.toml b/Cargo.toml index ec917bad..4046ef72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,8 @@ secp256k1 = {version = "0.17.0" } faster-hex = "0.4" env_logger = "0.6" crossbeam-channel = "0.3" -clap = "2.33.0" +clap = "3.0.0-beta.1" +clap_generate = "3.0.0-beta.1" serde = { version = "1.0", features = ["rc"] } serde_derive = "1.0" serde_json = "1.0" diff --git a/src/interactive.rs b/src/interactive.rs index 585f0f05..4e4debd9 100644 --- a/src/interactive.rs +++ b/src/interactive.rs @@ -32,7 +32,7 @@ pub struct InteractiveEnv { config_file: PathBuf, history_file: PathBuf, index_dir: PathBuf, - parser: clap::App<'static, 'static>, + parser: clap::App<'static>, key_store: KeyStore, rpc_client: HttpRpcClient, raw_rpc_client: RawHttpRpcClient, @@ -224,7 +224,7 @@ impl InteractiveEnv { let format = self.config.output_format(); let color = ColorWhen::new(self.config.color()).color(); let debug = self.config.debug(); - match self.parser.clone().get_matches_from_safe(args) { + match self.parser.clone().try_get_matches_from(args) { Ok(matches) => match matches.subcommand() { ("config", Some(m)) => { m.value_of("url").and_then(|url| { diff --git a/src/main.rs b/src/main.rs index 0e74e089..6f42dbee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use ckb_build_info::Version; use ckb_sdk::{rpc::RawHttpRpcClient, HttpRpcClient}; use ckb_util::RwLock; use clap::crate_version; -use clap::{App, AppSettings, Arg, SubCommand}; +use clap::{App, AppSettings, Arg}; #[cfg(unix)] use subcommands::TuiSubCommand; @@ -245,7 +245,7 @@ pub fn get_version() -> Version { } } -pub fn build_cli<'a>(version_short: &'a str, version_long: &'a str) -> App<'a, 'a> { +pub fn build_cli<'a>(version_short: &'a str, version_long: &'a str) -> App<'a> { let app = App::new("ckb-cli") .version(version_short) .long_version(version_long) @@ -265,7 +265,7 @@ pub fn build_cli<'a>(version_short: &'a str, version_long: &'a str) -> App<'a, ' .long("url") .takes_value(true) .validator(|input| UrlParser.validate(input)) - .help("RPC API server url"), + .about("RPC API server url"), ) .arg( Arg::with_name("output-format") @@ -274,36 +274,36 @@ pub fn build_cli<'a>(version_short: &'a str, version_long: &'a str) -> App<'a, ' .possible_values(&["yaml", "json"]) .default_value("yaml") .global(true) - .help("Select output format"), + .about("Select output format"), ) .arg( Arg::with_name("no-color") .long("no-color") .global(true) - .help("Do not highlight(color) output json"), + .about("Do not highlight(color) output json"), ) .arg( Arg::with_name("debug") .long("debug") .global(true) - .help("Display request parameters"), + .about("Display request parameters"), ) .arg( Arg::with_name("wait-for-sync") .long("wait-for-sync") .global(true) - .help( + .about( "Ensure the index-store synchronizes completely before command being executed", ), ); #[cfg(unix)] - let app = app.subcommand(SubCommand::with_name("tui").about("Enter TUI mode")); + let app = app.subcommand(App::new("tui").about("Enter TUI mode")); app } -pub fn build_interactive() -> App<'static, 'static> { +pub fn build_interactive() -> App<'static> { App::new("interactive") .version(crate_version!()) .global_setting(AppSettings::NoBinaryName) @@ -311,24 +311,24 @@ pub fn build_interactive() -> App<'static, 'static> { .global_setting(AppSettings::DeriveDisplayOrder) .global_setting(AppSettings::DisableVersion) .subcommand( - SubCommand::with_name("config") + App::new("config") .about("Config environment") .arg( Arg::with_name("url") .long("url") .validator(|input| UrlParser.validate(input)) .takes_value(true) - .help("Config RPC API url"), + .about("Config RPC API url"), ) .arg( Arg::with_name("color") .long("color") - .help("Switch color for rpc interface"), + .about("Switch color for rpc interface"), ) .arg( Arg::with_name("debug") .long("debug") - .help("Switch debug mode"), + .about("Switch debug mode"), ) .arg( Arg::with_name("output-format") @@ -336,22 +336,22 @@ pub fn build_interactive() -> App<'static, 'static> { .takes_value(true) .possible_values(&["yaml", "json"]) .default_value("yaml") - .help("Select output format"), + .about("Select output format"), ) .arg( Arg::with_name("completion_style") .long("completion_style") - .help("Switch completion style"), + .about("Switch completion style"), ) .arg( Arg::with_name("edit_style") .long("edit_style") - .help("Switch edit style"), + .about("Switch edit style"), ), ) - .subcommand(SubCommand::with_name("info").about("Display global variables")) + .subcommand(App::new("info").about("Display global variables")) .subcommand( - SubCommand::with_name("exit") + App::new("exit") .visible_alias("quit") .about("Exit the interactive interface"), ) diff --git a/src/subcommands/account.rs b/src/subcommands/account.rs index d7ef2128..8bf5f9b5 100644 --- a/src/subcommands/account.rs +++ b/src/subcommands/account.rs @@ -8,7 +8,7 @@ use ckb_sdk::{ Address, AddressPayload, NetworkType, }; use ckb_types::{packed::Script, prelude::*, H160, H256}; -use clap::{App, Arg, ArgMatches, SubCommand}; +use clap::{App, Arg, ArgMatches}; use super::CliSubCommand; use crate::utils::{ @@ -30,34 +30,34 @@ impl<'a> AccountSubCommand<'a> { AccountSubCommand { key_store } } - pub fn subcommand(name: &'static str) -> App<'static, 'static> { + pub fn subcommand(name: &'static str) -> App<'static> { let arg_privkey_path = Arg::with_name("privkey-path") .long("privkey-path") .takes_value(true); let arg_extended_privkey_path = Arg::with_name("extended-privkey-path") .long("extended-privkey-path") .takes_value(true) - .help("Extended private key path (include master private key and chain code)"); - SubCommand::with_name(name) + .about("Extended private key path (include master private key and chain code)"); + App::new(name) .about("Manage accounts") .subcommands(vec![ - SubCommand::with_name("list").about("List all accounts"), - SubCommand::with_name("new").about("Create a new account and print related information."), - SubCommand::with_name("import") + App::new("list").about("List all accounts"), + App::new("new").about("Create a new account and print related information."), + App::new("import") .about("Import an unencrypted private key from and create a new account.") .arg( arg_privkey_path .clone() .required_unless("extended-privkey-path") .validator(|input| PrivkeyPathParser.validate(input)) - .help("The privkey is assumed to contain an unencrypted private key in hexadecimal format. (only read first line)") + .about("The privkey is assumed to contain an unencrypted private key in hexadecimal format. (only read first line)") ) .arg(arg_extended_privkey_path .clone() .required_unless("privkey-path") .validator(|input| ExtendedPrivkeyPathParser.validate(input)) ), - SubCommand::with_name("import-keystore") + App::new("import-keystore") .about("Import key from encrypted keystore json file and create a new account.") .arg( Arg::with_name("path") @@ -65,9 +65,9 @@ impl<'a> AccountSubCommand<'a> { .takes_value(true) .required(true) .validator(|input| FilePathParser::new(true).validate(input)) - .help("The keystore file path (json format)") + .about("The keystore file path (json format)") ), - SubCommand::with_name("unlock") + App::new("unlock") .about("Unlock an account") .arg(lock_arg().required(true)) .arg( @@ -76,21 +76,21 @@ impl<'a> AccountSubCommand<'a> { .takes_value(true) .validator(|input| DurationParser.validate(input)) .required(true) - .help("How long before the key expired, format: 30s, 15m, 1h (repeat unlock will increase the time)") + .about("How long before the key expired, format: 30s, 15m, 1h (repeat unlock will increase the time)") ), - SubCommand::with_name("update") + App::new("update") .about("Update password of an account") .arg(lock_arg().required(true)), - SubCommand::with_name("export") + App::new("export") .about("Export master private key and chain code as hex plain text (USE WITH YOUR OWN RISK)") .arg(lock_arg().required(true)) .arg( arg_extended_privkey_path .clone() .required(true) - .help("Output extended private key path (PrivKey + ChainCode)") + .about("Output extended private key path (PrivKey + ChainCode)") ), - SubCommand::with_name("bip44-addresses") + App::new("bip44-addresses") .about("Extended receiving/change Addresses (see: BIP-44)") .arg( Arg::with_name("from-receiving-index") @@ -98,7 +98,7 @@ impl<'a> AccountSubCommand<'a> { .takes_value(true) .default_value("0") .validator(|input| FromStrParser::::default().validate(input)) - .help("Start from receiving path index") + .about("Start from receiving path index") ) .arg( Arg::with_name("receiving-length") @@ -106,7 +106,7 @@ impl<'a> AccountSubCommand<'a> { .takes_value(true) .default_value("20") .validator(|input| FromStrParser::::default().validate(input)) - .help("Receiving addresses length") + .about("Receiving addresses length") ) .arg( Arg::with_name("from-change-index") @@ -114,7 +114,7 @@ impl<'a> AccountSubCommand<'a> { .takes_value(true) .default_value("0") .validator(|input| FromStrParser::::default().validate(input)) - .help("Start from change path index") + .about("Start from change path index") ) .arg( Arg::with_name("change-length") @@ -122,10 +122,10 @@ impl<'a> AccountSubCommand<'a> { .takes_value(true) .default_value("10") .validator(|input| FromStrParser::::default().validate(input)) - .help("Change addresses length") + .about("Change addresses length") ) .arg(lock_arg().required(true)), - SubCommand::with_name("extended-address") + App::new("extended-address") .about("Extended address (see: BIP-44)") .arg(lock_arg().required(true)) .arg( @@ -133,7 +133,7 @@ impl<'a> AccountSubCommand<'a> { .long("path") .takes_value(true) .validator(|input| FromStrParser::::new().validate(input)) - .help("The address path") + .about("The address path") ), ]) } @@ -359,7 +359,7 @@ impl<'a> CliSubCommand for AccountSubCommand<'a> { }); Ok(resp.render(format, color)) } - _ => Err(matches.usage().to_owned()), + _ => Err(Self::subcommand("account").generate_usage()), } } } diff --git a/src/subcommands/api_server.rs b/src/subcommands/api_server.rs index f039c9ab..04a76a85 100644 --- a/src/subcommands/api_server.rs +++ b/src/subcommands/api_server.rs @@ -16,7 +16,7 @@ use ckb_types::{ prelude::*, H256, }; -use clap::{App, Arg, ArgMatches, SubCommand}; +use clap::{App, Arg, ArgMatches}; use jsonrpc_core::{Error as RpcError, ErrorCode as RpcErrorCode, IoHandler, Result as RpcResult}; use jsonrpc_derive::rpc; use jsonrpc_http_server::{Server, ServerBuilder}; @@ -58,8 +58,8 @@ impl<'a> ApiServerSubCommand<'a> { } } - pub fn subcommand(name: &'static str) -> App<'static, 'static> { - SubCommand::with_name(name) + pub fn subcommand(name: &'static str) -> App<'static> { + App::new(name) .about("Start advanced API server") .arg( Arg::with_name("listen") @@ -68,11 +68,11 @@ impl<'a> ApiServerSubCommand<'a> { .required(true) .default_value("127.0.0.1:3000") .validator(|input| FromStrParser::::new().validate(input)) - .help("Rpc server listen address (when --privkey-path is given ip MUST be 127.0.0.1)"), + .about("Rpc server listen address (when --privkey-path is given ip MUST be 127.0.0.1)"), ) .arg( arg::privkey_path() - .help("Private key file path (only read first line)") + .about("Private key file path (only read first line)") ) } } diff --git a/src/subcommands/dao/command.rs b/src/subcommands/dao/command.rs index 7a06fde8..344bd1af 100644 --- a/src/subcommands/dao/command.rs +++ b/src/subcommands/dao/command.rs @@ -16,7 +16,7 @@ use ckb_types::{ prelude::*, H160, H256, }; -use clap::{App, Arg, ArgMatches, SubCommand}; +use clap::{App, Arg, ArgMatches}; use std::collections::HashSet; impl<'a> CliSubCommand for DAOSubCommand<'a> { @@ -86,32 +86,32 @@ impl<'a> CliSubCommand for DAOSubCommand<'a> { }); Ok(resp.render(format, color)) } - _ => Err(matches.usage().to_owned()), + _ => Err(Self::subcommand().generate_usage()), } } } impl<'a> DAOSubCommand<'a> { - pub fn subcommand() -> App<'static, 'static> { - SubCommand::with_name("dao") + pub fn subcommand() -> App<'static> { + App::new("dao") .about("Deposit / prepare / withdraw / query NervosDAO balance (with local index) / key utils") .subcommands(vec![ - SubCommand::with_name("deposit") + App::new("deposit") .about("Deposit capacity into NervosDAO") .args(&TransactArgs::args()) .arg(arg::capacity().required(true)), - SubCommand::with_name("prepare") + App::new("prepare") .about("Prepare specified cells from NervosDAO") .args(&TransactArgs::args()) .arg(arg::out_point().required(true).multiple(true)), - SubCommand::with_name("withdraw") + App::new("withdraw") .about("Withdraw specified cells from NervosDAO") .args(&TransactArgs::args()) .arg(arg::out_point().required(true).multiple(true)), - SubCommand::with_name("query-deposited-cells") + App::new("query-deposited-cells") .about("Query NervosDAO deposited capacity by lock script hash or address") .args(&QueryArgs::args()), - SubCommand::with_name("query-prepared-cells") + App::new("query-prepared-cells") .about("Query NervosDAO prepared capacity by lock script hash or address") .args(&QueryArgs::args()) ]) @@ -142,7 +142,7 @@ impl QueryArgs { Ok(Self { lock_hash }) } - fn args<'a, 'b>() -> Vec> { + fn args<'a>() -> Vec> { vec![arg::lock_hash(), arg::address()] } } @@ -181,10 +181,10 @@ impl TransactArgs { }) } - fn args<'a, 'b>() -> Vec> { + fn args<'a>() -> Vec> { vec![ - arg::privkey_path().required_unless(arg::from_account().b.name), - arg::from_account().required_unless(arg::privkey_path().b.name), + arg::privkey_path().required_unless(arg::from_account().get_name()), + arg::from_account().required_unless(arg::privkey_path().get_name()), arg::tx_fee().required(true), ] } diff --git a/src/subcommands/mock_tx.rs b/src/subcommands/mock_tx.rs index d6f018b9..223b25e5 100644 --- a/src/subcommands/mock_tx.rs +++ b/src/subcommands/mock_tx.rs @@ -16,7 +16,7 @@ use ckb_types::{ prelude::*, H160, H256, }; -use clap::{App, Arg, ArgMatches, SubCommand}; +use clap::{App, Arg, ArgMatches}; use super::CliSubCommand; use crate::utils::{ @@ -45,37 +45,37 @@ impl<'a> MockTxSubCommand<'a> { } } - pub fn subcommand(name: &'static str) -> App<'static, 'static> { + pub fn subcommand(name: &'static str) -> App<'static> { let arg_tx_file = Arg::with_name("tx-file") .long("tx-file") .takes_value(true) .required(true) .validator(|input| FilePathParser::new(true).validate(input)) - .help("Mock transaction data file (format: json)"); + .about("Mock transaction data file (format: json)"); let arg_output_file = Arg::with_name("output-file") .long("output-file") .takes_value(true) .validator(|input| FilePathParser::new(false).validate(input)) - .help("Completed mock transaction data file (format: json)"); - SubCommand::with_name(name) + .about("Completed mock transaction data file (format: json)"); + App::new(name) .about("Handle mock transactions (verify/send)") .subcommands(vec![ - SubCommand::with_name("template") + App::new("template") .about("Print mock transaction template") .arg(lock_arg().required(true).clone().required(false)) - .arg(arg_output_file.clone().help("Save to a output file")), - SubCommand::with_name("complete") + .arg(arg_output_file.clone().about("Save to a output file")), + App::new("complete") .about("Complete the mock transaction") .arg(arg_tx_file.clone()) .arg( arg_output_file .clone() - .help("Completed mock transaction data file (format: json)"), + .about("Completed mock transaction data file (format: json)"), ), - SubCommand::with_name("verify") + App::new("verify") .about("Verify a mock transaction in local") .arg(arg_tx_file.clone()), - SubCommand::with_name("send") + App::new("send") .about("Complete then send a transaction") .arg(arg_tx_file.clone()), ]) @@ -230,7 +230,7 @@ impl<'a> CliSubCommand for MockTxSubCommand<'a> { .map_err(|err| format!("Send transaction error: {}", err))?; Ok(resp.render(format, color)) } - _ => Err(matches.usage().to_owned()), + _ => Err(Self::subcommand("mock-tx").generate_usage()), } } } diff --git a/src/subcommands/molecule.rs b/src/subcommands/molecule.rs index a1c9893a..6900ebc7 100644 --- a/src/subcommands/molecule.rs +++ b/src/subcommands/molecule.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use ckb_hash::blake2b_256; use ckb_jsonrpc_types::{self as json_types, JsonBytes}; use ckb_types::{bytes::Bytes, packed, prelude::*, H256}; -use clap::{App, Arg, ArgMatches, SubCommand}; +use clap::{App, Arg, ArgMatches}; use serde_derive::{Deserialize, Serialize}; use super::CliSubCommand; @@ -22,18 +22,18 @@ impl MoleculeSubCommand { MoleculeSubCommand {} } - pub fn subcommand(name: &'static str) -> App<'static, 'static> { + pub fn subcommand(name: &'static str) -> App<'static> { let arg_type = Arg::with_name("type") .long("type") .takes_value(true) .required(true) - .help("The molecule type name defined in blockchain.mol (and extra OutPointVec)"); + .about("The molecule type name defined in blockchain.mol (and extra OutPointVec)"); let arg_binary_hex = Arg::with_name("binary-hex") .long("binary-hex") .takes_value(true) .required(true) .validator(|input| HexParser.validate(input)) - .help("Binary data hex format"); + .about("Binary data hex format"); let arg_json_path = Arg::with_name("json-path") .long("json-path") @@ -45,21 +45,21 @@ impl MoleculeSubCommand { .takes_value(true) .default_value("binary") .possible_values(&["binary", "hash"]) - .help("Serialize output type"); + .about("Serialize output type"); - SubCommand::with_name(name) + App::new(name) .about("Molecule encode/decode utilities") .subcommands(vec![ - SubCommand::with_name("decode") + App::new("decode") .about("Decode molecule type from binary") .arg(arg_type.clone()) .arg(arg_binary_hex.clone()), - SubCommand::with_name("encode") + App::new("encode") .about("Encode molecule type from json to binary") .arg(arg_type.clone()) .arg(arg_json_path.clone()) .arg(arg_serialize_output_type), - SubCommand::with_name("default") + App::new("default") .about("Print default json structure of certain molecule type") .arg(arg_type.clone()) .arg( @@ -271,7 +271,7 @@ impl CliSubCommand for MoleculeSubCommand { Ok(json_string) } } - _ => Err(matches.usage().to_owned()), + _ => Err(Self::subcommand("molecule").generate_usage()), } } } diff --git a/src/subcommands/rpc.rs b/src/subcommands/rpc.rs index 00c25147..7a6ce728 100644 --- a/src/subcommands/rpc.rs +++ b/src/subcommands/rpc.rs @@ -9,7 +9,7 @@ use ckb_sdk::{ HttpRpcClient, }; use ckb_types::{packed, prelude::*, H256}; -use clap::{App, Arg, ArgMatches, SubCommand}; +use clap::{App, Arg, ArgMatches}; use ipnetwork::IpNetwork; use multiaddr::Multiaddr; use serde_derive::{Deserialize, Serialize}; @@ -39,7 +39,7 @@ impl<'a> RpcSubCommand<'a> { } } - pub fn subcommand() -> App<'static, 'static> { + pub fn subcommand() -> App<'static> { let arg_hash = Arg::with_name("hash") .long("hash") .takes_value(true) @@ -50,62 +50,62 @@ impl<'a> RpcSubCommand<'a> { .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) .required(true) - .help("Block number"); + .about("Block number"); let arg_page = Arg::with_name("page") .long("page") .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) .required(true) - .help("Page number"); + .about("Page number"); let arg_perpage = Arg::with_name("perpage") .long("perpage") .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) .default_value("50") .required(true) - .help("Page size, max value is 50"); + .about("Page size, max value is 50"); let arg_reverse_order = Arg::with_name("reverse-order") .long("reverse-order") - .help("Returns the live cells collection in reverse order"); + .about("Returns the live cells collection in reverse order"); let arg_peer_id = Arg::with_name("peer-id") .long("peer-id") .takes_value(true) .required(true) - .help("Node's peer id"); + .about("Node's peer id"); - SubCommand::with_name("rpc") + App::new("rpc") .about("Invoke RPC call to node") .arg( Arg::with_name("raw-data") .long("raw-data") .global(true) - .help("Output raw jsonrpc data") + .about("Output raw jsonrpc data") ) .subcommands(vec![ // [Chain] - SubCommand::with_name("get_block") + App::new("get_block") .about("Get block content by hash") - .arg(arg_hash.clone().help("Block hash")), - SubCommand::with_name("get_block_by_number") + .arg(arg_hash.clone().about("Block hash")), + App::new("get_block_by_number") .about("Get block content by block number") .arg(arg_number.clone()), - SubCommand::with_name("get_block_hash") + App::new("get_block_hash") .about("Get block hash by block number") .arg(arg_number.clone()), - SubCommand::with_name("get_cellbase_output_capacity_details") + App::new("get_cellbase_output_capacity_details") .about("Get block header content by hash") - .arg(arg_hash.clone().help("Block hash")), - SubCommand::with_name("get_cells_by_lock_hash") + .arg(arg_hash.clone().about("Block hash")), + App::new("get_cells_by_lock_hash") .about("Get cells by lock script hash") - .arg(arg_hash.clone().help("Lock hash")) + .arg(arg_hash.clone().about("Lock hash")) .arg( Arg::with_name("from") .long("from") .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) .required(true) - .help("From block number"), + .about("From block number"), ) .arg( Arg::with_name("to") @@ -113,19 +113,19 @@ impl<'a> RpcSubCommand<'a> { .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) .required(true) - .help("To block number"), + .about("To block number"), ), - SubCommand::with_name("get_current_epoch").about("Get current epoch information"), - SubCommand::with_name("get_epoch_by_number") + App::new("get_current_epoch").about("Get current epoch information"), + App::new("get_epoch_by_number") .about("Get epoch information by epoch number") - .arg(arg_number.clone().help("Epoch number")), - SubCommand::with_name("get_header") + .arg(arg_number.clone().about("Epoch number")), + App::new("get_header") .about("Get block header content by hash") - .arg(arg_hash.clone().help("Block hash")), - SubCommand::with_name("get_header_by_number") + .arg(arg_hash.clone().about("Block hash")), + App::new("get_header_by_number") .about("Get block header by block number") .arg(arg_number.clone()), - SubCommand::with_name("get_live_cell") + App::new("get_live_cell") .about("Get live cell (live means unspent)") .arg( Arg::with_name("tx-hash") @@ -133,7 +133,7 @@ impl<'a> RpcSubCommand<'a> { .takes_value(true) .validator(|input| FixedHashParser::::default().validate(input)) .required(true) - .help("Tx hash"), + .about("Tx hash"), ) .arg( Arg::with_name("index") @@ -141,56 +141,56 @@ impl<'a> RpcSubCommand<'a> { .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) .required(true) - .help("Output index"), + .about("Output index"), ) .arg( Arg::with_name("with-data") .long("with-data") - .help("Get live cell with data") + .about("Get live cell with data") ), - SubCommand::with_name("get_tip_block_number").about("Get tip block number"), - SubCommand::with_name("get_tip_header").about("Get tip header"), - SubCommand::with_name("get_transaction") + App::new("get_tip_block_number").about("Get tip block number"), + App::new("get_tip_header").about("Get tip header"), + App::new("get_transaction") .about("Get transaction content by transaction hash") - .arg(arg_hash.clone().help("Tx hash")), + .arg(arg_hash.clone().about("Tx hash")), // [Indexer] - SubCommand::with_name("deindex_lock_hash") - .arg(arg_hash.clone().help("Lock script hash")) + App::new("deindex_lock_hash") + .arg(arg_hash.clone().about("Lock script hash")) .about("Remove index for live cells and transactions by the hash of lock script"), - SubCommand::with_name("get_live_cells_by_lock_hash") - .arg(arg_hash.clone().help("Lock script hash")) + App::new("get_live_cells_by_lock_hash") + .arg(arg_hash.clone().about("Lock script hash")) .arg(arg_page.clone()) .arg(arg_perpage.clone()) .arg(arg_reverse_order.clone()) .about("Get the live cells collection by the hash of lock script"), - SubCommand::with_name("get_transactions_by_lock_hash") - .arg(arg_hash.clone().help("Lock script hash")) + App::new("get_transactions_by_lock_hash") + .arg(arg_hash.clone().about("Lock script hash")) .arg(arg_page.clone()) .arg(arg_perpage.clone()) .arg(arg_reverse_order.clone()) .about("Get the transactions collection by the hash of lock script. Returns empty array when the `lock_hash` has not been indexed yet"), - SubCommand::with_name("index_lock_hash") - .arg(arg_hash.clone().help("Lock script hash")) + App::new("index_lock_hash") + .arg(arg_hash.clone().about("Lock script hash")) .arg( Arg::with_name("index-from") .long("index-from") .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) - .help("Index from the block number") + .about("Index from the block number") ) .about("Create index for live cells and transactions by the hash of lock script"), // [Net] - SubCommand::with_name("get_banned_addresses").about("Get all banned IPs/Subnets"), - SubCommand::with_name("get_peers").about("Get connected peers"), - SubCommand::with_name("local_node_info").about("Get local node information"), - SubCommand::with_name("set_ban") + App::new("get_banned_addresses").about("Get all banned IPs/Subnets"), + App::new("get_peers").about("Get connected peers"), + App::new("local_node_info").about("Get local node information"), + App::new("set_ban") .arg( Arg::with_name("address") .long("address") .takes_value(true) .validator(|input| FromStrParser::::new().validate(input)) .required(true) - .help("The IP/Subnet with an optional netmask (default is /32 = single IP)") + .about("The IP/Subnet with an optional netmask (default is /32 = single IP)") ) .arg( Arg::with_name("command") @@ -198,7 +198,7 @@ impl<'a> RpcSubCommand<'a> { .takes_value(true) .possible_values(&["insert", "delete"]) .required(true) - .help("`insert` to insert an IP/Subnet to the list, `delete` to delete an IP/Subnet from the list") + .about("`insert` to insert an IP/Subnet to the list, `delete` to delete an IP/Subnet from the list") ) .arg( Arg::with_name("ban_time") @@ -207,21 +207,21 @@ impl<'a> RpcSubCommand<'a> { .validator(|input| DurationParser.validate(input)) .required(true) .default_value("24h") - .help("How long the IP is banned") + .about("How long the IP is banned") ) .arg( Arg::with_name("reason") .long("reason") .takes_value(true) - .help("Ban reason, optional parameter") + .about("Ban reason, optional parameter") ) .about("Insert or delete an IP/Subnet from the banned list"), // [Pool] - SubCommand::with_name("tx_pool_info").about("Get transaction pool information"), + App::new("tx_pool_info").about("Get transaction pool information"), // [`Stats`] - SubCommand::with_name("get_blockchain_info").about("Get chain information"), + App::new("get_blockchain_info").about("Get chain information"), // [`IntegrationTest`] - SubCommand::with_name("add_node") + App::new("add_node") .arg(arg_peer_id.clone()) .arg( Arg::with_name("address") @@ -229,20 +229,20 @@ impl<'a> RpcSubCommand<'a> { .takes_value(true) .validator(|input| FromStrParser::::new().validate(input)) .required(true) - .help("Target node's address (multiaddr)") + .about("Target node's address (multiaddr)") ) .about("Connect to a node"), - SubCommand::with_name("remove_node") + App::new("remove_node") .arg(arg_peer_id.clone()) .about("Disconnect a node"), - SubCommand::with_name("broadcast_transaction") + App::new("broadcast_transaction") .arg( Arg::with_name("json-path") .long("json-path") .takes_value(true) .required(true) .validator(|input| FilePathParser::new(true).validate(input)) - .help("Transaction content (json format, see rpc send_transaction)") + .about("Transaction content (json format, see rpc send_transaction)") ) .about("Broadcast transaction without verify"), ]) @@ -679,7 +679,7 @@ impl<'a> CliSubCommand for RpcSubCommand<'a> { let resp = self.rpc_client.broadcast_transaction(tx.into())?; Ok(resp.render(format, color)) } - _ => Err(matches.usage().to_owned()), + _ => Err(Self::subcommand().generate_usage()), } } } diff --git a/src/subcommands/tx.rs b/src/subcommands/tx.rs index 317be32b..d5319b6a 100644 --- a/src/subcommands/tx.rs +++ b/src/subcommands/tx.rs @@ -21,7 +21,7 @@ use ckb_types::{ prelude::*, H160, H256, }; -use clap::{App, Arg, ArgMatches, SubCommand}; +use clap::{App, Arg, ArgMatches}; use faster_hex::hex_string; use serde_derive::{Deserialize, Serialize}; @@ -58,54 +58,54 @@ impl<'a> TxSubCommand<'a> { } } - pub fn subcommand(name: &'static str) -> App<'static, 'static> { + pub fn subcommand(name: &'static str) -> App<'static> { let arg_tx_file = Arg::with_name("tx-file") .long("tx-file") .takes_value(true) .validator(|input| FilePathParser::new(false).validate(input)) .required(true) - .help("Multisig transaction data file (format: json)"); + .about("Multisig transaction data file (format: json)"); let arg_sighash_address = Arg::with_name("sighash-address") .long("sighash-address") .takes_value(true) .multiple(true) .required(true) .validator(|input| AddressParser::new_sighash().validate(input)) - .help("Normal sighash address"); + .about("Normal sighash address"); let arg_require_first_n = Arg::with_name("require-first-n") .long("require-first-n") .takes_value(true) .default_value("0") .validator(|input| FromStrParser::::default().validate(input)) - .help("Require first n signatures of corresponding pubkey"); + .about("Require first n signatures of corresponding pubkey"); let arg_threshold = Arg::with_name("threshold") .long("threshold") .takes_value(true) .default_value("1") .validator(|input| FromStrParser::::default().validate(input)) - .help("Multisig threshold"); + .about("Multisig threshold"); let arg_since_absolute_epoch = Arg::with_name("since-absolute-epoch") .long("since-absolute-epoch") .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) - .help("Since absolute epoch number"); + .about("Since absolute epoch number"); let arg_skip_check = Arg::with_name("skip-check") .long("skip-check") - .help("Send transaction without any check, be cautious to use this flag"); + .about("Send transaction without any check, be cautious to use this flag"); - SubCommand::with_name(name) + App::new(name) .about("Handle common sighash/multisig transaction") .subcommands(vec![ - SubCommand::with_name("init") + App::new("init") .about("Init a common (sighash/multisig) transaction") .arg(arg_tx_file.clone()), - SubCommand::with_name("add-multisig-config") + App::new("add-multisig-config") .about("Add multisig config") .arg(arg_sighash_address.clone()) .arg(arg_require_first_n.clone()) .arg(arg_threshold.clone()) .arg(arg_tx_file.clone()), - SubCommand::with_name("clear-field") + App::new("clear-field") .about("Remove all field items in transaction") .arg( Arg::with_name("field") @@ -113,10 +113,10 @@ impl<'a> TxSubCommand<'a> { .takes_value(true) .required(true) .possible_values(&["inputs", "outputs", "signatures"]) - .help("The transaction field"), + .about("The transaction field"), ) .arg(arg_tx_file.clone()), - SubCommand::with_name("add-input") + App::new("add-input") .about("Add cell input (with secp/multisig lock)") .arg( Arg::with_name("tx-hash") @@ -124,7 +124,7 @@ impl<'a> TxSubCommand<'a> { .takes_value(true) .validator(|input| FixedHashParser::::default().validate(input)) .required(true) - .help("Transaction hash"), + .about("Transaction hash"), ) .arg( Arg::with_name("index") @@ -132,12 +132,12 @@ impl<'a> TxSubCommand<'a> { .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) .required(true) - .help("Transaction output index"), + .about("Transaction output index"), ) .arg(arg_since_absolute_epoch.clone()) .arg(arg_tx_file.clone()) .arg(arg_skip_check.clone()), - SubCommand::with_name("add-output") + App::new("add-output") .about("Add cell output") .arg( Arg::with_name("to-sighash-address") @@ -148,7 +148,7 @@ impl<'a> TxSubCommand<'a> { ]) .takes_value(true) .validator(|input| AddressParser::new_sighash().validate(input)) - .help("To normal sighash address"), + .about("To normal sighash address"), ) .arg( Arg::with_name("to-short-multisig-address") @@ -156,7 +156,7 @@ impl<'a> TxSubCommand<'a> { .conflicts_with("to-long-multisig-address") .takes_value(true) .validator(|input| AddressParser::new_multisig().validate(input)) - .help("To short multisig address"), + .about("To short multisig address"), ) .arg( Arg::with_name("to-long-multisig-address") @@ -167,13 +167,13 @@ impl<'a> TxSubCommand<'a> { .set_full_type(MULTISIG_TYPE_HASH) .validate(input) }) - .help("To long multisig address (special case, include since)"), + .about("To long multisig address (special case, include since)"), ) .arg(arg::capacity().required(true)) .arg(arg::to_data()) .arg(arg::to_data_path()) .arg(arg_tx_file.clone()), - SubCommand::with_name("add-signature") + App::new("add-signature") .about("Add signature") .arg( Arg::with_name("lock-arg") @@ -185,7 +185,7 @@ impl<'a> TxSubCommand<'a> { Ok(ref data) => Err(format!("invalid data length: {}", data.len())), Err(err) => Err(err), }) - .help("The lock_arg of input lock script (20 bytes or 28 bytes)"), + .about("The lock_arg of input lock script (20 bytes or 28 bytes)"), ) .arg( Arg::with_name("signature") @@ -197,24 +197,24 @@ impl<'a> TxSubCommand<'a> { Ok(ref data) => Err(format!("invalid data length: {}", data.len())), Err(err) => Err(err), }) - .help("The signature"), + .about("The signature"), ) .arg(arg_tx_file.clone()), - SubCommand::with_name("info") + App::new("info") .about("Show detail of this multisig transaction (capacity, tx-fee, etc.)") .arg(arg_tx_file.clone()), - SubCommand::with_name("sign-inputs") + App::new("sign-inputs") .about("Sign all sighash/multisig inputs in this transaction") - .arg(arg::privkey_path().required_unless(arg::from_account().b.name)) - .arg(arg::from_account().required_unless(arg::privkey_path().b.name)) + .arg(arg::privkey_path().required_unless(arg::from_account().get_name())) + .arg(arg::from_account().required_unless(arg::privkey_path().get_name())) .arg(arg_tx_file.clone()) .arg( Arg::with_name("add-signatures") .long("add-signatures") - .help("Sign and add signatures"), + .about("Sign and add signatures"), ) .arg(arg_skip_check.clone()), - SubCommand::with_name("send") + App::new("send") .about("Send multisig transaction") .arg(arg_tx_file.clone()) .arg( @@ -223,10 +223,10 @@ impl<'a> TxSubCommand<'a> { .takes_value(true) .default_value("1.0") .validator(|input| CapacityParser.validate(input)) - .help("Max transaction fee (unit: CKB)"), + .about("Max transaction fee (unit: CKB)"), ) .arg(arg_skip_check), - SubCommand::with_name("build-multisig-address") + App::new("build-multisig-address") .about( "Build multisig address with multisig config and since(optional) argument", ) @@ -571,7 +571,7 @@ impl<'a> CliSubCommand for TxSubCommand<'a> { }); Ok(resp.render(format, color)) } - _ => Err(matches.usage().to_owned()), + _ => Err(Self::subcommand("tx").generate_usage()), } } } diff --git a/src/subcommands/util.rs b/src/subcommands/util.rs index 5ed113e2..cd30b5d4 100644 --- a/src/subcommands/util.rs +++ b/src/subcommands/util.rs @@ -15,7 +15,8 @@ use ckb_types::{ utilities::{compact_to_difficulty, difficulty_to_compact}, H160, H256, U256, }; -use clap::{App, Arg, ArgMatches, SubCommand}; +use clap::{App, Arg, ArgMatches}; +use clap_generate::generators::{Bash, Elvish, Fish, PowerShell, Zsh}; use eaglesong::EagleSongBuilder; use faster_hex::hex_string; use secp256k1::recovery::{RecoverableSignature, RecoveryId}; @@ -56,23 +57,23 @@ impl<'a> UtilSubCommand<'a> { } } - pub fn subcommand(name: &'static str) -> App<'static, 'static> { + pub fn subcommand(name: &'static str) -> App<'static> { let arg_privkey = Arg::with_name("privkey-path") .long("privkey-path") .takes_value(true) .validator(|input| PrivkeyPathParser.validate(input)) - .help("Private key file path (only read first line)"); + .about("Private key file path (only read first line)"); let arg_pubkey = Arg::with_name("pubkey") .long("pubkey") .takes_value(true) .validator(|input| PubkeyHexParser.validate(input)) - .help("Public key (hex string, compressed format)"); + .about("Public key (hex string, compressed format)"); let arg_address = Arg::with_name("address") .long("address") .takes_value(true) .validator(|input| AddressParser::default().validate(input)) .required(true) - .help("Target address (see: https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md)"); + .about("Target address (see: https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md)"); let binary_hex_arg = Arg::with_name("binary-hex") .long("binary-hex") @@ -88,11 +89,11 @@ impl<'a> UtilSubCommand<'a> { .set_short(CodeHashIndex::Sighash) .validate(input) }) - .help("The address in single signature format"); + .about("The address in single signature format"); let arg_recoverable = Arg::with_name("recoverable") .long("recoverable") - .help("Sign use recoverable signature"); + .about("Sign use recoverable signature"); let arg_message = Arg::with_name("message") .long("message") @@ -100,10 +101,10 @@ impl<'a> UtilSubCommand<'a> { .required(true) .validator(|input| FixedHashParser::::default().validate(input)); - SubCommand::with_name(name) + App::new(name) .about("Utilities") .subcommands(vec![ - SubCommand::with_name("key-info") + App::new("key-info") .about( "Show public information of a secp256k1 private key (from file) or public key", ) @@ -111,73 +112,73 @@ impl<'a> UtilSubCommand<'a> { .arg(arg_pubkey.clone().required(false)) .arg(arg_address.clone().required(false)) .arg(arg::lock_arg().clone()), - SubCommand::with_name("sign-data") + App::new("sign-data") .about("Sign data with secp256k1 signature ") - .arg(arg::privkey_path().required_unless(arg::from_account().b.name)) + .arg(arg::privkey_path().required_unless(arg::from_account().get_name())) .arg( arg::from_account() - .required_unless(arg::privkey_path().b.name) - .conflicts_with(arg::privkey_path().b.name), + .required_unless(arg::privkey_path().get_name()) + .conflicts_with(arg::privkey_path().get_name()), ) .arg(arg_recoverable.clone()) .arg( binary_hex_arg .clone() - .help("The data to be signed (blake2b hashed with 'ckb-default-hash' personalization)") + .about("The data to be signed (blake2b hashed with 'ckb-default-hash' personalization)") ), - SubCommand::with_name("sign-message") + App::new("sign-message") .about("Sign message with secp256k1 signature") - .arg(arg::privkey_path().required_unless(arg::from_account().b.name)) + .arg(arg::privkey_path().required_unless(arg::from_account().get_name())) .arg( arg::from_account() - .required_unless(arg::privkey_path().b.name) - .conflicts_with(arg::privkey_path().b.name), + .required_unless(arg::privkey_path().get_name()) + .conflicts_with(arg::privkey_path().get_name()), ) .arg(arg_recoverable.clone()) - .arg(arg_message.clone().help("The message to be signed (32 bytes)")), - SubCommand::with_name("verify-signature") + .arg(arg_message.clone().about("The message to be signed (32 bytes)")), + App::new("verify-signature") .about("Verify a compact format signature") .arg(arg::pubkey()) - .arg(arg::privkey_path().conflicts_with(arg::pubkey().b.name)) + .arg(arg::privkey_path().conflicts_with(arg::pubkey().get_name())) .arg( arg::from_account() - .conflicts_with_all(&[arg::privkey_path().b.name, arg::pubkey().b.name]), + .conflicts_with_all(&[arg::privkey_path().get_name(), arg::pubkey().get_name()]), ) - .arg(arg_message.clone().help("The message to be verify (32 bytes)")) + .arg(arg_message.clone().about("The message to be verify (32 bytes)")) .arg( Arg::with_name("signature") .long("signature") .takes_value(true) .required(true) .validator(|input| HexParser.validate(input)) - .help("The compact format signature (support recoverable signature)") + .about("The compact format signature (support recoverable signature)") ), - SubCommand::with_name("eaglesong") + App::new("eaglesong") .about("Hash binary use eaglesong algorithm") - .arg(binary_hex_arg.clone().help("The binary in hex format to hash")), - SubCommand::with_name("blake2b") + .arg(binary_hex_arg.clone().about("The binary in hex format to hash")), + App::new("blake2b") .about("Hash binary use blake2b algorithm (personalization: 'ckb-default-hash')") - .arg(binary_hex_arg.clone().required(false).help("The binary in hex format to hash")) + .arg(binary_hex_arg.clone().required(false).about("The binary in hex format to hash")) .arg( Arg::with_name("binary-path") .long("binary-path") .takes_value(true) .validator(|input| FilePathParser::new(true).validate(input)) - .help("The binary file path") + .about("The binary file path") ) .arg( Arg::with_name("prefix-160") .long("prefix-160") - .help("Only show prefix 160 bits (Example: calculate lock_arg from pubkey)") + .about("Only show prefix 160 bits (Example: calculate lock_arg from pubkey)") ), - SubCommand::with_name("compact-to-difficulty") + App::new("compact-to-difficulty") .about("Convert compact target value to difficulty value") .arg(Arg::with_name("compact-target") .long("compact-target") .takes_value(true) .validator(|input| { FromStrParser::::default() - .validate(input.clone()) + .validate(input) .or_else(|_| { let input = if input.starts_with("0x") || input.starts_with("0X") { &input[2..] @@ -188,9 +189,9 @@ impl<'a> UtilSubCommand<'a> { }) }) .required(true) - .help("The compact target value") + .about("The compact target value") ), - SubCommand::with_name("difficulty-to-compact") + App::new("difficulty-to-compact") .about("Convert difficulty value to compact target value") .arg(Arg::with_name("difficulty") .long("difficulty") @@ -204,9 +205,9 @@ impl<'a> UtilSubCommand<'a> { U256::from_hex_str(input).map(|_| ()).map_err(|err| err.to_string()) }) .required(true) - .help("The difficulty value") + .about("The difficulty value") ), - SubCommand::with_name("to-genesis-multisig-addr") + App::new("to-genesis-multisig-addr") .about("Convert address in single signature format to multisig format (only for mainnet genesis cells)") .arg( arg_sighash_address @@ -222,9 +223,9 @@ impl<'a> UtilSubCommand<'a> { .long("locktime") .required(true) .takes_value(true) - .help("The locktime in UTC format date. Example: 2022-05-01") + .about("The locktime in UTC format date. Example: 2022-05-01") ), - SubCommand::with_name("to-multisig-addr") + App::new("to-multisig-addr") .about("Convert address in single signature format to multisig format") .arg(arg_sighash_address.clone()) .arg( @@ -233,15 +234,15 @@ impl<'a> UtilSubCommand<'a> { .required(true) .takes_value(true) .validator(|input| DateTime::parse_from_rfc3339(&input).map(|_| ()).map_err(|err| err.to_string())) - .help("The locktime in RFC3339 format. Example: 2014-11-28T21:00:00+00:00") + .about("The locktime in RFC3339 format. Example: 2014-11-28T21:00:00+00:00") ), - SubCommand::with_name("completions") + App::new("completions") .about("Generates completion scripts for your shell") .arg( Arg::with_name("shell") .required(true) - .possible_values(&["bash", "fish", "zsh"]) - .help("The shell to generate the script for") + .possible_values(&["bash", "zsh", "fish", "elvish", "powershell"]) + .about("The shell to generate the script for") ), ]) } @@ -565,14 +566,24 @@ message = "0x" ("completions", Some(m)) => { let shell = m.value_of("shell").unwrap(); let version = get_version(); - build_cli(&version.short(), &version.long()).gen_completions_to( - "ckb-cli", - shell.parse().unwrap(), - &mut std::io::stdout(), - ); + let version_short = version.short(); + let version_long = version.long(); + let mut app = build_cli(&version_short, &version_long); + let bin_name = "ckb-cli"; + let output = &mut std::io::stdout(); + match shell { + "bash" => clap_generate::generate::(&mut app, bin_name, output), + "zsh" => clap_generate::generate::(&mut app, bin_name, output), + "fish" => clap_generate::generate::(&mut app, bin_name, output), + "elvish" => clap_generate::generate::(&mut app, bin_name, output), + "powershell" => { + clap_generate::generate::(&mut app, bin_name, output) + } + _ => panic!("Invalid shell: {}", shell), + } Ok("".to_string()) } - _ => Err(matches.usage().to_owned()), + _ => Err(Self::subcommand("util").generate_usage()), } } } diff --git a/src/subcommands/wallet/mod.rs b/src/subcommands/wallet/mod.rs index 3858e7f3..6bfb1688 100644 --- a/src/subcommands/wallet/mod.rs +++ b/src/subcommands/wallet/mod.rs @@ -11,7 +11,7 @@ use ckb_types::{ prelude::*, H160, H256, }; -use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; +use clap::{App, AppSettings, Arg, ArgMatches}; use serde::{Deserialize, Serialize}; use super::CliSubCommand; @@ -99,17 +99,17 @@ impl<'a> WalletSubCommand<'a> { }) } - pub fn subcommand() -> App<'static, 'static> { - SubCommand::with_name("wallet") + pub fn subcommand() -> App<'static> { + App::new("wallet") .about("Transfer / query balance (with local index) / key utils") .subcommands(vec![ - SubCommand::with_name("transfer") + App::new("transfer") .about("Transfer capacity to an address (can have data)") - .arg(arg::privkey_path().required_unless(arg::from_account().b.name)) + .arg(arg::privkey_path().required_unless(arg::from_account().get_name())) .arg( arg::from_account() - .required_unless(arg::privkey_path().b.name) - .conflicts_with(arg::privkey_path().b.name), + .required_unless(arg::privkey_path().get_name()) + .conflicts_with(arg::privkey_path().get_name()), ) .arg(arg::from_locked_address()) .arg(arg::to_address().required(true)) @@ -118,8 +118,10 @@ impl<'a> WalletSubCommand<'a> { .arg(arg::capacity().required(true)) .arg(arg::tx_fee().required(true)) .arg(arg::derive_receiving_address_length()) - .arg(arg::derive_change_address().conflicts_with(arg::privkey_path().b.name)), - SubCommand::with_name("get-capacity") + .arg( + arg::derive_change_address().conflicts_with(arg::privkey_path().get_name()), + ), + App::new("get-capacity") .about("Get capacity by lock script hash or address or lock arg or pubkey") .arg(arg::lock_hash()) .arg(arg::address()) @@ -127,8 +129,8 @@ impl<'a> WalletSubCommand<'a> { .arg(arg::lock_arg()) .arg(arg::derive_receiving_address_length()) .arg(arg::derive_change_address_length()) - .arg(arg::derived().conflicts_with(arg::lock_hash().b.name)), - SubCommand::with_name("get-live-cells") + .arg(arg::derived().conflicts_with(arg::lock_hash().get_name())), + App::new("get-live-cells") .about("Get live cells by lock/type/code hash") .arg(arg::lock_hash()) .arg(arg::type_hash()) @@ -140,13 +142,13 @@ impl<'a> WalletSubCommand<'a> { .arg( Arg::with_name("fast-mode") .long("fast-mode") - .help("Only visit current range (by --from and --to) of live cells"), + .about("Only visit current range (by --from and --to) of live cells"), ), // Move to index subcommand - SubCommand::with_name("db-metrics") + App::new("db-metrics") .about("Show index database metrics") .setting(AppSettings::Hidden), - SubCommand::with_name("top-capacity") + App::new("top-capacity") .about("Show top n capacity owned by lock script hash") .arg(arg::top_n()), ]) @@ -721,7 +723,7 @@ impl<'a> CliSubCommand for WalletSubCommand<'a> { let resp = serde_json::to_value(metrcis).map_err(|err| err.to_string())?; Ok(resp.render(format, color)) } - _ => Err(matches.usage().to_owned()), + _ => Err(Self::subcommand().generate_usage()), } } } diff --git a/src/utils/arg.rs b/src/utils/arg.rs index c2f89efc..a4825c48 100644 --- a/src/utils/arg.rs +++ b/src/utils/arg.rs @@ -5,200 +5,200 @@ use crate::utils::arg_parser::{ use ckb_types::{H160, H256}; use clap::Arg; -pub fn privkey_path<'a, 'b>() -> Arg<'a, 'b> { +pub fn privkey_path<'a>() -> Arg<'a> { Arg::with_name("privkey-path") .long("privkey-path") .takes_value(true) .validator(|input| PrivkeyPathParser.validate(input)) - .help("Private key file path (only read first line)") + .about("Private key file path (only read first line)") } -pub fn pubkey<'a, 'b>() -> Arg<'a, 'b> { +pub fn pubkey<'a>() -> Arg<'a> { Arg::with_name("pubkey") .long("pubkey") .takes_value(true) .validator(|input| PubkeyHexParser.validate(input)) - .help("Public key (hex string, compressed format)") + .about("Public key (hex string, compressed format)") } -pub fn address<'a, 'b>() -> Arg<'a, 'b> { +pub fn address<'a>() -> Arg<'a> { Arg::with_name("address") .long("address") .takes_value(true) .validator(|input| AddressParser::default().validate(input)) - .help( + .about( "Target address (see: https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md)", ) } -pub fn lock_hash<'a, 'b>() -> Arg<'a, 'b> { +pub fn lock_hash<'a>() -> Arg<'a> { Arg::with_name("lock-hash") .long("lock-hash") .takes_value(true) .validator(|input| FixedHashParser::::default().validate(input)) - .help("Lock hash") + .about("Lock hash") } -pub fn derive_receiving_address_length<'a, 'b>() -> Arg<'a, 'b> { +pub fn derive_receiving_address_length<'a>() -> Arg<'a> { Arg::with_name("derive-receiving-address-length") .long("derive-receiving-address-length") .takes_value(true) .default_value("1000") .validator(|input| FromStrParser::::default().validate(input)) - .help("Search derived receiving address length") + .about("Search derived receiving address length") } -pub fn derive_change_address_length<'a, 'b>() -> Arg<'a, 'b> { +pub fn derive_change_address_length<'a>() -> Arg<'a> { Arg::with_name("derive-change-address-length") .long("derive-change-address-length") .takes_value(true) .default_value("1000") .validator(|input| FromStrParser::::default().validate(input)) - .help("Search derived change address length") + .about("Search derived change address length") } -pub fn derive_change_address<'a, 'b>() -> Arg<'a, 'b> { +pub fn derive_change_address<'a>() -> Arg<'a> { Arg::with_name("derive-change-address") .long("derive-change-address") .takes_value(true) .validator(|input| AddressParser::default().validate(input)) - .help("Manually specify the last change address (search 10000 addresses max, required keystore password, see: BIP-44)") + .about("Manually specify the last change address (search 10000 addresses max, required keystore password, see: BIP-44)") } -pub fn derived<'a, 'b>() -> Arg<'a, 'b> { +pub fn derived<'a>() -> Arg<'a> { Arg::with_name("derived") .long("derived") - .help("Search derived address space (search 10000 addresses(change/receiving) max, required keystore password, see: BIP-44)") + .about("Search derived address space (search 10000 addresses(change/receiving) max, required keystore password, see: BIP-44)") } -pub fn lock_arg<'a, 'b>() -> Arg<'a, 'b> { +pub fn lock_arg<'a>() -> Arg<'a> { Arg::with_name("lock-arg") .long("lock-arg") .takes_value(true) .validator(|input| FixedHashParser::::default().validate(input)) - .help("Lock argument (account identifier, blake2b(pubkey)[0..20])") + .about("Lock argument (account identifier, blake2b(pubkey)[0..20])") } -pub fn from_account<'a, 'b>() -> Arg<'a, 'b> { +pub fn from_account<'a>() -> Arg<'a> { Arg::with_name("from-account") .long("from-account") .takes_value(true) .validator(|input| { FixedHashParser::::default() - .validate(input.clone()) + .validate(input) .or_else(|err| { AddressParser::default() - .validate(input.clone()) + .validate(input) .and_then(|()| AddressParser::new_sighash().validate(input)) .map_err(|_| err) }) }) - .help("The account's lock-arg or sighash address (transfer from this account)") + .about("The account's lock-arg or sighash address (transfer from this account)") } -pub fn from_locked_address<'a, 'b>() -> Arg<'a, 'b> { +pub fn from_locked_address<'a>() -> Arg<'a> { Arg::with_name("from-locked-address") .long("from-locked-address") .takes_value(true) .validator(|input| AddressParser::default().validate(input)) - .help("The time locked multisig address to search live cells (which S=0,R=0,M=1,N=1 and have since value)") + .about("The time locked multisig address to search live cells (which S=0,R=0,M=1,N=1 and have since value)") } -pub fn to_address<'a, 'b>() -> Arg<'a, 'b> { +pub fn to_address<'a>() -> Arg<'a> { Arg::with_name("to-address") .long("to-address") .takes_value(true) .validator(|input| AddressParser::default().validate(input)) - .help("Target address") + .about("Target address") } -pub fn to_data<'a, 'b>() -> Arg<'a, 'b> { +pub fn to_data<'a>() -> Arg<'a> { Arg::with_name("to-data") .long("to-data") .takes_value(true) .validator(|input| HexParser.validate(input)) - .help("Hex data store in target cell (optional)") + .about("Hex data store in target cell (optional)") } -pub fn to_data_path<'a, 'b>() -> Arg<'a, 'b> { +pub fn to_data_path<'a>() -> Arg<'a> { Arg::with_name("to-data-path") .long("to-data-path") .takes_value(true) .validator(|input| FilePathParser::new(true).validate(input)) - .help("Data binary file path store in target cell (optional)") + .about("Data binary file path store in target cell (optional)") } -pub fn capacity<'a, 'b>() -> Arg<'a, 'b> { +pub fn capacity<'a>() -> Arg<'a> { Arg::with_name("capacity") .long("capacity") .takes_value(true) .validator(|input| CapacityParser.validate(input)) - .help("The capacity (unit: CKB, format: 123.335)") + .about("The capacity (unit: CKB, format: 123.335)") } -pub fn tx_fee<'a, 'b>() -> Arg<'a, 'b> { +pub fn tx_fee<'a>() -> Arg<'a> { Arg::with_name("tx-fee") .long("tx-fee") .takes_value(true) .validator(|input| CapacityParser.validate(input)) - .help("The transaction fee capacity (unit: CKB, format: 0.0001)") + .about("The transaction fee capacity (unit: CKB, format: 0.0001)") } -pub fn type_hash<'a, 'b>() -> Arg<'a, 'b> { +pub fn type_hash<'a>() -> Arg<'a> { Arg::with_name("type-hash") .long("type-hash") .takes_value(true) .validator(|input| FixedHashParser::::default().validate(input)) - .help("The type script hash") + .about("The type script hash") } -pub fn code_hash<'a, 'b>() -> Arg<'a, 'b> { +pub fn code_hash<'a>() -> Arg<'a> { Arg::with_name("code-hash") .long("code-hash") .takes_value(true) .validator(|input| FixedHashParser::::default().validate(input)) - .help("The type script's code hash") + .about("The type script's code hash") } -pub fn live_cells_limit<'a, 'b>() -> Arg<'a, 'b> { +pub fn live_cells_limit<'a>() -> Arg<'a> { Arg::with_name("limit") .long("limit") .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) .default_value("15") - .help("Get live cells <= limit") + .about("Get live cells <= limit") } -pub fn from_block_number<'a, 'b>() -> Arg<'a, 'b> { +pub fn from_block_number<'a>() -> Arg<'a> { Arg::with_name("from") .long("from") .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) - .help("From block number (inclusive)") + .about("From block number (inclusive)") } -pub fn to_block_number<'a, 'b>() -> Arg<'a, 'b> { +pub fn to_block_number<'a>() -> Arg<'a> { Arg::with_name("to") .long("to") .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) - .help("To block number (inclusive)") + .about("To block number (inclusive)") } -pub fn top_n<'a, 'b>() -> Arg<'a, 'b> { +pub fn top_n<'a>() -> Arg<'a> { Arg::with_name("number") - .short("n") + .short('n') .long("number") .takes_value(true) .validator(|input| FromStrParser::::default().validate(input)) .default_value("10") - .help("Get top n capacity addresses") + .about("Get top n capacity addresses") } -pub fn out_point<'a, 'b>() -> Arg<'a, 'b> { +pub fn out_point<'a>() -> Arg<'a> { Arg::with_name("out-point") .long("out-point") .takes_value(true) .validator(|input| { OutPointParser.validate(input) }) - .help("out-point to specify a cell. Example: 0xd56ed5d4e8984701714de9744a533413f79604b3b91461e2265614829d2005d1-1") + .about("out-point to specify a cell. Example: 0xd56ed5d4e8984701714de9744a533413f79604b3b91461e2265614829d2005d1-1") } diff --git a/src/utils/arg_parser.rs b/src/utils/arg_parser.rs index fc40ebc1..e5d34548 100644 --- a/src/utils/arg_parser.rs +++ b/src/utils/arg_parser.rs @@ -18,8 +18,8 @@ use url::Url; pub trait ArgParser { fn parse(&self, input: &str) -> Result; - fn validate(&self, input: String) -> Result<(), String> { - self.parse(&input).map(|_| ()) + fn validate(&self, input: &str) -> Result<(), String> { + self.parse(input).map(|_| ()) } fn from_matches>(&self, matches: &ArgMatches, name: &str) -> Result { diff --git a/src/utils/completer.rs b/src/utils/completer.rs index 3d4cdac8..b36b653c 100644 --- a/src/utils/completer.rs +++ b/src/utils/completer.rs @@ -27,21 +27,18 @@ static DEFAULT_BREAK_CHARS: [u8; 17] = [ #[cfg(windows)] static ESCAPE_CHAR: Option = None; -pub struct CkbCompleter<'a, 'b> -where - 'a: 'b, -{ - clap_app: Arc>, +pub struct CkbCompleter<'a> { + clap_app: Arc>, } -impl<'a, 'b> CkbCompleter<'a, 'b> { - pub fn new(clap_app: clap::App<'a, 'b>) -> Self { +impl<'a> CkbCompleter<'a> { + pub fn new(clap_app: clap::App<'a>) -> Self { CkbCompleter { clap_app: Arc::new(clap_app), } } - pub fn get_completions(app: &Arc>, args: &[String]) -> Vec<(String, String)> { + pub fn get_completions(app: &Arc>, args: &[String]) -> Vec<(String, String)> { let args_set = args.iter().collect::>(); let switched_completions = |short: Option, long: Option<&str>, multiple: bool, required: bool| { @@ -67,39 +64,23 @@ impl<'a, 'b> CkbCompleter<'a, 'b> { names } }; - app.p - .subcommands() + app.get_subcommands() + .iter() .map(|app| { [ - vec![(app.p.meta.name.clone(), app.p.meta.name.clone())], - app.p - .meta - .aliases - .as_ref() - .map(|aliases| { - aliases - .iter() - .map(|(alias, _)| ((*alias).to_owned(), (*alias).to_owned())) - .collect::>() - }) - .unwrap_or_else(|| vec![]), + vec![(app.get_name().to_owned(), app.get_name().to_owned())], + app.get_all_aliases() + .map(|alias| (alias.to_owned(), alias.to_owned())) + .collect::>(), ] .concat() }) - .chain(app.p.flags().map(|a| { + .chain(app.get_arguments().iter().map(|a| { switched_completions( - a.s.short, - a.s.long, - a.b.is_set(clap::ArgSettings::Multiple), - a.b.is_set(clap::ArgSettings::Required), - ) - })) - .chain(app.p.opts().map(|a| { - switched_completions( - a.s.short, - a.s.long, - a.b.is_set(clap::ArgSettings::Multiple), - a.b.is_set(clap::ArgSettings::Required), + a.get_short(), + a.get_long(), + a.is_set(clap::ArgSettings::MultipleValues), + a.is_set(clap::ArgSettings::Required), ) })) .collect::>>() @@ -107,19 +88,13 @@ impl<'a, 'b> CkbCompleter<'a, 'b> { } pub fn find_subcommand<'s, Iter: iter::Iterator>( - app: Arc>, + app: Arc>, mut prefix_names: iter::Peekable, - ) -> Option>> { + ) -> Option>> { if let Some(name) = prefix_names.next() { - for inner_app in &(app.p.subcommands) { - if inner_app.p.meta.name == name - || inner_app - .p - .meta - .aliases - .as_ref() - .map(|aliases| aliases.iter().any(|&(alias, _)| alias == name)) - .unwrap_or(false) + for inner_app in app.get_subcommands().iter() { + if inner_app.get_name() == name + || inner_app.get_all_aliases().any(|alias| alias == name) { return if prefix_names.peek().is_none() { Some(Arc::new(inner_app.to_owned())) @@ -129,7 +104,7 @@ impl<'a, 'b> CkbCompleter<'a, 'b> { } } } - if prefix_names.peek().is_none() || app.p.subcommands.is_empty() { + if prefix_names.peek().is_none() || app.get_subcommands().is_empty() { Some(app) } else { None @@ -137,7 +112,7 @@ impl<'a, 'b> CkbCompleter<'a, 'b> { } } -impl<'a, 'b> Completer for CkbCompleter<'a, 'b> { +impl<'a> Completer for CkbCompleter<'a> { type Candidate = Pair; fn complete( @@ -206,9 +181,9 @@ impl<'a, 'b> Completer for CkbCompleter<'a, 'b> { } } -impl<'a, 'b> Helper for CkbCompleter<'a, 'b> {} +impl<'a> Helper for CkbCompleter<'a> {} -impl<'a, 'b> Highlighter for CkbCompleter<'a, 'b> { +impl<'a> Highlighter for CkbCompleter<'a> { fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> { Owned("\x1b[1m".to_owned() + hint + "\x1b[m") } @@ -235,7 +210,7 @@ impl<'a, 'b> Highlighter for CkbCompleter<'a, 'b> { } } -impl<'a, 'b> Hinter for CkbCompleter<'a, 'b> { +impl<'a> Hinter for CkbCompleter<'a> { fn hint(&self, _line: &str, _pos: usize, _context: &Context) -> Option { None } diff --git a/test/Cargo.toml b/test/Cargo.toml index 57b47024..43dd95e0 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = "2" +clap = "3.0.0-beta.1" tempfile = "3.0" log = "0.4" env_logger = "0.6" diff --git a/test/src/app.rs b/test/src/app.rs index efb4a5ff..21094f77 100644 --- a/test/src/app.rs +++ b/test/src/app.rs @@ -33,7 +33,7 @@ impl App { &self.cli_bin } - fn matches<'a>() -> clap::ArgMatches<'a> { + fn matches() -> clap::ArgMatches { clap::App::new("ckb-cli-test") .arg( clap::Arg::with_name("ckb-bin") @@ -41,7 +41,7 @@ impl App { .takes_value(true) .required(true) .value_name("PATH") - .help("Path to ckb executable"), + .about("Path to ckb executable"), ) .arg( clap::Arg::with_name("cli-bin") @@ -49,7 +49,7 @@ impl App { .takes_value(true) .required(true) .value_name("PATH") - .help("Path to ckb-cli executable"), + .about("Path to ckb-cli executable"), ) .get_matches() } From 01a044ae1b84fcb0341918be0d3a21949169947f Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 12 May 2020 21:26:23 +0000 Subject: [PATCH 8/9] chore(deps): bump serde_yaml from 0.8.11 to 0.8.12 Bumps [serde_yaml](https://github.com/dtolnay/serde-yaml) from 0.8.11 to 0.8.12. - [Release notes](https://github.com/dtolnay/serde-yaml/releases) - [Commits](https://github.com/dtolnay/serde-yaml/compare/0.8.11...0.8.12) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d8ba36f6..cab34ecd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2869,9 +2869,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35" +checksum = "16c7a592a1ec97c9c1c68d75b6e537dcbf60c7618e038e7841e00af1d9ccf0c4" dependencies = [ "dtoa", "linked-hash-map 0.5.2", From bdd1193a23eed1d28cbc0be44b329a560760805e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 19 May 2020 21:23:35 +0000 Subject: [PATCH 9/9] chore(deps): bump fnv from 1.0.6 to 1.0.7 Bumps [fnv](https://github.com/servo/rust-fnv) from 1.0.6 to 1.0.7. - [Release notes](https://github.com/servo/rust-fnv/releases) - [Commits](https://github.com/servo/rust-fnv/compare/v1.0.6...v1.0.7) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cab34ecd..a3f727a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1158,9 +1158,9 @@ dependencies = [ [[package]] name = "fnv" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "foreign-types"