This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
CLI API refactoring and improvement #4692
Merged
Merged
Changes from all commits
Commits
Show all changes
102 commits
Select commit
Hold shift + click to select a range
5721bab
Expose a method that allows converting RunCmd to Configuration
cecton e533791
WIP
cecton ecaeb7f
WIP
cecton f6c249b
WIP
cecton 9405756
WIP
cecton 99159d2
WIP
cecton 904b292
WIP
cecton 5c684a0
WIP
cecton 85b2d11
WIP
cecton c8581ad
WIP
cecton 1a9c594
WIP
cecton dae1972
WIP
cecton 214076d
WIP
cecton f98c3a4
WIP
cecton 963d33a
WIP
cecton 3a1bc54
WIP
cecton fda5a4c
WIP
cecton 4eb3213
WIP
cecton b67f970
WIP
cecton ca93dc7
WIP
cecton 1025061
WIP
cecton 6f6a8fb
Update bin/node-template/src/cli.rs
cecton ef4dd6a
WIP
cecton cd4fbb5
WIP
cecton a7d14f4
WIP
cecton 165631c
WIP
cecton d17ed47
WIP
cecton 82b85e6
Merge commit '410ce114e8fb37e5807606ed77fec80393042435^' into cecton-…
cecton 8c8c962
Merge commit '410ce114e8fb37e5807606ed77fec80393042435' into cecton-c…
cecton f310371
Merge commit 'c2b0c0f8395165f4fc5ee6b9ca8755cc9dd0d41f^' into cecton-…
cecton b7f066e
Merge commit 'c2b0c0f8395165f4fc5ee6b9ca8755cc9dd0d41f' into cecton-c…
cecton 2614c31
Merge commit '4c4ee3d5b91c4c825aef4fde2b096f014a89346a^' into cecton-…
cecton 1fe0c47
Merge commit '4c4ee3d5b91c4c825aef4fde2b096f014a89346a' into cecton-c…
cecton 0e81c21
Merge commit '3fa5f09dd1df584c1fa9de9c870e6cd5d44854f4' into cecton-c…
cecton 1983f96
Merge commit '47c36e6efe8285c9a6cbbcc0f588e3e7c4009de5' into cecton-c…
cecton ec95f22
Merge commit '879e28ae38643c028fa09c157e7b2714bcbf02a1' into cecton-c…
cecton 6d70474
Merge commit '083ada5c01ffbce9dbe763d4757ceba3ed1027b4' into cecton-c…
cecton 93b8467
Merge commit '8de5340c42e5e4638e63285f93cebaa1cca5ea46' into cecton-c…
cecton 96e6e31
Merge commit 'cfbb24cbdbc84410624a84daec55bfe178c7549f' into cecton-c…
cecton 2c70e27
Merge commit 'cb9c1818f198b946b402652d173bbd76e8fbe7d0' into cecton-c…
cecton 457a2c6
Merge commit '6ee1244e2d018333746d82131222308e0d802e6a^' into cecton-…
cecton 7a1fffc
Merge commit '6ee1244e2d018333746d82131222308e0d802e6a' into cecton-c…
cecton f25f218
Merge commit '4b2f70f8476a8c4092df952e549090268f936d1d' into cecton-c…
cecton 1e5e187
Merge commit '6c3b86d16ad19751fbbab86e369883b5425c72df' into cecton-c…
cecton 33e9314
fixed node-template
cecton c1dd237
WIP
cecton 7c14ccf
WIP
cecton fee08c4
WIP
cecton 4a0e3ee
Merge remote-tracking branch 'origin/master' into cecton-cli-refactoring
cecton 4bf2cfb
WIP
cecton 8c85245
WIP
cecton 5ee6197
WIP
cecton c69956e
WIP
cecton 93fd4ce
WIP
cecton 58b8db2
Update client/cli/src/lib.rs
cecton 4ab4bf2
WIP
cecton cc7e684
Update client/cli/src/lib.rs
cecton 7ffc8e5
WIP
cecton 63b7735
WIP
cecton bc28887
WIP
cecton 891eb19
WIP
cecton f75e03b
WIP
cecton bd596df
WIP
cecton 9eb2e4f
Merge remote-tracking branch 'origin/master' into cecton-cli-refactoring
cecton 6dacdbf
WIP
cecton d2564b7
Rename tasks_executor to task_executor
cecton 77f3db8
WIP
cecton 8bc1914
WIP
cecton 3e6b83a
Merge remote-tracking branch 'origin/master' into cecton-cli-refactoring
cecton 1ad686c
Added conflict between --sentry and --light
cecton 69072ba
WIP
cecton f1eae7d
WIP
cecton bea809d
WIP
cecton b6df525
WIP
cecton 07e0310
WIP
cecton e99c674
WIP
cecton 625933a
Merge commit '8f4495886a98d4a867d3f3813a8bf4dc6bca3a3f^' into cecton-…
cecton 5a1c557
Merge commit '8f4495886a98d4a867d3f3813a8bf4dc6bca3a3f' into cecton-c…
cecton c3bb276
WIP
cecton 8aedbd4
WIP
cecton 2df875b
Merge commit '38c5ed0af7740d55993e91bdc9001cc17446180f' into cecton-c…
cecton 35e1cd4
WIP
cecton 031ca07
Update client/cli/src/runtime.rs
cecton ff986dc
WIP
cecton a0d4a54
Update client/cli/src/params.rs
cecton 34cf930
Update client/cli/src/params.rs
cecton 957a102
Update client/cli/src/params.rs
cecton f3d7b01
Update client/cli/src/params.rs
cecton 292ec6e
Update client/cli/src/params.rs
cecton ec78b9c
Update client/cli/src/params.rs
cecton 505f574
Update client/cli/src/params.rs
cecton 3ffe543
Update client/cli/src/params.rs
cecton 03cc75f
Update client/cli/src/params.rs
cecton d126cb5
Update client/cli/src/params.rs
cecton 54ac33d
Update client/cli/src/params.rs
cecton 4fd3edf
WIP
cecton 6276b76
WIP
cecton 6c62acc
Merge remote-tracking branch 'origin/master' into cecton-cli-refactoring
cecton e543ebe
Merge remote-tracking branch 'origin/master' into cecton-cli-refactoring
cecton 6424b53
Update client/cli/src/lib.rs
cecton 7774621
Update client/cli/src/lib.rs
cecton 9c09d17
WIP
cecton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,121 +1,11 @@ | ||
| use crate::service; | ||
| use futures::{future::{select, Map, Either}, FutureExt, channel::oneshot}; | ||
| use std::cell::RefCell; | ||
| use tokio::runtime::Runtime; | ||
| pub use sc_cli::{VersionInfo, IntoExit, error}; | ||
| use sc_cli::{display_role, informant, parse_and_prepare, ParseAndPrepare, NoCustom}; | ||
| use sc_service::{AbstractService, Roles as ServiceRoles, Configuration}; | ||
| use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair}; | ||
| use crate::chain_spec; | ||
| use log::info; | ||
| use sc_cli::{RunCmd, Subcommand}; | ||
| use structopt::StructOpt; | ||
|
|
||
| /// Parse command line arguments into service configuration. | ||
| pub fn run<I, T, E>(args: I, exit: E, version: VersionInfo) -> error::Result<()> where | ||
| I: IntoIterator<Item = T>, | ||
| T: Into<std::ffi::OsString> + Clone, | ||
| E: IntoExit, | ||
| { | ||
| type Config<T> = Configuration<(), T>; | ||
| match parse_and_prepare::<NoCustom, NoCustom, _>(&version, "substrate-node", args) { | ||
| ParseAndPrepare::Run(cmd) => cmd.run(load_spec, exit, | ||
| |exit, _cli_args, _custom_args, mut config: Config<_>| { | ||
| info!("{}", version.name); | ||
| info!(" version {}", config.full_version()); | ||
| info!(" by {}, 2017, 2018", version.author); | ||
| info!("Chain specification: {}", config.chain_spec.name()); | ||
| info!("Node name: {}", config.name); | ||
| info!("Roles: {}", display_role(&config)); | ||
| let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?; | ||
| config.tasks_executor = { | ||
| let runtime_handle = runtime.handle().clone(); | ||
| Some(Box::new(move |fut| { runtime_handle.spawn(fut); })) | ||
| }; | ||
| match config.roles { | ||
| ServiceRoles::LIGHT => run_until_exit( | ||
| runtime, | ||
| service::new_light(config)?, | ||
| exit | ||
| ), | ||
| _ => run_until_exit( | ||
| runtime, | ||
| service::new_full(config)?, | ||
| exit | ||
| ), | ||
| } | ||
| }), | ||
| ParseAndPrepare::BuildSpec(cmd) => cmd.run::<NoCustom, _, _, _>(load_spec), | ||
| ParseAndPrepare::ExportBlocks(cmd) => cmd.run_with_builder(|config: Config<_>| | ||
| Ok(new_full_start!(config).0), load_spec, exit), | ||
| ParseAndPrepare::ImportBlocks(cmd) => cmd.run_with_builder(|config: Config<_>| | ||
| Ok(new_full_start!(config).0), load_spec, exit), | ||
| ParseAndPrepare::CheckBlock(cmd) => cmd.run_with_builder(|config: Config<_>| | ||
| Ok(new_full_start!(config).0), load_spec, exit), | ||
| ParseAndPrepare::PurgeChain(cmd) => cmd.run(load_spec), | ||
| ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder(|config: Config<_>| | ||
| Ok(new_full_start!(config).0), load_spec), | ||
| ParseAndPrepare::CustomCommand(_) => Ok(()) | ||
| }?; | ||
| #[derive(Debug, StructOpt)] | ||
| pub struct Cli { | ||
| #[structopt(subcommand)] | ||
| pub subcommand: Option<Subcommand>, | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn load_spec(id: &str) -> Result<Option<chain_spec::ChainSpec>, String> { | ||
| Ok(match chain_spec::Alternative::from(id) { | ||
| Some(spec) => Some(spec.load()?), | ||
| None => None, | ||
| }) | ||
| } | ||
|
|
||
| fn run_until_exit<T, E>( | ||
| mut runtime: Runtime, | ||
| service: T, | ||
| e: E, | ||
| ) -> error::Result<()> | ||
| where | ||
| T: AbstractService, | ||
| E: IntoExit, | ||
| { | ||
| let (exit_send, exit) = oneshot::channel(); | ||
|
|
||
| let informant = informant::build(&service); | ||
|
|
||
| let handle = runtime.spawn(select(exit, informant)); | ||
|
|
||
| // we eagerly drop the service so that the internal exit future is fired, | ||
| // but we need to keep holding a reference to the global telemetry guard | ||
| let _telemetry = service.telemetry(); | ||
|
|
||
| let exit = e.into_exit(); | ||
| let service_res = runtime.block_on(select(service, exit)); | ||
|
|
||
| let _ = exit_send.send(()); | ||
|
|
||
| if let Err(e) = runtime.block_on(handle) { | ||
| log::error!("Error running node: {:?}", e); | ||
| } | ||
|
|
||
| match service_res { | ||
| Either::Left((res, _)) => res.map_err(error::Error::Service), | ||
| Either::Right((_, _)) => Ok(()) | ||
| } | ||
| } | ||
|
|
||
| // handles ctrl-c | ||
| pub struct Exit; | ||
| impl IntoExit for Exit { | ||
| type Exit = 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 || { | ||
| let exit_send = exit_send_cell.try_borrow_mut().expect("signal handler not reentrant; qed").take(); | ||
| if let Some(exit_send) = exit_send { | ||
| exit_send.send(()).expect("Error sending exit notification"); | ||
| } | ||
| }).expect("Error setting Ctrl-C handler"); | ||
|
|
||
| exit.map(drop) | ||
| } | ||
| #[structopt(flatten)] | ||
| pub run: RunCmd, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright 2017-2020 Parity Technologies (UK) Ltd. | ||
| // This file is part of Substrate. | ||
|
|
||
| // Substrate is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Substrate is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair}; | ||
| use sc_cli::{VersionInfo, error}; | ||
| use crate::service; | ||
| use crate::chain_spec; | ||
| use crate::cli::Cli; | ||
|
|
||
| /// Parse and run command line arguments | ||
| pub fn run(version: VersionInfo) -> error::Result<()> | ||
| { | ||
| let opt = sc_cli::from_args::<Cli>(&version); | ||
|
|
||
| let mut config = sc_service::Configuration::default(); | ||
| config.impl_name = "node-template"; | ||
|
|
||
| match opt.subcommand { | ||
| Some(subcommand) => sc_cli::run_subcommand( | ||
| config, | ||
| subcommand, | ||
| chain_spec::load_spec, | ||
| |config: _| Ok(new_full_start!(config).0), | ||
| &version, | ||
| ), | ||
| None => sc_cli::run( | ||
| config, | ||
| opt.run, | ||
| service::new_light, | ||
| service::new_full, | ||
| chain_spec::load_spec, | ||
| &version, | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 <[email protected]>", | ||
| 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) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.