Skip to content

Commit

Permalink
fix: handle no slop error
Browse files Browse the repository at this point in the history
  • Loading branch information
nyarthan committed Sep 17, 2023
1 parent d3ac671 commit 10fd767
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
50 changes: 50 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ edition = "2021"
bitwarden = { version = "0.3.0", features = ["secrets"] }
clap = { version = "4.4.2", features = ["derive", "cargo", "env"] }
clap-markdown = "0.1.3"
log = "0.4.20"
serde = "1.0.188"
simple_logger = { version = "4.2.0", default-features = false, features = [
"colors",
] }
tokio = { version = "1.32.0", features = ["full"] }
toml = "0.7.6"
uuid = "1.4.1"
12 changes: 8 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ impl Cli {
Cli { args }
}

pub fn get_program(&self) -> (String, Vec<String>) {
pub fn get_program(&self) -> Option<(String, Vec<String>)> {
let slop = &self.args.slop;
let program = &slop[0];
let args = slop[1..].to_vec();
match &slop.get(0) {
Some(program) => {
let args = slop[1..].to_vec();

(program.to_owned(), args)
Some((program.to_string(), args))
}
None => None,
}
}
}
7 changes: 4 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ impl Config {
.as_ref()
.ok_or_else(|| Error::NoProfileInput)?;

let profile_name = cli_args.profile.clone().unwrap_or_else(|| {
get_profile_from_env(env_var_names).expect("no profile")
});
let profile_name = cli_args
.profile
.clone()
.unwrap_or_else(|| get_profile_from_env(env_var_names).expect("no profile"));

let profile = self
.profiles
Expand Down
13 changes: 12 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use simple_logger::SimpleLogger;
use std::{
io::{self, Read, Write},
path::PathBuf,
Expand All @@ -22,11 +23,21 @@ use crate::{bitwarden::BitwardenClient, cli::Cli};

#[tokio::main(flavor = "current_thread")]
async fn main() {
SimpleLogger::new().init().unwrap();

// generate docs
// let markdown: String = clap_markdown::help_markdown::<Args>();
// println!("{}", markdown);
let cli = Cli::new();
let (program, program_args) = cli.get_program();
let (program, program_args) = match cli.get_program() {
Some(t) => t,
None => {
log::error!("no slop provided");
std::process::exit(1)
}
};

println!("{:?}", program);

let config = Config::new();
let ConfigEvaluation {
Expand Down

0 comments on commit 10fd767

Please sign in to comment.