Skip to content
Open
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
5 changes: 5 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,10 @@ glob = "0.3"
# CLI and terminal output
colored = "3.0"

# Rust syntax parsing (used by gts-cli for struct expression extraction)
syn = { version = "2.0", features = ["full", "extra-traits"] }
quote = "1.0"
proc-macro2 = "1.0"

# Format parsing
serde-saphyr = "0.0.10"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CI := 1

.PHONY: help build dev-fmt dev-clippy all check fmt clippy test deny security update-spec e2e generate-schemas
.PHONY: help build dev-fmt dev-clippy all check fmt clippy test deny security update-spec e2e generate-schemas coverage

# Default target - show help
.DEFAULT_GOAL := help
Expand Down
5 changes: 5 additions & 0 deletions gts-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ path = "src/main.rs"

[dependencies]
gts.workspace = true
gts-id.workspace = true
serde.workspace = true
serde_json.workspace = true
anyhow.workspace = true
Expand All @@ -32,6 +33,10 @@ tracing-subscriber.workspace = true
chrono.workspace = true
regex.workspace = true
walkdir.workspace = true
jsonschema.workspace = true
syn.workspace = true
quote.workspace = true
proc-macro2.workspace = true

[dev-dependencies]
tempfile = "3.8"
Expand Down
42 changes: 36 additions & 6 deletions gts-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::{Parser, Subcommand};
use gts::GtsOps;
use std::io::Write;

use crate::gen_instances::generate_instances_from_rust;
use crate::gen_schemas::generate_schemas_from_rust;
use crate::server::GtsHttpServer;

Expand Down Expand Up @@ -119,20 +120,35 @@ pub enum Commands {
#[arg(long, default_value = "8000")]
port: u16,
},
/// Generate GTS schemas from Rust source code with `#[struct_to_gts_schema]` annotations
/// Generate GTS artifacts from Rust source code with `#[struct_to_gts_schema]` /
/// `#[gts_well_known_instance]` annotations
GenerateFromRust {
/// Source directory or file to scan for annotated structs
/// Source directory or file to scan for annotated items
#[arg(long)]
source: String,
/// Output directory for generated schemas (optional: uses paths from macro if not specified)
/// Output directory for generated files (optional: uses paths from macro if not specified)
#[arg(long)]
output: Option<String>,
/// Exclude patterns (can be specified multiple times). Supports glob patterns.
/// Example: --exclude "tests/*" --exclude "examples/*"
#[arg(long, action = clap::ArgAction::Append)]
exclude: Vec<String>,
/// What to generate: schemas (default), instances, or all
#[arg(long, default_value = "schemas")]
mode: GenerateMode,
},
}

/// Controls what `generate-from-rust` generates.
#[derive(clap::ValueEnum, Clone, Debug, PartialEq, Eq)]
pub enum GenerateMode {
/// Generate JSON schemas from `#[struct_to_gts_schema]` annotations (default)
Schemas,
/// Generate well-known instance JSON files from `#[gts_well_known_instance]` annotations
Instances,
/// Generate both schemas and instances
All,
}
/// Run the CLI application
///
/// # Errors
Expand Down Expand Up @@ -259,9 +275,19 @@ async fn run_command(cli: Cli) -> Result<()> {
source,
output,
exclude,
} => {
generate_schemas_from_rust(&source, output.as_deref(), &exclude, cli.verbose)?;
}
mode,
} => match mode {
GenerateMode::Schemas => {
generate_schemas_from_rust(&source, output.as_deref(), &exclude, cli.verbose)?;
}
GenerateMode::Instances => {
generate_instances_from_rust(&source, output.as_deref(), &exclude, cli.verbose)?;
}
GenerateMode::All => {
generate_schemas_from_rust(&source, output.as_deref(), &exclude, cli.verbose)?;
generate_instances_from_rust(&source, output.as_deref(), &exclude, cli.verbose)?;
}
},
}

Ok(())
Expand Down Expand Up @@ -357,10 +383,12 @@ mod tests {
source,
output,
exclude,
mode,
} => {
assert_eq!(source, "/src/path");
assert_eq!(output, Some("/out/path".to_owned()));
assert_eq!(exclude, vec!["tests/*", "examples/*"]);
assert_eq!(mode, GenerateMode::Schemas);
}
_ => panic!("Expected GenerateFromRust command"),
}
Expand Down Expand Up @@ -639,10 +667,12 @@ mod tests {
source,
output,
exclude,
mode,
} => {
assert_eq!(source, "/src/path");
assert_eq!(output, None);
assert!(exclude.is_empty());
assert_eq!(mode, GenerateMode::Schemas);
}
_ => panic!("Expected GenerateFromRust command"),
}
Expand Down
Loading
Loading