Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Select versions of demos & stacks #340

Merged
merged 11 commits into from
Dec 18, 2024
3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/cache.adoc
Original file line number Diff line number Diff line change
@@ -20,9 +20,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/completions.adoc
Original file line number Diff line number Diff line change
@@ -23,9 +23,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

4 changes: 2 additions & 2 deletions docs/modules/stackablectl/partials/commands/demo.adoc
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network
--release <RELEASE>
Target a specific Stackable release

-h, --help
Print help (see a summary with '-h')
Original file line number Diff line number Diff line change
@@ -37,9 +37,6 @@ Options:

Defaults to the image of the target container if not specified.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/index.adoc
Original file line number Diff line number Diff line change
@@ -26,9 +26,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/operator.adoc
Original file line number Diff line number Diff line change
@@ -23,9 +23,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/release.adoc
Original file line number Diff line number Diff line change
@@ -22,9 +22,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

4 changes: 2 additions & 2 deletions docs/modules/stackablectl/partials/commands/stack.adoc
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network
--release <RELEASE>
Target a specific Stackable release

-h, --help
Print help (see a summary with '-h')
3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/stacklet.adoc
Original file line number Diff line number Diff line change
@@ -25,9 +25,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

41 changes: 8 additions & 33 deletions extra/completions/_stackablectl

Large diffs are not rendered by default.

98 changes: 65 additions & 33 deletions extra/completions/stackablectl.bash

Large diffs are not rendered by default.

41 changes: 8 additions & 33 deletions extra/completions/stackablectl.elv

Large diffs are not rendered by default.

43 changes: 9 additions & 34 deletions extra/completions/stackablectl.fish

Large diffs are not rendered by default.

41 changes: 8 additions & 33 deletions extra/completions/stackablectl.nu

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions extra/man/stackablectl.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions rust/stackable-cockpit/src/common/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::marker::PhantomData;
use std::{marker::PhantomData, ops::Deref};

use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
@@ -18,7 +18,7 @@ pub enum Error {
}

pub trait SpecIter<S> {
fn inner(&self) -> &IndexMap<String, S>;
fn inner(self) -> IndexMap<String, S>;
}

/// A [`List`] describes a list of specs. The list can contain any specs, for
@@ -54,7 +54,7 @@ where
.context(FileTransferSnafu)?;

for (spec_name, spec) in specs.inner() {
map.insert(spec_name.clone(), spec.clone());
map.insert(spec_name, spec);
}
}

@@ -63,17 +63,16 @@ where
inner: map,
})
}
}

