-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathsdk.rs
More file actions
73 lines (64 loc) · 2.02 KB
/
Copy pathsdk.rs
File metadata and controls
73 lines (64 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use clap::Subcommand;
use color_eyre::{
Result,
eyre::{Context, bail},
};
use repository::{
Repository,
sdk::{SDKImage, build_sdk_container, pull_sdk_image},
};
use tokio::process::Command;
#[derive(Subcommand)]
pub enum Arguments {
/// Pulls the SDK image from ghcr.io/hulks
#[command(visible_alias = "installier")]
Install {
/// SDK version e.g. `1.0.0`. If not provided, version specified by `hulk.toml` is used.
#[arg(long, visible_alias = "abbild", visible_alias = "bild")]
image: Option<String>,
},
/// Builds the SDK image
#[command(visible_alias = "bau")]
Build {
/// SDK version e.g. `3.3.1`. If not provided, version specified by `hulk.toml` is used.
#[arg(long, visible_alias = "abbild", visible_alias = "bild")]
image: Option<String>,
},
#[command(visible_alias = "aufzähl")]
List,
}
pub async fn sdk(arguments: Arguments, repository: &Repository) -> Result<()> {
let sdk_version = repository
.read_sdk_version()
.await
.wrap_err("failed to get HULK OS version")?;
let mut sdk_image = SDKImage {
registry: "ghcr.io/hulks".to_string(),
name: "k1sdk".to_string(),
tag: sdk_version,
};
match arguments {
Arguments::Install { image } => {
if let Some(image) = image {
sdk_image = sdk_image.parse_and_update(&image)
}
pull_sdk_image(&sdk_image).await?;
}
Arguments::Build { image } => {
if let Some(image) = image {
sdk_image = sdk_image.parse_and_update(&image)
}
build_sdk_container(repository, &sdk_image).await?;
}
Arguments::List => {
let status = Command::new("podman")
.args(["image", "list", "--filter", "reference=k1sdk"])
.status()
.await?;
if !status.success() {
bail!("podman failed with {status}");
}
}
}
Ok(())
}