Skip to content

Add Tag Argument To Select A Version #35

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

Merged
merged 2 commits into from
Aug 1, 2025
Merged
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
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
20 changes: 15 additions & 5 deletions cli/src/command/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Asset {
size: u64,
}

pub async fn handle_download(features: Option<Vec<String>>) {
pub async fn handle_download(tag: Option<String>, features: Option<Vec<String>>) {
println!(
"{}",
"╔══════════════════════════════════════════════════════════════════════════════╗"
Expand Down Expand Up @@ -69,7 +69,7 @@ pub async fn handle_download(features: Option<Vec<String>>) {

// 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!(
"{} {}",
Expand Down Expand Up @@ -119,9 +119,19 @@ pub async fn handle_download(features: Option<Vec<String>>) {
println!("{}", "═".repeat(80).bright_cyan());
}

async fn download_definitions_as_bytes() -> Option<bytes::Bytes> {
async fn download_definitions_as_bytes(tag: Option<String>) -> Option<bytes::Bytes> {
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...",
Expand Down Expand Up @@ -171,7 +181,7 @@ async fn download_definitions_as_bytes() -> Option<bytes::Bytes> {
println!(
"{} {}",
"✅".green(),
format!("Found latest release: {}", release.tag_name).green()
format!("Selected release: {}", release.tag_name).green()
);
release
}
Expand Down
6 changes: 5 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ enum Commands {
path: Option<String>,
},
Download {
#[arg(short, long)]
tag: Option<String>,
#[clap(short, long, value_parser, num_args = 1.., value_delimiter = ' ')]
features: Option<Vec<String>>,
},
Expand All @@ -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,
}
}