Skip to content

Commit

Permalink
refactor 'latest_release' and address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
labrenbe committed Dec 9, 2024
1 parent e6f73ca commit 967fce0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rust/stackable-cockpit/src/platform/release/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ impl ReleaseSpec {
}

impl ReleaseList {
/// Checks if a value provided in the '--release' argument is in the release list
pub fn contains(&self, release: &str) -> bool {
self.inner().contains_key(release)
}

/// Retrieves the latest release from the list and applies a sanity check to the release format.
pub fn latest_release(&self) -> Result<String, Error> {
let release = self.inner().first().context(EmptyReleaseListSnafu)?.0;
Expand Down
3 changes: 3 additions & 0 deletions rust/stackablectl/src/cmds/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ impl DemoArgs {

let release_branch = match &self.release {
Some(release) => {
if !release_list.contains(release) {
return NoSuchReleaseSnafu { name: release }.fail();
}
if release == "dev" {
"main".to_string()
} else {
Expand Down
6 changes: 6 additions & 0 deletions rust/stackablectl/src/cmds/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ pub enum CmdError {
#[snafu(display("failed to serialize JSON output"))]
SerializeJsonOutput { source: serde_json::Error },

#[snafu(display("no release with name '{name}'"))]
NoSuchRelease { name: String },

#[snafu(display("failed to get latest release"))]
LatestRelease { source: platform::release::Error },

Expand Down Expand Up @@ -155,6 +158,9 @@ impl StackArgs {

let release_branch = match &self.release {
Some(release) => {
if !release_list.contains(release) {
return NoSuchReleaseSnafu { name: release }.fail();
}
if release == "dev" {
"main".to_string()
} else {
Expand Down

0 comments on commit 967fce0

Please sign in to comment.