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::{cli::BuildSpecCmd, service::node_builder::Sealing},
20
    tc_service_container_chain_data_preserver::DataPreserverCmd,
21
};
22

            
23
pub type BaseSubcommand = node_common::cli::Subcommand<BuildSpecCmdSimple>;
24

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

            
34
#[derive(Debug, Parser)]
35
#[group(skip)]
36
pub struct RunCmd {
37
    #[clap(flatten)]
38
    pub base: cumulus_client_cli::RunCmd,
39

            
40
    /// Id of the parachain this collator collates for.
41
    #[arg(long)]
42
    pub parachain_id: Option<u32>,
43

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

            
51
impl std::ops::Deref for RunCmd {
52
    type Target = cumulus_client_cli::RunCmd;
53

            
54
156
    fn deref(&self) -> &Self::Target {
55
156
        &self.base
56
156
    }
57
}
58

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

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

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

            
87
    /// Optional parachain id that should be used to build chain spec.
88
    #[arg(long)]
89
    pub para_id: Option<u32>,
90

            
91
    /// Relay chain arguments
92
    #[arg(raw = true)]
93
    pub relay_chain_args: Vec<String>,
94
}
95

            
96
#[derive(Debug, Clone, clap::Args)]
97
pub struct BuildSpecCmdExtraFields {
98
    /// List of bootnodes to add to chain spec
99
    #[arg(long)]
100
    pub add_bootnode: Vec<String>,
101

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

            
108
pub type BuildSpecCmdSimple = BuildSpecCmd<BuildSpecCmdExtraFields>;