Skip to content

Commit

Permalink
Merge pull request #65 from Ramilito/fix/set_default_multifile
Browse files Browse the repository at this point in the history
fix: set default context
  • Loading branch information
Ramilito authored Nov 17, 2024
2 parents c894030 + d887ee3 commit cd2de15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::config;
use crate::error::SetContextError;
use crate::KUBECONFIG;

use std::{
io::Cursor,
Expand All @@ -24,17 +25,20 @@ pub fn set_default_namespace(ns: &str, ctx: &str, target: &Path) {
.unwrap();
}

pub fn set_default_context(ctx: &str, target: &Path) {
Command::new("kubectl")
pub fn set_default_context(ctx: &str) {
let output = Command::new("kubectl")
.arg("config")
.arg(format!("--kubeconfig={}", target.to_string_lossy()))
.arg("use-context")
.arg(ctx)
.env("KUBECONFIG", KUBECONFIG.as_str())
.stdout(Stdio::null())
.spawn()
.unwrap()
.wait()
.unwrap();
.stderr(Stdio::piped())
.output()
.expect("Failed to execute command");

if !output.status.success() {
eprintln!("Error: {}", String::from_utf8_lossy(&output.stderr));
}
}

pub fn get_namespaces() -> Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn default_context(args: Cli) -> Result<(), Error> {
})
.map(|(_, path)| path.clone())
{
commands::set_default_context(&ctx, &target);
commands::set_default_context(&ctx);
// TODO: We should move the target to the front of the line instead of inserting a
// duplicate
println!("{}:{}", target.to_string_lossy(), KUBECONFIG.as_str());
Expand Down

0 comments on commit cd2de15

Please sign in to comment.