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, cli::Subcommand, service::Sealing},
20
    url::Url,
21
};
22

            
23
pub type SimpleSubcommand = Subcommand<BuildSpecCmdSimple>;
24

            
25
#[derive(Debug, Parser)]
26
#[group(skip)]
27
pub struct RunCmd {
28
    #[clap(flatten)]
29
    pub base: cumulus_client_cli::RunCmd,
30

            
31
    /// Id of the parachain this collator collates for.
32
    #[arg(long)]
33
    pub parachain_id: Option<u32>,
34

            
35
    /// When blocks should be sealed in the dev service.
36
    ///
37
    /// Options are "instant", "manual", or timer interval in milliseconds
38
    #[arg(long, default_value = "instant")]
39
    pub sealing: Sealing,
40
}
41

            
42
impl std::ops::Deref for RunCmd {
43
    type Target = cumulus_client_cli::RunCmd;
44

            
45
132
    fn deref(&self) -> &Self::Target {
46
132
        &self.base
47
132
    }
48
}
49

            
50
#[derive(Debug, clap::Parser)]
51
#[command(
52
    propagate_version = true,
53
    args_conflicts_with_subcommands = true,
54
    subcommand_negates_reqs = true
55
)]
56
pub struct Cli {
57
    #[command(subcommand)]
58
    pub subcommand: Option<SimpleSubcommand>,
59

            
60
    #[command(flatten)]
61
    pub run: RunCmd,
62

            
63
    /// Disable automatic hardware benchmarks.
64
    ///
65
    /// By default these benchmarks are automatically ran at startup and measure
66
    /// the CPU speed, the memory bandwidth and the disk speed.
67
    ///
68
    /// The results are then printed out in the logs, and also sent as part of
69
    /// telemetry, if telemetry is enabled.
70
    #[arg(long)]
71
    pub no_hardware_benchmarks: bool,
72

            
73
    /// Optional parachain id that should be used to build chain spec.
74
    #[arg(long)]
75
    pub para_id: Option<u32>,
76

            
77
    /// Profile id associated with the node, whose assignements will be followed to provide RPC services.
78
    #[arg(long)]
79
    pub rpc_provider_profile_id: Option<u64>,
80

            
81
    /// Endpoints to connect to orchestrator nodes, avoiding to start a local orchestrator node.
82
    /// If this list is empty, a local embeded orchestrator node is started.
83
    #[arg(long)]
84
    pub orchestrator_endpoints: Vec<Url>,
85

            
86
    /// Relay chain arguments, optionally followed by "--" and container chain arguments
87
    #[arg(raw = true)]
88
    extra_args: Vec<String>,
89
}
90

            
91
impl Cli {
92
66
    pub fn relaychain_args(&self) -> &[String] {
93
66
        let (relay_chain_args, _) = self.split_extra_args_at_first_dashdash();
94
66

            
95
66
        relay_chain_args
96
66
    }
97

            
98
    pub fn container_chain_args(&self) -> &[String] {
99
        let (_, container_chain_args) = self.split_extra_args_at_first_dashdash();
100

            
101
        container_chain_args
102
    }
103

            
104
66
    fn split_extra_args_at_first_dashdash(&self) -> (&[String], &[String]) {
105
66
        let index_of_dashdash = self.extra_args.iter().position(|x| *x == "--");
106

            
107
66
        if let Some(i) = index_of_dashdash {
108
            let (container_chain_args, extra_extra) = self.extra_args.split_at(i);
109
            (&extra_extra[1..], container_chain_args)
110
        } else {
111
            // Only relay chain args
112
66
            (&self.extra_args, &[])
113
        }
114
66
    }
115
}
116

            
117
#[derive(Debug, Clone, clap::Args)]
118
pub struct BuildSpecCmdExtraFields {
119
    /// List of bootnodes to add to chain spec
120
    #[arg(long)]
121
    pub add_bootnode: Vec<String>,
122

            
123
    /// Id of the parachain this spec is for. Note that this overrides the `--chain` param.
124
    #[arg(long, conflicts_with = "chain")]
125
    #[arg(long)]
126
    pub parachain_id: Option<u32>,
127
}
128

            
129
pub type BuildSpecCmdSimple = BuildSpecCmd<BuildSpecCmdExtraFields>;