Skip to content

Commit e6f73ca

Browse files
committed
refactor 'latest_release' and address PR feedback
1 parent 1a0e041 commit e6f73ca

File tree

14 files changed

+99
-43
lines changed

14 files changed

+99
-43
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/modules/stackablectl/partials/commands/stack.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Options:
2121
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
2222
'$HOME/.cache/stackablectl' when not explicitly set.
2323
24+
--release <RELEASE>
25+
Target a specific Stackable release
26+
2427
-h, --help
2528
Print help (see a summary with '-h')
2629

extra/completions/_stackablectl

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extra/completions/stackablectl.bash

Lines changed: 20 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extra/completions/stackablectl.elv

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extra/completions/stackablectl.fish

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extra/completions/stackablectl.nu

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/stackable-cockpit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ indexmap.workspace = true
2020
k8s-openapi.workspace = true
2121
kube.workspace = true
2222
rand.workspace = true
23+
regex.workspace = true
2324
reqwest.workspace = true
2425
semver.workspace = true
2526
serde_json.workspace = true

rust/stackable-cockpit/src/platform/release/spec.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use futures::{StreamExt as _, TryStreamExt};
22
use indexmap::IndexMap;
3+
use regex::Regex;
34
use serde::{Deserialize, Serialize};
4-
use snafu::{ResultExt, Snafu};
5+
use snafu::{OptionExt, ResultExt, Snafu};
56
use tokio::task::JoinError;
67
use tracing::{info, instrument};
78

@@ -16,6 +17,8 @@ use crate::{
1617
},
1718
};
1819

20+
use super::ReleaseList;
21+
1922
type Result<T, E = Error> = std::result::Result<T, E>;
2023

2124
#[derive(Debug, Snafu)]
@@ -31,6 +34,12 @@ pub enum Error {
3134

3235
#[snafu(display("failed to launch background task"))]
3336
BackgroundTask { source: JoinError },
37+
38+
#[snafu(display("release list is empty"))]
39+
EmptyReleaseList,
40+
41+
#[snafu(display("latest release doesn't have expected format"))]
42+
LatestReleaseFormat,
3443
}
3544

3645
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -119,3 +128,16 @@ impl ReleaseSpec {
119128
.collect()
120129
}
121130
}
131+
132+
impl ReleaseList {
133+
/// Retrieves the latest release from the list and applies a sanity check to the release format.
134+
pub fn latest_release(&self) -> Result<String, Error> {
135+
let release = self.inner().first().context(EmptyReleaseListSnafu)?.0;
136+
let sanity_check = Regex::new("^[0-9]{2}.[0-9]{1,2}$").unwrap();
137+
if sanity_check.is_match(release) {
138+
Ok(release.to_string())
139+
} else {
140+
LatestReleaseFormatSnafu {}.fail()
141+
}
142+
}
143+
}

0 commit comments

Comments
 (0)