-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathcli.rs
92 lines (68 loc) · 2.49 KB
/
cli.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// KILT Blockchain – <https://kilt.io>
// Copyright (C) 2025, KILT Foundation
// The KILT Blockchain 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.
// The KILT Blockchain 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 this program. If not, see <https://www.gnu.org/licenses/>.
// If you feel like getting in touch with us, you can do so at <hello@kilt.io>
use std::path::PathBuf;
use cumulus_client_cli::{ExportGenesisHeadCommand, ExportGenesisWasmCommand, PurgeChainCmd};
use polkadot_cli::RunCmd;
use sc_cli::{BuildSpecCmd, CheckBlockCmd, ExportBlocksCmd, ExportStateCmd, ImportBlocksCmd, RevertCmd};
use sc_service::Configuration;
use crate::chain_spec::Extensions;
#[allow(clippy::large_enum_variant)]
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
BuildSpec(BuildSpecCmd),
CheckBlock(CheckBlockCmd),
ExportBlocks(ExportBlocksCmd),
ExportState(ExportStateCmd),
ImportBlocks(ImportBlocksCmd),
Revert(RevertCmd),
PurgeChain(PurgeChainCmd),
ExportGenesisState(ExportGenesisHeadCommand),
ExportGenesisWasm(ExportGenesisWasmCommand),
#[command(subcommand)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
}
#[derive(Debug, clap::Parser)]
#[command(
propagate_version = true,
args_conflicts_with_subcommands = true,
subcommand_negates_reqs = true
)]
pub struct Cli {
#[command(subcommand)]
pub subcommand: Option<Subcommand>,
#[command(flatten)]
pub run: cumulus_client_cli::RunCmd,
#[arg(long)]
pub no_hardware_benchmarks: bool,
#[arg(raw = true)]
pub relay_chain_args: Vec<String>,
}
#[derive(Debug)]
pub struct RelayChainCli {
pub base: RunCmd,
pub chain_id: Option<String>,
pub base_path: Option<PathBuf>,
}
impl RelayChainCli {
pub fn new<'a>(para_config: &Configuration, relay_chain_args: impl Iterator<Item = &'a String>) -> Self {
let extension = Extensions::try_get(&*para_config.chain_spec);
let chain_id = extension.map(|e| e.relay_chain.clone());
let base_path = Some(para_config.base_path.path().join("polkadot"));
Self {
base_path,
chain_id,
base: clap::Parser::parse_from(relay_chain_args),
}
}
}