/// Returns a reference to the inner [`IndexMap`]
pub fn inner(&self) -> &IndexMap<String, S> {
&self.inner
}
impl<L, S> Deref for List<L, S>
where
L: for<'a> Deserialize<'a> + Serialize + SpecIter<S>,
S: for<'a> Deserialize<'a> + Serialize + Clone,
{
type Target = IndexMap<String, S>;

/// Returns an optional reference to a single spec of type `S` by `name`
pub fn get<T>(&self, name: T) -> Option<&S>
where
T: AsRef<str>,
{
self.inner.get(name.as_ref())
fn deref(&self) -> &Self::Target {
&self.inner
}
}
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/platform/demo/mod.rs
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ pub struct DemosV2 {
}

impl SpecIter<DemoSpec> for DemosV2 {
fn inner(&self) -> &IndexMap<String, DemoSpec> {
&self.demos
fn inner(self) -> IndexMap<String, DemoSpec> {
self.demos
}
}

7 changes: 2 additions & 5 deletions rust/stackable-cockpit/src/platform/release/mod.rs
Original file line number Diff line number Diff line change
@@ -15,12 +15,9 @@ pub struct Releases {
}

impl SpecIter<ReleaseSpec> for Releases {
fn inner(&self) -> &IndexMap<String, ReleaseSpec> {
&self.releases
fn inner(self) -> IndexMap<String, ReleaseSpec> {
self.releases
}
}

pub type ReleaseList = crate::common::list::List<Releases, ReleaseSpec>;

#[derive(Default)]
pub struct Release {}
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/platform/stack/mod.rs
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ pub struct StacksV2 {
}

impl SpecIter<StackSpec> for StacksV2 {
fn inner(&self) -> &IndexMap<String, StackSpec> {
&self.stacks
fn inner(self) -> IndexMap<String, StackSpec> {
self.stacks
}
}

10 changes: 10 additions & 0 deletions rust/stackablectl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Add new argument `--release` that allows installing a specific version of a demo or stack ([#340]).

### Removed

- Remove argument `--offline` that was not implemented yet ([#340]).

[#340]: https://github.com/stackabletech/stackable-cockpit/pull/340

## [24.11.1] - 2024-11-20

### Added
3 changes: 0 additions & 3 deletions rust/stackablectl/README.md
Original file line number Diff line number Diff line change
@@ -35,9 +35,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

46 changes: 24 additions & 22 deletions rust/stackablectl/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -8,20 +8,19 @@ use tracing::{debug, instrument, Level};
use stackable_cockpit::{
constants::{HELM_REPO_NAME_DEV, HELM_REPO_NAME_STABLE, HELM_REPO_NAME_TEST},
helm,
platform::demo::List,
utils::path::{
IntoPathOrUrl, IntoPathsOrUrls, ParsePathsOrUrls, PathOrUrl, PathOrUrlParseError,
},
xfer::{cache::Settings, Client},
xfer::cache::Settings,
};

use crate::{
args::{CommonFileArgs, CommonRepoArgs},
cmds::{cache, completions, debug, demo, operator, release, stack, stacklet},
constants::{
ENV_KEY_DEMO_FILES, ENV_KEY_RELEASE_FILES, ENV_KEY_STACK_FILES, REMOTE_DEMO_FILE,
REMOTE_RELEASE_FILE, REMOTE_STACK_FILE, USER_DIR_APPLICATION_NAME,
USER_DIR_ORGANIZATION_NAME, USER_DIR_QUALIFIER,
DEMOS_REPOSITORY_DEMOS_SUBPATH, DEMOS_REPOSITORY_STACKS_SUBPATH, DEMOS_REPOSITORY_URL_BASE,
ENV_KEY_DEMO_FILES, ENV_KEY_RELEASE_FILES, ENV_KEY_STACK_FILES, REMOTE_RELEASE_FILE,
USER_DIR_APPLICATION_NAME, USER_DIR_ORGANIZATION_NAME, USER_DIR_QUALIFIER,
},
output::{ErrorContext, Output, ResultContext},
};
@@ -74,10 +73,6 @@ Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
)]
pub no_cache: bool,

/// Do not request any remote files via the network
#[arg(long, global = true)]
pub offline: bool,

#[command(flatten)]
pub files: CommonFileArgs,

@@ -90,27 +85,34 @@ Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually

impl Cli {
/// Returns a list of demo files, consisting of entries which are either a path or URL. The list of files combines
/// the default demo file URL, [`REMOTE_DEMO_FILE`], files provided by the ENV variable [`ENV_KEY_DEMO_FILES`], and
/// lastly, files provided by the CLI argument `--demo-file`.
pub fn get_demo_files(&self) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let mut files = get_files(REMOTE_DEMO_FILE, ENV_KEY_DEMO_FILES)?;
/// the default demo file URL constructed from [`DEMOS_REPOSITORY_URL_BASE`] and the provided branch, files provided
/// by the ENV variable [`ENV_KEY_DEMO_FILES`], and lastly, files provided by the CLI argument `--demo-file`.
pub fn get_demo_files(&self, branch: &str) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let branch_url = format!(
"{base}/{branch}/{demos}",
base = DEMOS_REPOSITORY_URL_BASE,
demos = DEMOS_REPOSITORY_DEMOS_SUBPATH
);

let mut files = get_files(&branch_url, ENV_KEY_DEMO_FILES)?;

let arg_files = self.files.demo_files.clone().into_paths_or_urls()?;
files.extend(arg_files);

Ok(files)
}

pub async fn get_demo_list(&self, transfer_client: &Client) -> List {
let files = self.get_demo_files().unwrap();
List::build(&files, transfer_client).await.unwrap()
}

/// Returns a list of stack files, consisting of entries which are either a path or URL. The list of files combines
/// the default stack file URL, [`REMOTE_STACK_FILE`], files provided by the ENV variable [`ENV_KEY_STACK_FILES`],
/// and lastly, files provided by the CLI argument `--stack-file`.
pub fn get_stack_files(&self) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let mut files = get_files(REMOTE_STACK_FILE, ENV_KEY_STACK_FILES)?;
/// the default stack file URL constructed from [`DEMOS_REPOSITORY_URL_BASE`] and the provided branch, files provided
/// by the ENV variable [`ENV_KEY_STACK_FILES`], and lastly, files provided by the CLI argument `--stack-file`.
pub fn get_stack_files(&self, branch: &str) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let branch_url = format!(
"{base}/{branch}/{stacks}",
base = DEMOS_REPOSITORY_URL_BASE,
stacks = DEMOS_REPOSITORY_STACKS_SUBPATH
);

let mut files = get_files(&branch_url, ENV_KEY_STACK_FILES)?;

let arg_files = self.files.stack_files.clone().into_paths_or_urls()?;
files.extend(arg_files);
Loading
Loading