1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
34// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
89// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
1314// You should have received a copy of the GNU General Public License
15// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1617//! Polkadot CLI library.
1819use clap::Parser;
20use sc_cli::SubstrateCli;
21use std::path::PathBuf;
2223/// Sub-commands supported by the collator.
24#[derive(Debug, Parser)]
25pub enum Subcommand {
26/// Export the genesis state of the parachain.
27#[command(name = "export-genesis-state")]
28ExportGenesisState(ExportGenesisHeadCommand),
2930/// Export the genesis wasm of the parachain.
31#[command(name = "export-genesis-wasm")]
32ExportGenesisWasm(ExportGenesisWasmCommand),
33}
3435/// Command for exporting the genesis head data of the parachain
36#[derive(Debug, Parser)]
37pub struct ExportGenesisHeadCommand {
38/// Output file name or stdout if unspecified.
39#[arg()]
40pub output: Option<PathBuf>,
41}
4243/// Command for exporting the genesis wasm file.
44#[derive(Debug, Parser)]
45pub struct ExportGenesisWasmCommand {
46/// Output file name or stdout if unspecified.
47#[arg()]
48pub output: Option<PathBuf>,
49}
5051#[allow(missing_docs)]
52#[derive(Debug, Parser)]
53#[group(skip)]
54pub struct RunCmd {
55#[allow(missing_docs)]
56 #[clap(flatten)]
57pub base: sc_cli::RunCmd,
5859/// Id of the parachain this collator collates for.
60#[arg(long)]
61pub parachain_id: Option<u32>,
62}
6364#[allow(missing_docs)]
65#[derive(Debug, Parser)]
66pub struct Cli {
67#[command(subcommand)]
68pub subcommand: Option<Subcommand>,
6970#[clap(flatten)]
71pub run: RunCmd,
72}
7374impl SubstrateCli for Cli {
75fn impl_name() -> String {
76"Parity Polkadot".into()
77 }
7879fn impl_version() -> String {
80"0.0.0".into()
81 }
8283fn description() -> String {
84env!("CARGO_PKG_DESCRIPTION").into()
85 }
8687fn author() -> String {
88env!("CARGO_PKG_AUTHORS").into()
89 }
9091fn support_url() -> String {
92"https://github.com/paritytech/polkadot-sdk/issues/new".into()
93 }
9495fn copyright_start_year() -> i32 {
962017
97}
9899fn executable_name() -> String {
100"adder-collator".into()
101 }
102103fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
104let id = if id.is_empty() { "rococo" } else { id };
105Ok(match id {
106"rococo-staging" =>
107 Box::new(polkadot_service::chain_spec::rococo_staging_testnet_config()?),
108"rococo-local" =>
109 Box::new(polkadot_service::chain_spec::rococo_local_testnet_config()?),
110"rococo" => Box::new(polkadot_service::chain_spec::rococo_config()?),
111 path => {
112let path = std::path::PathBuf::from(path);
113 Box::new(polkadot_service::RococoChainSpec::from_json_file(path)?)
114 },
115 })
116 }
117}