Skip to content

Commit a8dd7c1

Browse files
committed
WIP - Start moving Clap code to a crate for clap-markdown to be run as an xtask.
1 parent ea2a9b5 commit a8dd7c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+878
-735
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ name = "weaver"
7171

7272
[dependencies]
7373
# local crates dependencies
74+
weaver_cli = { path = "crates/weaver_cli" }
7475
weaver_common = { path = "crates/weaver_common" }
7576
weaver_resolver = { path = "crates/weaver_resolver" }
7677
weaver_semconv = { path = "crates/weaver_semconv" }
@@ -83,7 +84,6 @@ weaver_live_check = { path = "crates/weaver_live_check" }
8384

8485
clap = { version = "4.5.37", features = ["derive"] }
8586
clap_complete = "4.5.48"
86-
clap-markdown = "0.1.5"
8787
rayon = "1.10.0"
8888
ratatui = { version = "0.29.0", features = ["serde"] }
8989
tui-textarea = "0.7.0"

crates/weaver_cli/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "weaver_cli"
3+
version.workspace = true
4+
authors.workspace = true
5+
repository.workspace = true
6+
license.workspace = true
7+
publish.workspace = true
8+
edition.workspace = true
9+
rust-version.workspace = true
10+
11+
[dependencies]
12+
clap = { version = "4.5.37", features = ["derive"] }
13+
clap_complete = "4.5.50"
14+
#serde_yaml = "0.9.34"
15+
weaver_common = { path = "../weaver_common" }
16+
weaver_emit = { path = "../weaver_emit" }
17+
serde_yaml = "0.9.34+deprecated"
18+
thiserror = "1.0.69"
19+
serde = { version = "1.0.219", features = ["derive"] }
20+
miette = { version = "7.5.0", features = ["fancy", "serde"] }
21+
22+
[lints]
23+
workspace = true

crates/weaver_cli/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Weaver CLI
2+
3+
This crate is used to isolate the CLI code from the rest of the weaver codebase. This is so we can generate the markdown
4+
help, as well as the man page file without having to build that into the weaver binary.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
# This is used with cargo-check-external-types to reduce the surface area of downstream crates from
4+
# the public API. Ideally this can have a few exceptions as possible.
5+
allowed_external_types = [
6+
7+
]

src/cli.rs renamed to crates/weaver_cli/src/cli.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ use crate::diagnostic::DiagnosticCommand;
66
use crate::registry::RegistryCommand;
77
use clap::{Args, Parser, Subcommand};
88

9-
/// Command line arguments.
9+
/// Manage semantic convention registry and telemetry schema workflows (OpenTelemetry Project)
1010
#[derive(Parser)]
1111
#[command(
1212
author,
1313
version,
1414
about,
1515
long_about = None,
1616
subcommand_required = true,
17-
arg_required_else_help = true
17+
arg_required_else_help = true,
18+
bin_name = "weaver"
1819
)]
1920
pub struct Cli {
2021
/// Turn debugging information on
@@ -46,11 +47,9 @@ pub enum Commands {
4647
Diagnostic(DiagnosticCommand),
4748
/// Generate shell completions
4849
Completion(CompletionCommand),
49-
/// Generate markdown documentation (hidden)
50-
#[command(hide = true)]
51-
Markdown(MarkdownCommand),
5250
}
5351

52+
/// Commands for generating completions and markdown documentation
5453
#[derive(Args)]
5554
pub struct CompletionCommand {
5655
/// The shell to generate the completions for
@@ -61,10 +60,3 @@ pub struct CompletionCommand {
6160
#[arg(long, hide = true)]
6261
pub completion_file: Option<std::path::PathBuf>,
6362
}
64-
65-
#[derive(Args)]
66-
pub struct MarkdownCommand {
67-
/// The file to write the markdown documentation to. Defaults to `STDOUT`.
68-
#[arg(long)]
69-
pub output_file: Option<std::path::PathBuf>,
70-
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
//! Module for diagnostic init sub-command.
4+
5+
use crate::DiagnosticArgs;
6+
use clap::Args;
7+
use std::path::PathBuf;
8+
9+
/// Parameters for the `diagnostic init` sub-command
10+
#[derive(Debug, Args)]
11+
pub struct DiagnosticInitArgs {
12+
/// Optional target to initialize the diagnostic templates for. If empty, all default templates will be extracted.
13+
#[arg(default_value = "")]
14+
pub target: String,
15+
16+
/// Optional path where the diagnostic templates directory should be created.
17+
#[arg(short = 't', long, default_value = "diagnostic_templates")]
18+
pub diagnostic_templates_dir: PathBuf,
19+
20+
/// Parameters to specify the diagnostic format.
21+
#[command(flatten)]
22+
pub diagnostic: DiagnosticArgs,
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
//! The weaver CLI diagnostic command module
4+
5+
pub mod init;
6+
7+
use clap::{Args, Subcommand};
8+
9+
/// Parameters for the `diagnostic` command
10+
#[derive(Debug, Args)]
11+
pub struct DiagnosticCommand {
12+
/// Define the sub-commands for the `diagnostic` command
13+
#[clap(subcommand)]
14+
pub command: DiagnosticSubCommand,
15+
}
16+
17+
/// Sub-commands to manage `diagnostic` messages.
18+
#[derive(Debug, Subcommand)]
19+
#[clap(verbatim_doc_comment)]
20+
pub enum DiagnosticSubCommand {
21+
/// Initializes a `diagnostic_templates` directory to define or override diagnostic output
22+
/// formats.
23+
Init(init::DiagnosticInitArgs),
24+
}

crates/weaver_cli/src/format.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
//! Supported output formats for the resolved registry and telemetry schema
4+
5+
use clap::ValueEnum;
6+
7+
/// Supported output formats for the resolved schema
8+
#[derive(Debug, Clone, ValueEnum)]
9+
pub enum Format {
10+
/// YAML format
11+
Yaml,
12+
/// JSON format
13+
Json,
14+
}

crates/weaver_cli/src/lib.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
//! Weaver command and subcommands
4+
5+
use clap::Args;
6+
use std::path::PathBuf;
7+
8+
pub mod cli;
9+
pub mod diagnostic;
10+
pub mod format;
11+
pub mod registry;
12+
13+
/// Set of parameters used to specify the diagnostic format.
14+
#[derive(Args, Debug, Clone)]
15+
pub struct DiagnosticArgs {
16+
/// Format used to render the diagnostic messages. Predefined formats are: `ansi`, `json`,
17+
/// `gh_workflow_command`.
18+
#[arg(long, default_value = "ansi")]
19+
pub diagnostic_format: String,
20+
21+
/// Path to the directory where the diagnostic templates are located.
22+
#[arg(long, default_value = "diagnostic_templates")]
23+
pub diagnostic_template: PathBuf,
24+
25+
/// Send the output to stdout instead of stderr.
26+
#[arg(long)]
27+
pub diagnostic_stdout: bool,
28+
}
29+
30+
impl Default for DiagnosticArgs {
31+
fn default() -> Self {
32+
Self {
33+
diagnostic_format: "ansi".to_owned(),
34+
diagnostic_template: PathBuf::from("diagnostic_templates"),
35+
diagnostic_stdout: false,
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)