Skip to content

Commit

Permalink
Merge pull request #52 from nicmr/fix/clippy-warnings
Browse files Browse the repository at this point in the history
Fix clippy warnings
  • Loading branch information
nicmr authored Dec 16, 2023
2 parents 0e2c1f8 + 15490ca commit d1ccfb3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn set_default_namespace(ns: &str, ctx: &str) {
.arg("config")
.arg(format!(
"--kubeconfig={}/.kube/config",
dirs::home_dir().unwrap().display().to_string()
dirs::home_dir().unwrap().display()
))
.arg("set-context")
.arg(ctx)
Expand All @@ -32,7 +32,7 @@ pub fn set_default_context(ctx: &str) {
.arg("config")
.arg(format!(
"--kubeconfig={}/.kube/config",
dirs::home_dir().unwrap().display().to_string()
dirs::home_dir().unwrap().display()
))
.arg("use-context")
.arg(ctx)
Expand Down
46 changes: 23 additions & 23 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ use std::io::{BufReader, BufWriter, Read};
use std::path::Path;

fn build(ctx: &Contexts, ns: Option<&str>, strbuf: &str) -> KubeConfig {
let mut config: KubeConfig = serde_yaml::from_str(&strbuf).unwrap();
let mut config: KubeConfig = serde_yaml::from_str(strbuf).unwrap();
config.api_version = "v1".to_string();
config.kind = "Config".to_string();
config.current_context = format!("{}", ctx.name);

let ns = if ns.is_some() {
ns.unwrap().to_string()
} else if config.contexts.len() > 0 && !config.contexts[0].context.namespace.is_empty() {
config.contexts[0].context.namespace.to_string()
} else if !ctx.context.namespace.is_empty() {
ctx.context.namespace.to_string()
} else {
"default".to_string()
config.current_context = ctx.name.to_string();

let ns = match ns {
Some(namespace) => namespace.to_string(),
None => {
if !config.contexts.is_empty() && !config.contexts[0].context.namespace.is_empty() {
config.contexts[0].context.namespace.to_string()
} else if !ctx.context.namespace.is_empty() {
ctx.context.namespace.to_string()
} else {
"default".to_string()
}
}
};

config.contexts = vec![Contexts {
context: Context {
namespace: ns.to_string(),
namespace: ns,
cluster: ctx.context.cluster.to_string(),
user: ctx.context.user.to_string(),
},
Expand Down Expand Up @@ -66,15 +69,15 @@ pub fn write(ctx: &Contexts, namespace: Option<&str>, dest: &str) {

let options = get_file(&path);
let writer = BufWriter::new(&options);
let config = build(&ctx, namespace, &strbuf);
let config = build(ctx, namespace, &strbuf);

serde_yaml::to_writer(writer, &config).unwrap();
}

pub fn get() -> KubeConfig {
let mut configs = KubeConfig::default();

for s in KUBECONFIG.rsplit(":") {
for s in KUBECONFIG.rsplit(':') {
if s.contains("/kubesess/cache") {
continue;
}
Expand Down Expand Up @@ -110,20 +113,17 @@ fn get_config(path: &str) -> KubeConfig {
.read_to_string(&mut tmp)
.expect("Unable to read file");

let config: KubeConfig = serde_yaml::from_str(&tmp.trim()).unwrap();
let config: KubeConfig = serde_yaml::from_str(tmp.trim()).unwrap();

config
}

pub fn get_current_session() -> KubeConfig {
let config;
let current;

if KUBESESSCONFIG.is_empty() {
current = KUBECONFIG.split(":").next().unwrap();
let current= if KUBESESSCONFIG.is_empty() {
KUBECONFIG.split(':').next().unwrap()
} else {
current = KUBESESSCONFIG.as_str();
}
KUBESESSCONFIG.as_str()
};

let f = File::open(current).unwrap();

Expand All @@ -133,7 +133,7 @@ pub fn get_current_session() -> KubeConfig {
.read_to_string(&mut tmp)
.expect("Unable to read file");

config = serde_yaml::from_str(&tmp.trim()).unwrap();
let config = serde_yaml::from_str(tmp.trim()).unwrap();

config
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lazy_static! {
match env::var("KUBECONFIG") {
Ok(val) => {
let mut paths: String = String::new();
for s in val.split_inclusive(":") {
for s in val.split_inclusive(':') {
if s.contains("/kubesess/cache") {
continue;
}
Expand All @@ -30,7 +30,7 @@ lazy_static! {
match env::var("KUBECONFIG") {
Ok(val) => {
let mut paths: String = String::new();
for s in val.split(":") {
for s in val.split(':') {
if s.contains("/kubesess/cache") {
paths.push_str(s);
}
Expand Down
4 changes: 2 additions & 2 deletions src/modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn context(args: Cli) {
"{}/{}:{}",
&DEST.as_str(),
str::replace(&ctx, ":", "_"),
KUBECONFIG.to_string()
*KUBECONFIG
);
},
Err(e) => {
Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn namespace(args: Cli) {
"{}/{}:{}",
&DEST.as_str(),
str::replace(&config.current_context, ":", "_"),
KUBECONFIG.to_string()
*KUBECONFIG
);
}

Expand Down

0 comments on commit d1ccfb3

Please sign in to comment.