Skip to content

Commit 676b999

Browse files
Merge pull request #35 from code0-tech/34-version-arg
Add Tag Argument To Select A Version
2 parents e028cf9 + 776b142 commit 676b999

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ This repository contains all definitions for Code0. These definitions will be us
44
## Definition CLI
55

66
### Setup
7+
First download cargo to use the cli.
78
[Install Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html)
89

10+
Then run:
11+
```bash
12+
cargo install code0-cli
13+
```
14+
15+
After the cli compiled succesfully you can use it via:
16+
```bash
17+
code0-cli
18+
```
19+
920
### Usage
1021
(Stay inside the root directory when running the command)
1122

@@ -14,43 +25,48 @@ Will download the latest Definitions from the Code0 Definition Repository.
1425

1526
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.
1627

28+
-f (--features) is a list of features that will be downloaded.
29+
-t (--tag) is the version tag of the release you want to select.
30+
1731
```bash
18-
./cargo run download
19-
./cargo run download -f feature_1 feature_2 feature_3
32+
code0-cli download
33+
code0-cli download -t def-0.0.8
34+
code0-cli download -f feature_1 feature_2 feature_3
35+
code0-cli download -t def-0.0.8 -f feature_1 feature_2 feature_3
2036
```
2137

2238
#### General Report
2339
Will create a report of all errors in the definitions.
2440

2541
```bash
26-
./cargo run report
27-
./cargo run report -p /path/to/definitions
42+
code0-cli report
43+
code0-cli report -p /path/to/definitions
2844
```
2945

3046
#### Feature Report
3147
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.
3248

3349
```bash
34-
./cargo run feature
35-
./cargo run feature -p /path/to/definitions
36-
./cargo run feature -f feature_name
37-
./cargo run feature -f feature_name -p /path/to/definitions
50+
code0-cli feature
51+
code0-cli feature -p /path/to/definitions
52+
code0-cli feature -f feature_name
53+
code0-cli feature -f feature_name -p /path/to/definitions
3854
```
3955

4056
#### Watch for Changes
4157
Will run the report each time a definition file changes.
4258

4359
```bash
44-
./cargo run watch
45-
./cargo run watch -p /path/to/definitions
60+
code0-cli watch
61+
code0-cli watch -p /path/to/definitions
4662
```
4763

4864
#### Definition
4965
Will search for a specific definition.
5066

5167
```bash
52-
./cargo run definition -n definition_name
53-
./cargo run definition -n definition_name -p /path/to/definitions
68+
code0-cli definition -n definition_name
69+
code0-cli definition -n definition_name -p /path/to/definitions
5470
```
5571

5672
## TypeScript Definition Package

cli/src/command/download.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Asset {
1919
size: u64,
2020
}
2121

22-
pub async fn handle_download(features: Option<Vec<String>>) {
22+
pub async fn handle_download(tag: Option<String>, features: Option<Vec<String>>) {
2323
println!(
2424
"{}",
2525
"╔══════════════════════════════════════════════════════════════════════════════╗"
@@ -69,7 +69,7 @@ pub async fn handle_download(features: Option<Vec<String>>) {
6969

7070
// Download the definitions
7171
println!("\n{} Starting download process...", "📥".bright_blue());
72-
let bytes = match download_definitions_as_bytes().await {
72+
let bytes = match download_definitions_as_bytes(tag).await {
7373
Some(bytes) => {
7474
println!(
7575
"{} {}",
@@ -119,9 +119,19 @@ pub async fn handle_download(features: Option<Vec<String>>) {
119119
println!("{}", "═".repeat(80).bright_cyan());
120120
}
121121

122-
async fn download_definitions_as_bytes() -> Option<bytes::Bytes> {
122+
async fn download_definitions_as_bytes(tag: Option<String>) -> Option<bytes::Bytes> {
123123
let client = reqwest::Client::new();
124-
let url = "https://api.github.com/repos/code0-tech/code0-definition/releases/latest";
124+
125+
let url = match tag {
126+
Some(t) => {
127+
println!("Selected the version: {}", t.bright_blue());
128+
format!("https://api.github.com/repos/code0-tech/code0-definition/releases/tags/{t}")
129+
}
130+
None => {
131+
println!("No version specified, using latest version");
132+
String::from("https://api.github.com/repos/code0-tech/code0-definition/releases/latest")
133+
}
134+
};
125135

126136
println!(
127137
"{} Fetching latest release information...",
@@ -171,7 +181,7 @@ async fn download_definitions_as_bytes() -> Option<bytes::Bytes> {
171181
println!(
172182
"{} {}",
173183
"✅".green(),
174-
format!("Found latest release: {}", release.tag_name).green()
184+
format!("Selected release: {}", release.tag_name).green()
175185
);
176186
release
177187
}

cli/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ enum Commands {
4646
path: Option<String>,
4747
},
4848
Download {
49+
#[arg(short, long)]
50+
tag: Option<String>,
4951
#[clap(short, long, value_parser, num_args = 1.., value_delimiter = ' ')]
5052
features: Option<Vec<String>>,
5153
},
@@ -59,7 +61,9 @@ async fn main() {
5961
Commands::Report { path } => command::report::report_errors(path),
6062
Commands::Feature { name, path } => command::feature::search_feature(name, path),
6163
Commands::Definition { name, path } => command::definition::search_definition(name, path),
62-
Commands::Download { features } => command::download::handle_download(features).await,
64+
Commands::Download { tag, features } => {
65+
command::download::handle_download(tag, features).await
66+
}
6367
Commands::Watch { path } => command::watch::watch_for_changes(path).await,
6468
}
6569
}

0 commit comments

Comments
 (0)