Skip to content

Commit 2cea2f3

Browse files
committed
feat: added tag argument to cli to select download version
1 parent e028cf9 commit 2cea2f3

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

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)