Skip to content

Commit

Permalink
Merge pull request #1 from embik/create-config-dir
Browse files Browse the repository at this point in the history
cmd: create configuration directory if it does not exist
  • Loading branch information
embik authored Nov 20, 2023
2 parents 0c01063 + 08deb26 commit 1095308
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kubeconfig-bikeshed"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

authors = ["Marvin Beckers <[email protected]>"]
Expand Down
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ mod kubeconfig;
use env_logger::Builder;
use log::{self, SetLoggerError};
use std::error::Error;
use std::fs;
use std::process;

fn main() -> Result<(), Box<dyn Error>> {
let matches = cmd::cli().get_matches();
let config_path = config::get_config_path()?;

setup_logger(matches.get_flag("verbose"))?;
log::debug!("using {} as config path", config_path.display());
log::debug!("using {} as configuration directory", config_path.display());

if !config_path.is_dir() {
log::debug!("creating configuration directory as it does not exist");
fs::create_dir_all(&config_path).or_else(
|err: std::io::Error| -> Result<(), Box<dyn Error>> {
log::error!("failed to create directory: {err}");
process::exit(1);
},
)?;
}

cmd::execute(&config_path, matches.subcommand())
}
Expand Down

0 comments on commit 1095308

Please sign in to comment.