Skip to content

Commit 9eb6467

Browse files
authored
Merge pull request #1424 from sfauvel/sfa/command-line-doc
Generate documentation on module command lines
2 parents 1c37f60 + 3d9eff3 commit 9eb6467

File tree

28 files changed

+1550
-102
lines changed

28 files changed

+1550
-102
lines changed

Cargo.lock

Lines changed: 30 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ members = [
1212
"mithril-client-cli",
1313
"mithril-client-wasm",
1414
"mithril-common",
15+
"mithril-doc",
16+
"mithril-doc-derive",
1517
"mithril-persistence",
1618
"mithril-relay",
1719
"mithril-signer",

demo/protocol-demo/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithrildemo"
3-
version = "0.1.29"
3+
version = "0.1.30"
44
authors = { workspace = true }
55
edition = { workspace = true }
66
documentation = { workspace = true }
@@ -15,6 +15,7 @@ clap = { version = "4.4.18", features = ["derive"] }
1515
hex = "0.4.3"
1616
log = "0.4.20"
1717
mithril-common = { path = "../../mithril-common", features = ["fs"] }
18+
mithril-doc = { path = "../../mithril-doc" }
1819
rand_chacha = "0.3.1"
1920
rand_core = "0.6.4"
2021
serde = { version = "1.0.196", features = ["derive"] }

demo/protocol-demo/src/demonstrator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl Demonstrator {
316316
})
317317
.collect::<Vec<Vec<u8>>>();
318318
Self {
319-
config: *config,
319+
config: config.clone(),
320320
parties,
321321
verifier: None,
322322
messages,
@@ -495,6 +495,7 @@ mod tests {
495495
fn default_config() -> crate::Config {
496496
let protocol_parameters = setup_protocol_parameters();
497497
crate::Config {
498+
command: None,
498499
m: protocol_parameters.m,
499500
k: protocol_parameters.k,
500501
phi_f: protocol_parameters.phi_f,

demo/protocol-demo/src/main.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ mod demonstrator;
22
mod types;
33

44
use crate::demonstrator::{Demonstrator, ProtocolDemonstrator};
5-
use clap::Parser;
5+
use clap::{CommandFactory, Parser, Subcommand};
6+
use mithril_doc::GenerateDocCommands;
67
use rand_chacha::ChaCha20Rng;
78
use rand_core::SeedableRng;
89

910
/// Simple demonstration of the Mithril protocol
10-
#[derive(Parser, Debug, PartialEq, Clone, Copy)]
11+
#[derive(Parser, Debug, PartialEq)]
1112
pub struct Config {
13+
/// Available commands
14+
#[command(subcommand)]
15+
command: Option<DemoCommands>,
16+
1217
/// Security parameter, upper bound on indices
1318
#[clap(short, long, default_value_t = 200)]
1419
m: u64,
@@ -30,9 +35,29 @@ pub struct Config {
3035
nmessages: usize,
3136
}
3237

38+
impl Clone for Config {
39+
fn clone(&self) -> Self {
40+
Config {
41+
command: None,
42+
..*self
43+
}
44+
}
45+
}
46+
47+
#[derive(Subcommand, Debug, PartialEq)]
48+
enum DemoCommands {
49+
#[clap(alias("doc"), hide(true))]
50+
GenerateDoc(GenerateDocCommands),
51+
}
52+
3353
fn main() {
3454
let config = Config::parse();
3555

56+
if let Some(DemoCommands::GenerateDoc(cmd)) = &config.command {
57+
cmd.execute(&mut Config::command()).unwrap();
58+
return;
59+
}
60+
3661
println!(">> Launch Mithril protocol demonstrator with configuration: \n{config:#?}");
3762

3863
//////////////////////

mithril-aggregator/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.4.38"
3+
version = "0.4.39"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -19,6 +19,7 @@ config = "0.13.4"
1919
flate2 = "1.0.28"
2020
hex = "0.4.3"
2121
mithril-common = { path = "../mithril-common", features = ["full"] }
22+
mithril-doc = { path = "../mithril-doc" }
2223
mithril-persistence = { path = "../mithril-persistence" }
2324
openssl = { version = "0.10.63", features = ["vendored"], optional = true }
2425
openssl-probe = { version = "0.1.5", optional = true }

mithril-aggregator/src/commands/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ mod genesis_command;
33
mod serve_command;
44
mod tools_command;
55

6-
use clap::{Parser, Subcommand};
6+
use anyhow::anyhow;
7+
use clap::{CommandFactory, Parser, Subcommand};
78
use config::{builder::DefaultState, ConfigBuilder, Map, Source, Value, ValueKind};
89
use mithril_common::StdResult;
10+
use mithril_doc::{Documenter, DocumenterDefault, StructDoc};
911
use slog::Level;
1012
use slog_scope::debug;
1113
use std::path::PathBuf;
1214

13-
use crate::DefaultConfiguration;
15+
use crate::{Configuration, DefaultConfiguration};
16+
use mithril_doc::GenerateDocCommands;
1417

1518
/// Main command selector
1619
#[derive(Debug, Clone, Subcommand)]
@@ -19,6 +22,8 @@ pub enum MainCommand {
1922
Era(era_command::EraCommand),
2023
Serve(serve_command::ServeCommand),
2124
Tools(tools_command::ToolsCommand),
25+
#[clap(alias("doc"), hide(true))]
26+
GenerateDoc(GenerateDocCommands),
2227
}
2328

2429
impl MainCommand {
@@ -28,12 +33,17 @@ impl MainCommand {
2833
Self::Era(cmd) => cmd.execute(config_builder).await,
2934
Self::Serve(cmd) => cmd.execute(config_builder).await,
3035
Self::Tools(cmd) => cmd.execute(config_builder).await,
36+
Self::GenerateDoc(cmd) => {
37+
let config_infos = vec![Configuration::extract(), DefaultConfiguration::extract()];
38+
cmd.execute_with_configurations(&mut MainOpts::command(), &config_infos)
39+
.map_err(|message| anyhow!(message))
40+
}
3141
}
3242
}
3343
}
3444

3545
/// Mithril Aggregator Node
36-
#[derive(Parser, Debug, Clone)]
46+
#[derive(Documenter, Parser, Debug, Clone)]
3747
#[command(version)]
3848
pub struct MainOpts {
3949
/// application main command
@@ -46,6 +56,7 @@ pub struct MainOpts {
4656

4757
/// Verbosity level
4858
#[clap(short, long, action = clap::ArgAction::Count)]
59+
#[example = "Parsed from the number of occurrences: `-v` for `Warning`, `-vv` for `Info`, `-vvv` for `Debug` and `-vvvv` for `Trace`"]
4960
pub verbose: u8,
5061

5162
/// Directory of the Cardano node files

mithril-aggregator/src/configuration.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use config::{ConfigError, Map, Source, Value, ValueKind};
33
use mithril_common::chain_observer::ChainObserverType;
44
use mithril_common::crypto_helper::ProtocolGenesisSigner;
55
use mithril_common::era::adapters::EraReaderAdapterType;
6+
use mithril_doc::{Documenter, DocumenterDefault, StructDoc};
67
use serde::{Deserialize, Serialize};
78
use std::path::PathBuf;
89
use std::str::FromStr;
@@ -39,16 +40,18 @@ impl FromStr for ExecutionEnvironment {
3940
}
4041

4142
/// Aggregator configuration
42-
#[derive(Debug, Clone, Serialize, Deserialize)]
43+
#[derive(Debug, Clone, Serialize, Deserialize, Documenter)]
4344
pub struct Configuration {
4445
/// What kind of runtime environment the configuration is meant to.
4546
pub environment: ExecutionEnvironment,
4647

4748
/// Cardano CLI tool path
49+
#[example = "`cardano-cli`"]
4850
pub cardano_cli_path: PathBuf,
4951

5052
/// Path of the socket used by the Cardano CLI tool
5153
/// to communicate with the Cardano node
54+
#[example = "`/tmp/cardano.sock`"]
5255
pub cardano_node_socket_path: PathBuf,
5356

5457
/// Cardano node version.
@@ -61,18 +64,22 @@ pub struct Configuration {
6164
/// Cardano Network Magic number
6265
///
6366
/// useful for TestNet & DevNet
67+
#[example = "`1097911063` or `42`"]
6468
pub network_magic: Option<u64>,
6569

6670
/// Cardano network
71+
#[example = "`testnet` or `mainnet` or `devnet`"]
6772
pub network: String,
6873

6974
/// Cardano chain observer type
7075
pub chain_observer_type: ChainObserverType,
7176

7277
/// Protocol parameters
78+
#[example = "`{ k: 5, m: 100, phi_f: 0.65 }`"]
7379
pub protocol_parameters: ProtocolParameters,
7480

7581
/// Type of snapshot uploader to use
82+
#[example = "`gcp` or `local`"]
7683
pub snapshot_uploader_type: SnapshotUploaderType,
7784

7885
/// Bucket name where the snapshots are stored if snapshot_uploader_type is Gcp
@@ -88,6 +95,7 @@ pub struct Configuration {
8895
pub server_port: u16,
8996

9097
/// Run Interval is the interval between two runtime cycles in ms
98+
#[example = "`60000`"]
9199
pub run_interval: u64,
92100

93101
/// Directory of the Cardano node store.
@@ -97,6 +105,7 @@ pub struct Configuration {
97105
pub snapshot_directory: PathBuf,
98106

99107
/// Directory to store aggregator data (Certificates, Snapshots, Protocol Parameters, ...)
108+
#[example = "`./mithril-aggregator/stores`"]
100109
pub data_stores_directory: PathBuf,
101110

102111
/// Genesis verification key
@@ -120,14 +129,17 @@ pub struct Configuration {
120129
/// Era reader adapter parameters
121130
pub era_reader_adapter_params: Option<String>,
122131

123-
/// Signed entity types parameters (discriminants names in an ordered comma separated list).
132+
/// Signed entity types parameters (discriminants names in an ordered comma separated list).
133+
#[example = "`MithrilStakeDistribution,CardanoImmutableFilesFull,CardanoStakeDistribution`"]
124134
pub signed_entity_types: Option<String>,
125135

126136
/// Compression algorithm used for the snapshot archive artifacts.
137+
#[example = "`gzip` or `zstandard`"]
127138
pub snapshot_compression_algorithm: CompressionAlgorithm,
128139

129140
/// Specific parameters when [snapshot_compression_algorithm][Self::snapshot_compression_algorithm]
130141
/// is set to [zstandard][CompressionAlgorithm::Zstandard].
142+
#[example = "`{ level: 9, number_of_workers: 4 }`"]
131143
pub zstandard_parameters: Option<ZstandardCompressionParameters>,
132144

133145
/// Url to CExplorer list of pools to import as signer in the database.
@@ -284,9 +296,8 @@ impl Configuration {
284296
Ok(signed_entity_types)
285297
}
286298
}
287-
288299
/// Default configuration with all the default values for configurations.
289-
#[derive(Debug, Clone)]
300+
#[derive(Debug, Clone, DocumenterDefault)]
290301
pub struct DefaultConfiguration {
291302
/// Execution environment
292303
pub environment: ExecutionEnvironment,
@@ -304,6 +315,7 @@ pub struct DefaultConfiguration {
304315
pub snapshot_directory: String,
305316

306317
/// Type of snapshot store to use
318+
#[example = "`gcp` or `local`"]
307319
pub snapshot_store_type: String,
308320

309321
/// Type of snapshot uploader to use

0 commit comments

Comments
 (0)