Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 131 additions & 67 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ bitcoin = { git="https://github.com/rust-bitcoin/rust-bitcoin", rev="436de8ef12a
faster-hex = "0.6"
env_logger = "0.6"
crossbeam-channel = "0.5.8"
clap = "=3.0.0-beta.1"
clap_generate = "=3.0.0-beta.1"
clap = { version = "4.5.0", features = ["cargo", "deprecated", "string", "derive"] }
clap_complete = "4.5.0"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ ci: fmt clippy test security-audit check-crates check-licenses
git diff --exit-code Cargo.lock

integration:
bash devtools/ci/integration.sh v0.203.0 $(ARGS)
bash devtools/ci/integration.sh v0.204.0 $(ARGS)

integration-spec:
@if [ -z "$(SPEC)" ]; then \
echo "Usage: make integration-spec SPEC=pattern"; \
echo "Example: make integration-spec SPEC=deploy_type_id"; \
exit 1; \
fi
bash devtools/ci/integration.sh v0.203.0 --spec=$(SPEC)
bash devtools/ci/integration.sh v0.204.0 --spec=$(SPEC)

prod: ## Build binary with release profile.
cargo build --locked --release
Expand Down
34 changes: 34 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use clap::Parser;

use crate::utils::arg_parser::{ArgParser, UrlParser};

fn parse_url(input: &str) -> Result<String, String> {
UrlParser.validate(input).map(|_| input.to_string())
}

#[derive(Parser, Debug)]
#[command(name = "ckb-cli")]
pub struct CliArgs {
/// CKB RPC server url.
/// The default value is http://127.0.0.1:8114
/// You may also use some public available nodes, check the list of public nodes:
/// https://github.com/nervosnetwork/ckb/wiki/Public-JSON-RPC-nodes
#[arg(long, value_parser = parse_url)]
pub url: Option<String>,

/// Select output format
#[arg(long = "output-format", id = "output-format", value_parser = ["yaml", "json"], default_value = "yaml", global = true)]
pub output_format: String,

/// Do not highlight(color) output json
#[arg(long = "no-color", id = "no-color", global = true)]
pub no_color: bool,

/// Display request parameters
#[arg(long, global = true)]
pub debug: bool,

/// This is a local only subcommand, do not check alerts and get network type
#[arg(long = "local-only", id = "local-only", global = true)]
pub local_only: bool,
}
41 changes: 21 additions & 20 deletions src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::subcommands::{
UtilSubCommand, WalletSubCommand,
};
use crate::utils::{
arg_parser::ArgMatchesExt,
completer::CkbCompleter,
config::GlobalConfig,
genesis_info::GenesisInfo,
Expand All @@ -34,7 +35,7 @@ pub struct InteractiveEnv {
config: GlobalConfig,
config_file: PathBuf,
history_file: PathBuf,
parser: clap::App<'static>,
parser: clap::Command,
plugin_mgr: PluginManager,
key_store: KeyStore,
rpc_client: HttpRpcClient,
Expand Down Expand Up @@ -126,8 +127,8 @@ impl InteractiveEnv {
}
for (cmd_name, description) in &plugin_sub_cmds {
parser = parser.subcommand(
// FIXME: when clap updated add `clap::AppSettings::DisableHelpFlags` back
clap::App::new(cmd_name.as_str()).about(description.as_str()),
// FIXME: when clap updated add `clap::CommandSettings::DisableHelpFlags` back
clap::Command::new(cmd_name.clone()).about(description.clone()),
);
}

Expand Down Expand Up @@ -218,7 +219,7 @@ impl InteractiveEnv {

fn handle_command(
&mut self,
parser: &clap::App,
parser: &clap::Command,
line: &str,
env_regex: &Regex,
) -> Result<bool, String> {
Expand Down Expand Up @@ -251,7 +252,7 @@ impl InteractiveEnv {

match parser.clone().try_get_matches_from(args) {
Ok(matches) => match matches.subcommand() {
("config", Some(m)) => {
Some(("config", m)) => {
if let Some(url) = m.value_of("url") {
self.config.set_url(url.to_string());
self.rpc_client = HttpRpcClient::new(self.config.get_url().to_string());
Expand Down Expand Up @@ -288,35 +289,35 @@ impl InteractiveEnv {
.map_err(|err| format!("save config file failed: {:?}", err))?;
Ok(())
}
("set", Some(m)) => {
Some(("set", m)) => {
let key = m.value_of("key").unwrap().to_owned();
let value = m.value_of("value").unwrap().to_owned();
self.config.set(key, serde_json::Value::String(value));
Ok(())
}
("get", Some(m)) => {
Some(("get", m)) => {
let key = m.value_of("key");
println!("{}", self.config.get(key).render(format, color));
Ok(())
}
("info", _) => {
Some(("info", _)) => {
self.config.print(false);
Ok(())
}
("rpc", Some(sub_matches)) => {
Some(("rpc", sub_matches)) => {
check_alerts(&mut self.rpc_client);
let output = RpcSubCommand::new(&mut self.rpc_client, &mut self.raw_rpc_client)
.process(sub_matches, debug)?;
output.print(format, color);
Ok(())
}
("account", Some(sub_matches)) => {
Some(("account", sub_matches)) => {
let output = AccountSubCommand::new(&mut self.plugin_mgr, &mut self.key_store)
.process(sub_matches, debug)?;
output.print(format, color);
Ok(())
}
("mock-tx", Some(sub_matches)) => {
Some(("mock-tx", sub_matches)) => {
let genesis_info = self.genesis_info().ok();
let output = MockTxSubCommand::new(
&mut self.rpc_client,
Expand All @@ -327,32 +328,32 @@ impl InteractiveEnv {
output.print(format, color);
Ok(())
}
("tx", Some(sub_matches)) => {
Some(("tx", sub_matches)) => {
let genesis_info = self.genesis_info().ok();
let output =
TxSubCommand::new(&mut self.rpc_client, &mut self.plugin_mgr, genesis_info)
.process(sub_matches, debug)?;
output.print(format, color);
Ok(())
}
("util", Some(sub_matches)) => {
Some(("util", sub_matches)) => {
let output = UtilSubCommand::new(&mut self.rpc_client, &mut self.plugin_mgr)
.process(sub_matches, debug)?;
output.print(format, color);
Ok(())
}
("plugin", Some(sub_matches)) => {
Some(("plugin", sub_matches)) => {
let output =
PluginSubCommand::new(&mut self.plugin_mgr).process(sub_matches, debug)?;
output.print(format, color);
Ok(())
}
("molecule", Some(sub_matches)) => {
Some(("molecule", sub_matches)) => {
let output = MoleculeSubCommand::new().process(sub_matches, debug)?;
output.print(format, color);
Ok(())
}
("wallet", Some(sub_matches)) => {
Some(("wallet", sub_matches)) => {
let genesis_info = self.genesis_info()?;
let output = WalletSubCommand::new(
&mut self.rpc_client,
Expand All @@ -363,7 +364,7 @@ impl InteractiveEnv {
output.print(format, color);
Ok(())
}
("dao", Some(sub_matches)) => {
Some(("dao", sub_matches)) => {
let genesis_info = self.genesis_info()?;
let output = DAOSubCommand::new(
&mut self.rpc_client,
Expand All @@ -374,7 +375,7 @@ impl InteractiveEnv {
output.print(format, color);
Ok(())
}
("sudt", Some(sub_matches)) => {
Some(("sudt", sub_matches)) => {
let genesis_info = self.genesis_info()?;
let output = SudtSubCommand::new(
&mut self.rpc_client,
Expand All @@ -385,7 +386,7 @@ impl InteractiveEnv {
output.print(format, color);
Ok(())
}
("deploy", Some(sub_matches)) => {
Some(("deploy", sub_matches)) => {
let genesis_info = self.genesis_info()?;
let output = DeploySubCommand::new(
&mut self.rpc_client,
Expand All @@ -396,7 +397,7 @@ impl InteractiveEnv {
output.print(format, color);
Ok(())
}
("exit", _) => {
Some(("exit", _)) => {
return Ok(true);
}
_ => Ok(()),
Expand Down
Loading
Loading