Skip to content

Commit

Permalink
remove duplicate code, handle control c
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcichra committed Dec 25, 2023
1 parent b27d320 commit a176e1c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.76"
clap = { version = "4.4.11", features = ["derive"] }
ctrlc = "3.4.2"
futures = "0.3.30"
k8s-openapi = { version = "0.20.0", features = ["latest"] }
kube = { version = "0.87.2", features = ["runtime", "derive"] }
Expand Down
14 changes: 0 additions & 14 deletions src/kubeclient.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::{bail, Context, Result};
use clap::Parser;
use kube::{
api::{Patch, PatchParams},
core::{DynamicObject, GroupVersionKind},
Expand All @@ -8,19 +7,6 @@ use kube::{
};
use log::{info, trace, warn};

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(long, default_value = "kapplier")]
user_agent: String,
#[clap(long, default_value = ".")]
directory: String,
#[clap(long, default_values = [".git"])]
ignore_directories: Vec<String>,
#[clap(long, default_values = ["yml", "yaml"])]
supported_extensions: Vec<String>,
}

// https://github.com/kube-rs/kube/blob/main/examples/kubectl.rs#L249
fn multidoc_deserialize(data: &str) -> Result<Vec<serde_yaml::Value>> {
use serde::Deserialize;
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{path::Path, time::Duration};
use std::{path::Path, process, time::Duration};

use anyhow::Result;
use clap::Parser;
Expand Down Expand Up @@ -34,6 +34,13 @@ async fn main() -> Result<()> {
let args = Args::parse();
let full_run_args = args.clone();

// handle control c
ctrlc::set_handler(move || {
info!("received Ctrl+C! Exiting...");
// exit immediately
process::exit(0);
})?;

// full run thread
tokio::spawn(async move {
let args = full_run_args;
Expand Down

0 comments on commit a176e1c

Please sign in to comment.