Skip to content

Commit

Permalink
feat: smoll setup for config
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakiyo committed Dec 10, 2023
1 parent 419adde commit 3119cbf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::util;
use anyhow::bail;
use clap::{ArgAction, Parser, Subcommand};
use std::path::PathBuf;

Expand Down Expand Up @@ -40,10 +41,22 @@ pub enum Commands {
}

impl Cli {
pub fn _get_config(&self) {
let _config_path = match &self.config {
pub fn get_config(&self) -> anyhow::Result<()> {
let config_path = match &self.config {
Some(t) => t.clone(),
None => util::default_config_path(),
};
// if we are searching for config in the default location
// or one provided by user
let is_default = self.config.is_some();
// if path was implicitly specified but does not exist, return error
// if we are using default location, then don't show err when not found
if !is_default && !config_path.exists() {
bail!(
"Config file does not exist in specified path: {}",
config_path.display()
);
}
Ok(())
}
}
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use atty::Stream;
use clap::Parser;
use cli::Cli;
use env_logger as logger;
use std::process;
use yansi::Paint;

mod cli;
mod util;

fn main() {
use cli::Cli;
let args = Cli::parse();

// configure log level
Expand All @@ -22,6 +23,13 @@ fn main() {
log::info!("disabling colors in output");
Paint::disable();
}
if let Err(e) = run(args) {
eprintln!("{e}");
process::exit(1);
}
}

println!("Hello World");
fn run(args: Cli) -> anyhow::Result<()> {
let _config = args.get_config()?;
Ok(())
}

0 comments on commit 3119cbf

Please sign in to comment.