Skip to content

Use clap-markdown to produce usage in a markdown file. (WIP) #732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ name = "weaver"

[dependencies]
# local crates dependencies
weaver_cli = { path = "crates/weaver_cli" }
weaver_common = { path = "crates/weaver_common" }
weaver_resolver = { path = "crates/weaver_resolver" }
weaver_semconv = { path = "crates/weaver_semconv" }
Expand All @@ -82,7 +83,7 @@ weaver_emit = { path = "crates/weaver_emit" }
weaver_live_check = { path = "crates/weaver_live_check" }

clap = { version = "4.5.37", features = ["derive"] }
clap_complete = "4.5.47"
clap_complete = "4.5.48"
rayon = "1.10.0"
ratatui = { version = "0.29.0", features = ["serde"] }
tui-textarea = "0.7.0"
Expand Down Expand Up @@ -256,3 +257,4 @@ github-custom-runners = { global="ubuntu-latest", x86_64-unknown-linux-gnu="ubun
#todo = "warn"
#implicit_clone = "warn"
#inconsistent_struct_constructor = "warn"

23 changes: 23 additions & 0 deletions crates/weaver_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "weaver_cli"
version.workspace = true
authors.workspace = true
repository.workspace = true
license.workspace = true
publish.workspace = true
edition.workspace = true
rust-version.workspace = true

[dependencies]
clap = { version = "4.5.37", features = ["derive"] }
clap_complete = "4.5.50"
#serde_yaml = "0.9.34"
weaver_common = { path = "../weaver_common" }
weaver_emit = { path = "../weaver_emit" }
serde_yaml = "0.9.34+deprecated"
thiserror = "1.0.69"
serde = { version = "1.0.219", features = ["derive"] }
miette = { version = "7.5.0", features = ["fancy", "serde"] }

[lints]
workspace = true
4 changes: 4 additions & 0 deletions crates/weaver_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Weaver CLI

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

]
8 changes: 5 additions & 3 deletions src/cli.rs → crates/weaver_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ use crate::diagnostic::DiagnosticCommand;
use crate::registry::RegistryCommand;
use clap::{Args, Parser, Subcommand};

