referrerpolicy=no-referrer-when-downgrade

sc_cli/params/
shared_params.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19use crate::arg_enums::TracingReceiver;
20use clap::Args;
21use sc_service::config::BasePath;
22use std::path::PathBuf;
23
24/// Shared parameters used by all `CoreParams`.
25#[derive(Debug, Clone, Args)]
26pub struct SharedParams {
27	/// Specify the chain specification.
28	///
29	/// It can be one of the predefined ones (dev, local, or staging) or it can be a path to
30	/// a file with the chainspec (such as one exported by a node's chain specification export
31	/// subcommand).
32	#[arg(long, value_name = "CHAIN_SPEC")]
33	pub chain: Option<String>,
34
35	/// Specify the development chain.
36	///
37	/// This flag sets `--chain=dev`, `--force-authoring`, `--rpc-cors=all`, `--alice`, and `--tmp`
38	/// flags, unless explicitly overridden. It also disables local peer discovery (see `--no-mdns`
39	/// and `--discover-local`). With this flag some nodes might start with manual seal, producing
40	/// blocks at certain events (e.g. `polkadot-omni-node`, which produces blocks at certain
41	/// intervals dictated by `--dev-block-time`).
42	#[arg(long)]
43	pub dev: bool,
44
45	/// Specify custom base path.
46	#[arg(long, short = 'd', value_name = "PATH")]
47	pub base_path: Option<PathBuf>,
48
49	/// Sets a custom logging filter (syntax: `<target>=<level>`).
50	///
51	/// Log levels (least to most verbose) are `error`, `warn`, `info`, `debug`, and `trace`.
52	///
53	/// By default, all targets log `info`. The global log level can be set with `-l<level>`.
54	///
55	/// Multiple `<target>=<level>` entries can be specified and separated by a comma.
56	///
57	/// *Example*: `--log error,sync=debug,grandpa=warn`.
58	/// Sets Global log level to `error`, sets `sync` target to debug and grandpa target to `warn`.
59	#[arg(short = 'l', long, value_name = "LOG_PATTERN", num_args = 1..)]
60	pub log: Vec<String>,
61
62	/// Enable detailed log output.
63	///
64	/// Includes displaying the log target, log level and thread name.
65	///
66	/// This is automatically enabled when something is logged with any higher level than `info`.
67	#[arg(long)]
68	pub detailed_log_output: bool,
69
70	/// Disable log color output.
71	#[arg(long)]
72	pub disable_log_color: bool,
73
74	/// Enable feature to dynamically update and reload the log filter.
75	///
76	/// Be aware that enabling this feature can lead to a performance decrease up to factor six or
77	/// more. Depending on the global logging level the performance decrease changes.
78	///
79	/// The `system_addLogFilter` and `system_resetLogFilter` RPCs will have no effect with this
80	/// option not being set.
81	#[arg(long)]
82	pub enable_log_reloading: bool,
83
84	/// Sets a custom profiling filter.
85	///
86	/// Syntax is the same as for logging (`--log`).
87	#[arg(long, value_name = "TARGETS")]
88	pub tracing_targets: Option<String>,
89
90	/// Receiver to process tracing messages.
91	#[arg(long, value_name = "RECEIVER", value_enum, ignore_case = true, default_value_t = TracingReceiver::Log)]
92	pub tracing_receiver: TracingReceiver,
93}
94
95impl SharedParams {
96	/// Specify custom base path.
97	pub fn base_path(&self) -> Result<Option<BasePath>, crate::Error> {
98		match &self.base_path {
99			Some(r) => Ok(Some(r.clone().into())),
100			// If `dev` is enabled, we use the temp base path.
101			None if self.is_dev() => Ok(Some(BasePath::new_temp_dir()?)),
102			None => Ok(None),
103		}
104	}
105
106	/// Specify the development chain.
107	pub fn is_dev(&self) -> bool {
108		self.dev
109	}
110
111	/// Get the chain spec for the parameters provided
112	pub fn chain_id(&self, is_dev: bool) -> String {
113		match self.chain {
114			Some(ref chain) => chain.clone(),
115			None if is_dev => "dev".into(),
116			_ => "".into(),
117		}
118	}
119
120	/// Get the filters for the logging
121	pub fn log_filters(&self) -> &[String] {
122		&self.log
123	}
124
125	/// Should the detailed log output be enabled.
126	pub fn detailed_log_output(&self) -> bool {
127		self.detailed_log_output
128	}
129
130	/// Should the log color output be disabled?
131	pub fn disable_log_color(&self) -> bool {
132		self.disable_log_color
133	}
134
135	/// Is log reloading enabled
136	pub fn enable_log_reloading(&self) -> bool {
137		self.enable_log_reloading
138	}
139
140	/// Receiver to process tracing messages.
141	pub fn tracing_receiver(&self) -> sc_service::TracingReceiver {
142		self.tracing_receiver.into()
143	}
144
145	/// Comma separated list of targets for tracing.
146	pub fn tracing_targets(&self) -> Option<String> {
147		self.tracing_targets.clone()
148	}
149}