use std::path::PathBuf; use serde::Deserialize; use tokio::process::Command; use crate::{get_configs_path, run_command}; #[derive(Debug, Deserialize)] pub struct TalosConfig { context: String, } impl TalosConfig { pub fn merged_path() -> PathBuf { get_configs_path().join("talosconfig") } } pub async fn get_current_context() -> Option { tokio::fs::read(&TalosConfig::merged_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 mut command = Command::new("talosctl"); command.args([ "config", "--talosconfig", TalosConfig::merged_path() .to_str() .expect("Path should be valid utf-8"), "context", &context, ]); run_command(command).await; }