CLI API refactoring and improvement (#4692)

It changes the way we extended the CLI functionalities of substrate to allow more flexibility. (If this was not clear, here is another version: it changes the `sc_cli` API to allow more flexibility).

This touches a few important things:
 - the startup of the async task with tokei:
    This was in node and node-template and I moved it to substrate. The idea is to have 1 time the code that handles unix signals (SIGTERM and SIGINT) properly. It is however possible to make this more generic to wait for a future instead and provide only a helper for the basic handling of SIGTERM and SIGINT.
 - increased the version of structopt and tokei
 - no more use of structopt internal's API
 - less use of generics

Related to #4643 and https://github.com/paritytech/cumulus/pull/42: the implementation of "into_configuration" and "get_config" are similar but with better flexibility so it is now possible in cumulus to have the command-line arguments only of the run command for polkadot if we want

Related to https://github.com/paritytech/cumulus/issues/24 and https://github.com/paritytech/cumulus/issues/34 : it will now be possible to make a configuration struct for polkadot with some overrides of the default parameters much more easily.
This commit is contained in:
Cecile Tonglet
2020-01-30 11:40:08 +01:00
committed by GitHub
parent 506f9c29d9
commit 605f643eed
28 changed files with 2041 additions and 2234 deletions
+2 -24
View File
@@ -18,31 +18,8 @@
#![warn(missing_docs)]
use futures::channel::oneshot;
use futures::{future, FutureExt};
use sc_cli::VersionInfo;
use std::cell::RefCell;
// handles ctrl-c
struct Exit;
impl sc_cli::IntoExit for Exit {
type Exit = future::Map<oneshot::Receiver<()>, fn(Result<(), oneshot::Canceled>) -> ()>;
fn into_exit(self) -> Self::Exit {
// can't use signal directly here because CtrlC takes only `Fn`.
let (exit_send, exit) = oneshot::channel();
let exit_send_cell = RefCell::new(Some(exit_send));
ctrlc::set_handler(move || {
if let Some(exit_send) = exit_send_cell.try_borrow_mut().expect("signal handler not reentrant; qed").take() {
exit_send.send(()).expect("Error sending exit notification");
}
}).expect("Error setting Ctrl-C handler");
exit.map(|_| ())
}
}
fn main() -> Result<(), sc_cli::error::Error> {
let version = VersionInfo {
name: "Substrate Node",
@@ -52,7 +29,8 @@ fn main() -> Result<(), sc_cli::error::Error> {
author: "Parity Technologies <admin@parity.io>",
description: "Generic substrate node",
support_url: "https://github.com/paritytech/substrate/issues/new",
copyright_start_year: 2017,
};
node_cli::run(std::env::args(), Exit, version)
node_cli::run(std::env::args(), version)
}