1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi 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.
8

            
9
// Tanssi 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.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
use {
18
    clap::Parser,
19
    node_common::{
20
        cli::{BuildSpecCmd, ExportChainSpecCmd},
21
        service::node_builder::Sealing,
22
    },
23
    tc_service_container_chain_data_preserver::DataPreserverCmd,
24
};
25

            
26
pub type BaseSubcommand =
27
    node_common::cli::Subcommand<BuildSpecCmdSimple, ExportChainSpecCmdSimple>;
28

            
29
/// Custom subcommand enum with `rpc-provider`
30
#[derive(Debug, clap::Subcommand)]
31
#[allow(clippy::large_enum_variant)]
32
pub enum Subcommand {
33
    DataPreserver(DataPreserverCmd),
34
    #[command(flatten)]
35
    Base(BaseSubcommand),
36
}
37

            
38
#[derive(Debug, Parser)]
39
#[group(skip)]
40
pub struct RunCmd {
41
    #[clap(flatten)]
42
    pub base: cumulus_client_cli::RunCmd,
43

            
44
    /// Id of the parachain this collator collates for.
45
    #[arg(long)]
46
    pub parachain_id: Option<u32>,
47

            
48
    /// When blocks should be sealed in the dev service.
49
    ///
50
    /// Options are "instant", "manual", or timer interval in milliseconds
51
    #[arg(long, default_value = "instant")]
52
    pub sealing: Sealing,
53
}
54

            
55
impl std::ops::Deref for RunCmd {
56
    type Target = cumulus_client_cli::RunCmd;
57

            
58
160
    fn deref(&self) -> &Self::Target {
59
160
        &self.base
60
160
    }
61
}
62

            
63
#[derive(Debug, clap::Parser)]
64
#[command(
65
    propagate_version = true,
66
    args_conflicts_with_subcommands = true,
67
    subcommand_negates_reqs = true
68
)]
69
pub struct Cli {
70
    #[command(subcommand)]
71
    pub subcommand: Option<Subcommand>,
72

            
73
    // ===== WARNING =====
74
    // The following arguments are only parsed if `subcommand` is `None`. They
75
    // get default values when a subcommand is used!
76
    // TODO: Fix usage of those wrong values in subcommands.
77
    // SEE: https://github.com/paritytech/polkadot-sdk/issues/9356
78
    #[command(flatten)]
79
    pub run: RunCmd,
80

            
81
    /// Disable automatic hardware benchmarks.
82
    ///
83
    /// By default these benchmarks are automatically ran at startup and measure
84
    /// the CPU speed, the memory bandwidth and the disk speed.
85
    ///
86
    /// The results are then printed out in the logs, and also sent as part of
87
    /// telemetry, if telemetry is enabled.
88
    #[arg(long)]
89
    pub no_hardware_benchmarks: bool,
90

            
91
    /// Optional parachain id that should be used to build chain spec.
92
    #[arg(long)]
93
    pub para_id: Option<u32>,
94

            
95
    /// Relay chain arguments
96
    #[arg(raw = true)]
97
    pub relay_chain_args: Vec<String>,
98
}
99

            
100
#[derive(Debug, Clone, clap::Args)]
101
pub struct ExtraFields {
102
    /// List of bootnodes to add to chain spec
103
    #[arg(long)]
104
    pub add_bootnode: Vec<String>,
105

            
106
    /// Id of the parachain this spec is for. Note that this overrides the `--chain` param.
107
    #[arg(long, conflicts_with = "chain")]
108
    #[arg(long)]
109
    pub parachain_id: Option<u32>,
110
}
111

            
112
pub type BuildSpecCmdSimple = BuildSpecCmd<ExtraFields>;
113

            
114
pub type ExportChainSpecCmdSimple = ExportChainSpecCmd<ExtraFields>;