Skip to content

Commit 8f39afe

Browse files
committed
error message when version is invalid
1 parent 92cc8e7 commit 8f39afe

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

cli/src/commands/publish.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub async fn publish(
2424
let request = create_publish_package_request(&payload);
2525
client.publish_package(&jwt, &request).await?;
2626

27+
if payload.install_files.is_empty() {
28+
return Err(anyhow::anyhow!("No valid script file (.sql) found."));
29+
}
30+
2731
let mut num_published = 0;
2832

2933
for install_file in &payload.install_files {
@@ -45,10 +49,6 @@ pub async fn publish(
4549
}
4650
}
4751

48-
if num_published == 0 {
49-
return Err(anyhow::anyhow!("No valid script file (.sql) found."));
50-
}
51-
5252
for upgrade_file in &payload.upgrade_files {
5353
let request =
5454
create_publich_package_upgrade_request(&payload.metadata.extension_name, upgrade_file);

cli/src/models.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Payload {
171171
continue;
172172
}
173173
if !util::is_valid_version(ver) {
174-
println!("Warning: file `{file_name}` will be skipped because its version (`{ver}`) is invalid");
174+
println!("Warning: file `{file_name}` will be skipped because its version (`{ver}`) is invalid. It should be have the format `major.minor.patch`.");
175175
continue;
176176
}
177177

@@ -190,11 +190,11 @@ impl Payload {
190190
continue;
191191
}
192192
if !util::is_valid_version(from_ver) {
193-
println!("Warning: file `{file_name}` will be skipped because its from version(`{from_ver}`) is invalid.");
193+
println!("Warning: file `{file_name}` will be skipped because its from version(`{from_ver}`) is invalid. It should be have the format `major.minor.patch`.");
194194
continue;
195195
}
196196
if !util::is_valid_version(to_ver) {
197-
println!("Warning: file `{file_name}` will be skipped because its from version(`{to_ver}`) is invalid.");
197+
println!("Warning: file `{file_name}` will be skipped because its from version(`{to_ver}`) is invalid. It should be have the format `major.minor.patch`.");
198198
continue;
199199
}
200200

cli/src/util.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@ pub fn is_valid_extension_name(name: &str) -> bool {
1616
name_regex.is_match(name)
1717
}
1818

19-
pub fn is_valid_version(_version: &str) -> bool {
19+
pub fn is_valid_version(version: &str) -> bool {
20+
let nums: Vec<&str> = version.split('.').collect();
21+
if nums.len() != 3 {
22+
println!("1");
23+
return false;
24+
}
25+
26+
for num_str in nums {
27+
let num: i16 = match num_str.parse() {
28+
Ok(n) => n,
29+
_ => return false,
30+
};
31+
if num < 0 {
32+
return false;
33+
}
34+
}
35+
2036
true
2137
}
2238

0 commit comments

Comments
 (0)