From 2cea2f372f29ae96846ebce06e9903be4b7c34a5 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 1 Aug 2025 10:40:16 +0200 Subject: [PATCH 1/2] feat: added tag argument to cli to select download version --- cli/src/command/download.rs | 20 +++++++++++++++----- cli/src/main.rs | 6 +++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cli/src/command/download.rs b/cli/src/command/download.rs index ed137ce..70b0f35 100644 --- a/cli/src/command/download.rs +++ b/cli/src/command/download.rs @@ -19,7 +19,7 @@ struct Asset { size: u64, } -pub async fn handle_download(features: Option>) { +pub async fn handle_download(tag: Option, features: Option>) { println!( "{}", "╔══════════════════════════════════════════════════════════════════════════════╗" @@ -69,7 +69,7 @@ pub async fn handle_download(features: Option>) { // Download the definitions println!("\n{} Starting download process...", "📥".bright_blue()); - let bytes = match download_definitions_as_bytes().await { + let bytes = match download_definitions_as_bytes(tag).await { Some(bytes) => { println!( "{} {}", @@ -119,9 +119,19 @@ pub async fn handle_download(features: Option>) { println!("{}", "═".repeat(80).bright_cyan()); } -async fn download_definitions_as_bytes() -> Option { +async fn download_definitions_as_bytes(tag: Option) -> Option { let client = reqwest::Client::new(); - let url = "https://api.github.com/repos/code0-tech/code0-definition/releases/latest"; + + let url = match tag { + Some(t) => { + println!("Selected the version: {}", t.bright_blue()); + format!("https://api.github.com/repos/code0-tech/code0-definition/releases/tags/{t}") + } + None => { + println!("No version specified, using latest version"); + String::from("https://api.github.com/repos/code0-tech/code0-definition/releases/latest") + } + }; println!( "{} Fetching latest release information...", @@ -171,7 +181,7 @@ async fn download_definitions_as_bytes() -> Option { println!( "{} {}", "✅".green(), - format!("Found latest release: {}", release.tag_name).green() + format!("Selected release: {}", release.tag_name).green() ); release } diff --git a/cli/src/main.rs b/cli/src/main.rs index dd9ace7..c9f8ea1 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -46,6 +46,8 @@ enum Commands { path: Option, }, Download { + #[arg(short, long)] + tag: Option, #[clap(short, long, value_parser, num_args = 1.., value_delimiter = ' ')] features: Option>, }, @@ -59,7 +61,9 @@ async fn main() { Commands::Report { path } => command::report::report_errors(path), Commands::Feature { name, path } => command::feature::search_feature(name, path), Commands::Definition { name, path } => command::definition::search_definition(name, path), - Commands::Download { features } => command::download::handle_download(features).await, + Commands::Download { tag, features } => { + command::download::handle_download(tag, features).await + } Commands::Watch { path } => command::watch::watch_for_changes(path).await, } } From 776b1428ff15006555999a0fe4e07d203f6b3aea Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 1 Aug 2025 10:46:25 +0200 Subject: [PATCH 2/2] docs: updated cli desription --- README.md | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2e0de58..ea822a4 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,19 @@ This repository contains all definitions for Code0. These definitions will be us ## Definition CLI ### Setup +First download cargo to use the cli. [Install Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) +Then run: +```bash +cargo install code0-cli +``` + +After the cli compiled succesfully you can use it via: +```bash +code0-cli +``` + ### Usage (Stay inside the root directory when running the command) @@ -14,43 +25,48 @@ Will download the latest Definitions from the Code0 Definition Repository. If no feature is specified, all features will be downloaded. If a feature is specified, only that feature will be kept & can be loaded by one of the following languages: TypeScript, Rust. +-f (--features) is a list of features that will be downloaded. +-t (--tag) is the version tag of the release you want to select. + ```bash -./cargo run download -./cargo run download -f feature_1 feature_2 feature_3 +code0-cli download +code0-cli download -t def-0.0.8 +code0-cli download -f feature_1 feature_2 feature_3 +code0-cli download -t def-0.0.8 -f feature_1 feature_2 feature_3 ``` #### General Report Will create a report of all errors in the definitions. ```bash -./cargo run report -./cargo run report -p /path/to/definitions +code0-cli report +code0-cli report -p /path/to/definitions ``` #### Feature Report Will create a report of all errors in the definitions for a specific feature. Will also report on all specified functions, data types, and flow types. ```bash -./cargo run feature -./cargo run feature -p /path/to/definitions -./cargo run feature -f feature_name -./cargo run feature -f feature_name -p /path/to/definitions +code0-cli feature +code0-cli feature -p /path/to/definitions +code0-cli feature -f feature_name +code0-cli feature -f feature_name -p /path/to/definitions ``` #### Watch for Changes Will run the report each time a definition file changes. ```bash -./cargo run watch -./cargo run watch -p /path/to/definitions +code0-cli watch +code0-cli watch -p /path/to/definitions ``` #### Definition Will search for a specific definition. ```bash -./cargo run definition -n definition_name -./cargo run definition -n definition_name -p /path/to/definitions +code0-cli definition -n definition_name +code0-cli definition -n definition_name -p /path/to/definitions ``` ## TypeScript Definition Package