pub fn run() -> sc_cli::Result<()> {
	let cli = Cli::from_args();

	match &cli.subcommand {
		Some(Subcommand::Key(cmd)) => cmd.run(&cli),
		Some(Subcommand::BuildSpec(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
		},
		Some(Subcommand::CheckBlock(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, import_queue, .. } =
					service::new_partial(&config, &cli)?;
				Ok((cmd.run(client, import_queue), task_manager))
			})
		},
		Some(Subcommand::ExportBlocks(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, .. } =
					service::new_partial(&config, &cli)?;
				Ok((cmd.run(client, config.database), task_manager))
			})
		},
		Some(Subcommand::ExportState(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, .. } =
					service::new_partial(&config, &cli)?;
				Ok((cmd.run(client, config.chain_spec), task_manager))
			})
		},
		Some(Subcommand::ImportBlocks(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, import_queue, .. } =
					service::new_partial(&config, &cli)?;
				Ok((cmd.run(client, import_queue), task_manager))
			})
		},
		Some(Subcommand::PurgeChain(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.sync_run(|config| cmd.run(config.database))
		},
		Some(Subcommand::Inspect(cmd)) => {
			let runner = cli.create_runner(cmd)?;

			runner
				.sync_run(|config| cmd.run::<Block, RuntimeApi, service::ExecutorDispatch>(config))
		},
		Some(Subcommand::Benchmark(cmd)) => {
			let runner = cli.create_runner(cmd)?;

			runner.sync_run(|config| {
				let PartialComponents { client, backend, .. } =
					service::new_partial(&config, &cli)?;

				// This switch needs to be in the client, since the client decides
				// which sub-commands it wants to support.
				match cmd {
					BenchmarkCmd::Pallet(cmd) => {
						if !cfg!(feature = "runtime-benchmarks") {
							return Err(
								"Runtime benchmarking wasn't enabled when building the node. \
							You can enable it with `--features runtime-benchmarks`."
									.into(),
							)
						}

						cmd.run::<Block, service::ExecutorDispatch>(config)
					},
					BenchmarkCmd::Block(cmd) => cmd.run(client),
					BenchmarkCmd::Storage(cmd) => {
						let db = backend.expose_db();
						let storage = backend.expose_storage();

						cmd.run(config, client, db, storage)
					},
					BenchmarkCmd::Overhead(cmd) => {
						let ext_builder = BenchmarkExtrinsicBuilder::new(client.clone());

						cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder))
					},
				}
			})
		},
		Some(Subcommand::Revert(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, backend, .. } =
					service::new_partial(&config, &cli)?;
				let aux_revert = Box::new(move |client, _, blocks| {
					sc_finality_grandpa::revert(client, blocks)?;
					Ok(())
				});
				Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
			})
		},
		None => {
			let runner = cli.create_runner(&cli.run.base)?;
			runner.run_node_until_exit(|config| async move {
				service::new_full(config, &cli).map_err(sc_cli::Error::Service)
			})
		},
	}
}
/// Parse and run command line arguments
Parse and run command line arguments
Parse and run command line arguments
pub fn run() -> sc_cli::Result<()> {
	let cli = Cli::from_args();
	match &cli.subcommand {
		Some(Subcommand::Key(cmd)) => cmd.run(&cli),
		Some(Subcommand::BuildSpec(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
		},
		Some(Subcommand::CheckBlock(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, import_queue, .. } =
					service::new_partial(&config, &cli)?;
				Ok((cmd.run(client, import_queue), task_manager))
			})
		},
		Some(Subcommand::ExportBlocks(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, .. } =
					service::new_partial(&config, &cli)?;
				Ok((cmd.run(client, config.database), task_manager))
			})
		},
		Some(Subcommand::ExportState(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, .. } =
					service::new_partial(&config, &cli)?;
				Ok((cmd.run(client, config.chain_spec), task_manager))
			})
		},
		Some(Subcommand::ImportBlocks(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, import_queue, .. } =
					service::new_partial(&config, &cli)?;
				Ok((cmd.run(client, import_queue), task_manager))
			})
		},
		Some(Subcommand::PurgeChain(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.sync_run(|config| cmd.run(config.database))
		},
		Some(Subcommand::Inspect(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner
				.sync_run(|config| cmd.run::<Block, RuntimeApi, service::ExecutorDispatch>(config))
		},
		Some(Subcommand::Benchmark(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.sync_run(|config| {
				let PartialComponents { client, backend, .. } =
					service::new_partial(&config, &cli)?;
				// This switch needs to be in the client, since the client decides
				// which sub-commands it wants to support.
				match cmd {
					BenchmarkCmd::Pallet(cmd) => {
						if !cfg!(feature = "runtime-benchmarks") {
							return Err(
								"Runtime benchmarking wasn't enabled when building the node. \
							You can enable it with `--features runtime-benchmarks`."
									.into(),
							)
						}
						cmd.run::<Block, service::ExecutorDispatch>(config)
					},
					BenchmarkCmd::Block(cmd) => cmd.run(client),
					BenchmarkCmd::Storage(cmd) => {
						let db = backend.expose_db();
						let storage = backend.expose_storage();
						cmd.run(config, client, db, storage)
					},
					BenchmarkCmd::Overhead(cmd) => {
						let ext_builder = BenchmarkExtrinsicBuilder::new(client.clone());
						cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder))
					},
				}
			})
		},
		Some(Subcommand::Revert(cmd)) => {
			let runner = cli.create_runner(cmd)?;
			runner.async_run(|config| {
				let PartialComponents { client, task_manager, backend, .. } =
					service::new_partial(&config, &cli)?;
				let aux_revert = Box::new(move |client, _, blocks| {
					sc_finality_grandpa::revert(client, blocks)?;
					Ok(())
				});
				Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
			})
		},
		None => {
			let runner = cli.create_runner(&cli.run.base)?;
			runner.run_node_until_exit(|config| async move {
				service::new_full(config, &cli).map_err(sc_cli::Error::Service)
			})
		},
	}
}
pub fn run ( ) -> sc_cli :: Result < ( ) > { let cli = Cli :: from_args ( ) ; match & cli . subcommand { Some ( Subcommand :: Key ( cmd ) ) => cmd . run ( & cli ) , Some ( Subcommand :: BuildSpec ( cmd ) ) => { let runner = cli . create_runner ( cmd ) ? ; runner . sync_run ( | config | cmd . run ( config . chain_spec , config . network ) ) } , Some ( Subcommand :: CheckBlock ( cmd ) ) => { let runner = cli . create_runner ( cmd ) ? ; runner . async_run ( | config | { let PartialComponents { client , task_manager , import_queue , .. } = service :: new_partial ( & config , & cli ) ? ; Ok ( ( cmd . run ( client , import_queue ) , task_manager ) ) } ) } , Some ( Subcommand :: ExportBlocks ( cmd ) ) => { let runner = cli . create_runner ( cmd ) ? ; runner . async_run ( | config | { let PartialComponents { client , task_manager , .. } = service :: new_partial ( & config , & cli ) ? ; Ok ( ( cmd . run ( client , config . database ) , task_manager ) ) } ) } , Some ( Subcommand :: ExportState ( cmd ) ) => { let runner = cli . create_runner ( cmd ) ? ; runner . async_run ( | config | { let PartialComponents { client , task_manager , .. } = service :: new_partial ( & config , & cli ) ? ; Ok ( ( cmd . run ( client , config . chain_spec ) , task_manager ) ) } ) } , Some ( Subcommand :: ImportBlocks ( cmd ) ) => { let runner = cli . create_runner ( cmd ) ? ; runner . async_run ( | config | { let PartialComponents { client , task_manager , import_queue , .. } = service :: new_partial ( & config , & cli ) ? ; Ok ( ( cmd . run ( client , import_queue ) , task_manager ) ) } ) } , Some ( Subcommand :: PurgeChain ( cmd ) ) => { let runner = cli . create_runner ( cmd ) ? ; runner . sync_run ( | config | cmd . run ( config . database ) ) } , Some ( Subcommand :: Inspect ( cmd ) ) => { let runner = cli . create_runner ( cmd ) ? ; runner . sync_run ( | config | cmd . run :: < Block , RuntimeApi , service :: ExecutorDispatch > ( config ) ) } , Some ( Subcommand :: Benchmark ( cmd ) ) => { let runner = cli . create_runner ( cmd ) ? ; runner . sync_run ( | config | { let PartialComponents { client , backend , .. } = service :: new_partial ( & config , & cli ) ? ; // This switch needs to be in the client, since the client decides // which sub-commands it wants to support. match cmd { BenchmarkCmd :: Pallet ( cmd ) => { if ! cfg ! ( feature " " ) { return Err ( " \
 " . into ( ) , ) } cmd . run :: < Block , service :: ExecutorDispatch > ( config ) } , BenchmarkCmd :: Block ( cmd ) => cmd . run ( client ) , BenchmarkCmd :: Storage ( cmd ) => { let db = backend . expose_db ( ) ; let storage = backend . expose_storage ( ) ; cmd . run ( config , client , db , storage ) } , BenchmarkCmd :: Overhead ( cmd ) => { let ext_builder = BenchmarkExtrinsicBuilder :: new ( client . clone ( ) ) ; cmd . run ( config , client , inherent_benchmark_data ( ) ? , Arc :: new ( ext_builder ) ) } , } } ) } , Some ( Subcommand :: Revert ( cmd ) ) => { let runner = cli . create_runner ( cmd ) ? ; runner . async_run ( | config | { let PartialComponents { client , task_manager , backend , .. } = service :: new_partial ( & config , & cli ) ? ; let aux_revert = Box :: new ( move | client , _ , blocks | { sc_finality_grandpa :: revert ( client , blocks ) ? ; Ok ( ( ) ) } ) ; Ok ( ( cmd . run ( client , backend , Some ( aux_revert ) ) , task_manager ) ) } ) } , None => { let runner = cli . create_runner ( & cli . run . base ) ? ; runner . run_node_until_exit ( | config | async move { service :: new_full ( config , & cli ) . map_err ( sc_cli :: Error :: Service ) } ) } , } }
Parse and run command line arguments
Parse and run command line arguments