Skip to content

Commit aab9649

Browse files
authored
Merge pull request #3306 from iosh/cli
add verison and fix error
2 parents 6c0c287 + 101bc7a commit aab9649

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

bins/conflux/src/command/rpc.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ impl RpcCommand {
2525
None => return Err(String::from("RPC URL not specified")),
2626
};
2727

28-
let args: Vec<Value> = match matches.get_many::<String>("rpc-args") {
29-
Some(args) => {
28+
let args: Vec<Value> = match matches.try_get_many::<String>("rpc-args")
29+
{
30+
Ok(Some(args)) => {
3031
let mut params = Vec::new();
3132

3233
for arg in args {
@@ -37,7 +38,8 @@ impl RpcCommand {
3738
}
3839
params
3940
}
40-
None => Vec::new(),
41+
Ok(None) => Vec::new(),
42+
Err(_e) => Vec::new(),
4143
};
4244

4345
Ok(Some(RpcCommand {
@@ -136,6 +138,8 @@ impl<'a> ArgSchema<'a> {
136138
#[cfg(test)]
137139

138140
mod tests {
141+
use std::vec;
142+
139143
use crate::cli::Cli;
140144

141145
use super::*;
@@ -308,6 +312,28 @@ mod tests {
308312
expected_url: "http://localhost:12539",
309313
expected_params: vec![json!("0x654321fedcba"), json!(false)],
310314
},
315+
TestCase {
316+
name: "voting_status",
317+
args: vec!["conflux", "rpc", "local", "pos", "voting_status"],
318+
expected_method: "test_posVotingStatus",
319+
expected_params: vec![],
320+
expected_url: "http://localhost:12539",
321+
},
322+
TestCase {
323+
name: "voting_status_with_custom_url",
324+
args: vec![
325+
"conflux",
326+
"rpc",
327+
"local",
328+
"pos",
329+
"voting_status",
330+
"--url",
331+
"http://localhost:9999",
332+
],
333+
expected_method: "test_posVotingStatus",
334+
expected_params: vec![],
335+
expected_url: "http://localhost:9999",
336+
},
311337
];
312338

313339
for test_case in test_cases {

bins/conflux/src/main.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ use log4rs::{
2828
};
2929
use network::throttling::THROTTLING_SERVICE;
3030
use parking_lot::{Condvar, Mutex};
31-
use std::sync::Arc;
31+
use std::sync::{Arc, OnceLock};
32+
33+
static VERSION: OnceLock<String> = OnceLock::new();
34+
35+
fn get_version() -> &'static str {
36+
VERSION.get_or_init(|| parity_version::version(crate_version!()))
37+
}
3238

3339
fn main() -> Result<(), String> {
3440
#[cfg(feature = "deadlock-detection")]
@@ -56,8 +62,7 @@ fn main() -> Result<(), String> {
5662
});
5763
} // only for #[cfg]
5864

59-
let version = parity_version::version(crate_version!());
60-
let matches = Cli::command().get_matches();
65+
let matches = Cli::command().version(get_version()).get_matches();
6166

6267
if let Some(output) = handle_sub_command(&matches)? {
6368
println!("{}", output);
@@ -88,7 +93,7 @@ fn main() -> Result<(), String> {
8893
:......::::.......:::..::::..::..::::::::........:::.......:::..:::::..::
8994
Current Version: {}
9095
",
91-
version
96+
get_version()
9297
);
9398

9499
let client_handle: Box<dyn ClientTrait>;

0 commit comments

Comments
 (0)