Skip to content
Permalink
Browse files

Better error handling

  • Loading branch information...
Raggaer committed Jun 3, 2019
1 parent 2e0deac commit 89de1161114700c41527cb2e3d99fa7593fd32e8
Showing with 21 additions and 21 deletions.
  1. +1 −0 src/args.rs
  2. +0 −1 src/command/list/user.rs
  3. +20 −20 src/command/mod.rs
@@ -13,6 +13,7 @@ pub fn build_args() -> getopts::Options {
opts.optopt("i", "item", "Item, mostly for 'get item' calls", "");
opts.optopt("", "search", "Search term, mostly for 'list' calls", "");
opts.optopt("f", "fields", "List of fields to retrieve", "");
opts.optopt("", "vault", "Vault name", "");
opts
}

@@ -1,5 +1,4 @@
use std::error;
use std::option;
use std::string;

pub fn execute_list_user_command() -> Result<(), Box<dyn error::Error>> {
@@ -87,25 +87,23 @@ pub fn execute_list_command(
sub: option::Option<string::String>,
search: option::Option<string::String>,
) {
match sub {
let r = match sub {
Some(s) => match s.as_str() {
"items" => {
if let Err(e) = crate::command::list::item::execute_list_item_command(search) {
eprintln!("{}", e);
}
"items" => crate::command::list::item::execute_list_item_command(search),
"users" => crate::command::list::user::execute_list_user_command(),
sub => {
eprintln!("Unkown subcommand '{}'", sub);
Ok(())
}
"users" => {
if let Err(e) = crate::command::list::user::execute_list_user_command() {
eprintln!("{}", e);
}
}
sub => eprintln!("Unkown subcommand '{}'", sub),
},
None => {
eprintln!("Missing subcommand flag (-s)");
return;
Ok(())
}
};
if let Err(e) = r {
eprintln!("{}", e);
}
}

pub fn execute_get_command(
@@ -114,22 +112,24 @@ pub fn execute_get_command(
fields: option::Option<string::String>,
password_only: bool,
) {
match sub {
let r = match sub {
Some(s) => match s.as_str() {
"item" => {
if let Err(e) =
crate::command::get::item::execute_get_item_command(item, fields, password_only)
{
eprintln!("{}", e);
};
crate::command::get::item::execute_get_item_command(item, fields, password_only)
}
sub => {
eprintln!("Unkown subcommand '{}'", sub);
Ok(())
}
sub => eprintln!("Unkown subcommand '{}'", sub),
},
None => {
eprintln!("Missing subcommand flag (-s)");
return;
Ok(())
}
};
if let Err(e) = r {
eprintln!("{}", e);
}
}

pub fn execute_command_stdout(

0 comments on commit 89de116

Please sign in to comment.
You can’t perform that action at this time.