/// Command line arguments.
/// Manage semantic convention registry and telemetry schema workflows (OpenTelemetry Project)
#[derive(Parser)]
#[command(
author,
version,
about,
long_about = None,
subcommand_required = true,
arg_required_else_help = true
arg_required_else_help = true,
bin_name = "weaver"
)]
pub struct Cli {
/// Turn debugging information on
Expand Down Expand Up @@ -48,13 +49,14 @@ pub enum Commands {
Completion(CompletionCommand),
}

/// Commands for generating completions and markdown documentation
#[derive(Args)]
pub struct CompletionCommand {
/// The shell to generate the completions for
#[arg(value_enum)]
pub shell: clap_complete::Shell,

/// (Optional) The file to write the completions to. Defaults to STDOUT.
/// (Optional) The file to write the completions to. Defaults to `STDOUT`.
#[arg(long, hide = true)]
pub completion_file: Option<std::path::PathBuf>,
}
23 changes: 23 additions & 0 deletions crates/weaver_cli/src/diagnostic/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0

//! Module for diagnostic init sub-command.

use crate::DiagnosticArgs;
use clap::Args;
use std::path::PathBuf;

/// Parameters for the `diagnostic init` sub-command
#[derive(Debug, Args)]
pub struct DiagnosticInitArgs {
/// Optional target to initialize the diagnostic templates for. If empty, all default templates will be extracted.
#[arg(default_value = "")]
pub target: String,

/// Optional path where the diagnostic templates directory should be created.
#[arg(short = 't', long, default_value = "diagnostic_templates")]
pub diagnostic_templates_dir: PathBuf,

/// Parameters to specify the diagnostic format.
#[command(flatten)]
pub diagnostic: DiagnosticArgs,
}
24 changes: 24 additions & 0 deletions crates/weaver_cli/src/diagnostic/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0

//! The weaver CLI diagnostic command module

pub mod init;

use clap::{Args, Subcommand};

/// Parameters for the `diagnostic` command
#[derive(Debug, Args)]
pub struct DiagnosticCommand {
/// Define the sub-commands for the `diagnostic` command
#[clap(subcommand)]
pub command: DiagnosticSubCommand,
}

/// Sub-commands to manage `diagnostic` messages.
#[derive(Debug, Subcommand)]
#[clap(verbatim_doc_comment)]
pub enum DiagnosticSubCommand {
/// Initializes a `diagnostic_templates` directory to define or override diagnostic output
/// formats.
Init(init::DiagnosticInitArgs),
}
14 changes: 14 additions & 0 deletions crates/weaver_cli/src/format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0

//! Supported output formats for the resolved registry and telemetry schema

use clap::ValueEnum;

/// Supported output formats for the resolved schema
#[derive(Debug, Clone, ValueEnum)]
pub enum Format {
/// YAML format
Yaml,
/// JSON format
Json,
}
38 changes: 38 additions & 0 deletions crates/weaver_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: Apache-2.0

//! Weaver command and subcommands

use clap::Args;
use std::path::PathBuf;

pub mod cli;
pub mod diagnostic;
pub mod format;
pub mod registry;

/// Set of parameters used to specify the diagnostic format.
#[derive(Args, Debug, Clone)]
pub struct DiagnosticArgs {
/// Format used to render the diagnostic messages. Predefined formats are: `ansi`, `json`,
/// `gh_workflow_command`.
#[arg(long, default_value = "ansi")]
pub diagnostic_format: String,

/// Path to the directory where the diagnostic templates are located.
#[arg(long, default_value = "diagnostic_templates")]
pub diagnostic_template: PathBuf,

/// Send the output to stdout instead of stderr.
#[arg(long)]
pub diagnostic_stdout: bool,
}

impl Default for DiagnosticArgs {
fn default() -> Self {

Check warning on line 31 in crates/weaver_cli/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/weaver_cli/src/lib.rs#L31

Added line #L31 was not covered by tests
Self {
diagnostic_format: "ansi".to_owned(),
diagnostic_template: PathBuf::from("diagnostic_templates"),

Check warning on line 34 in crates/weaver_cli/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/weaver_cli/src/lib.rs#L33-L34

Added lines #L33 - L34 were not covered by tests
diagnostic_stdout: false,
}
}
}
28 changes: 28 additions & 0 deletions crates/weaver_cli/src/registry/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0

//! Weaver registry check sub-command.

use crate::registry::{PolicyArgs, RegistryArgs};
use crate::DiagnosticArgs;
use clap::Args;
use weaver_common::vdir::VirtualDirectoryPath;

/// Parameters for the `registry check` sub-command
#[derive(Debug, Args)]
pub struct RegistryCheckArgs {
/// Parameters to specify the semantic convention registry
#[command(flatten)]
pub registry: RegistryArgs,

/// Parameters to specify the baseline semantic convention registry
#[arg(long)]
pub baseline_registry: Option<VirtualDirectoryPath>,

/// Policy parameters
#[command(flatten)]
pub policy: PolicyArgs,

/// Parameters to specify the diagnostic format.
#[command(flatten)]
pub diagnostic: DiagnosticArgs,
}
39 changes: 39 additions & 0 deletions crates/weaver_cli/src/registry/diff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0

//! Weaver registry diff sub-command.

use crate::registry::RegistryArgs;
use crate::DiagnosticArgs;
use clap::Args;
use std::path::PathBuf;
use weaver_common::vdir::VirtualDirectoryPath;

/// Parameters for the `registry diff` sub-command
#[derive(Debug, Args)]
pub struct RegistryDiffArgs {
/// Parameters to specify the semantic convention registry
#[command(flatten)]
pub registry: RegistryArgs,

/// Parameters to specify the baseline semantic convention registry
#[arg(long)]
pub baseline_registry: VirtualDirectoryPath,

/// Format used to render the schema changes. Predefined formats are: `ansi`, `json`,
/// and `markdown`.
#[arg(long, default_value = "ansi")]
pub diff_format: String,

/// Path to the directory where the schema changes templates are located.
#[arg(long, default_value = "diff_templates")]
pub diff_template: PathBuf,

/// Path to the directory where the generated artifacts will be saved.
/// If not specified, the diff report is printed to stdout
#[arg(short, long)]
pub output: Option<PathBuf>,

/// Parameters to specify the diagnostic format.
#[command(flatten)]
pub diagnostic: DiagnosticArgs,
}
31 changes: 31 additions & 0 deletions crates/weaver_cli/src/registry/emit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache-2.0

//! Weaver registry emit sub-command.

use crate::registry::{PolicyArgs, RegistryArgs};
use crate::DiagnosticArgs;
use clap::Args;

/// Parameters for the `registry emit` sub-command
#[derive(Debug, Args)]
pub struct RegistryEmitArgs {
/// Parameters to specify the semantic convention registry
#[command(flatten)]
pub registry: RegistryArgs,

/// Policy parameters
#[command(flatten)]
pub policy: PolicyArgs,

/// Parameters to specify the diagnostic format.
#[command(flatten)]
pub diagnostic: DiagnosticArgs,

/// Write the telemetry to standard output
#[arg(long)]
pub stdout: bool,

/// Endpoint for the OTLP receiver. OTEL_EXPORTER_OTLP_ENDPOINT env var will override this.
#[arg(long, default_value = weaver_emit::DEFAULT_OTLP_ENDPOINT)]
pub endpoint: String,
}
Loading
Loading