feat: Retain context

This commit is contained in:
2026-10-04 05:53:17 +02:00
parent 35aedf1d5b
commit 88405a1e63
3 changed files with 42 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
use serde::Deserialize;
use tokio::process::Command;
use crate::{get_configs_path, run_command};
#[derive(Debug, Deserialize)]
struct TalosConfig {
pub context: String,
}
pub async fn get_current_context() -> Option<String> {
let path = get_configs_path().join("talosconfig");
tokio::fs::read(&path)
.await
.ok()
.and_then(|config| serde_yaml::from_slice(&config).ok())
.map(|config: TalosConfig| config.context)
}
pub async fn set_context(context: String) {
let path = get_configs_path().join("talosconfig");
let mut command = Command::new("talosctl");
command.args([
"config",
"--talosconfig",
path.to_str().expect("Path should be valid utf-8"),
"context",
&context,
]);
run_command(command).await;
}