Skip to content
Permalink
Browse files

Add user list

  • Loading branch information...
Raggaer committed Jun 2, 2019
1 parent 986be0c commit 940c55557b9826d128ca2089b15bc0124552d102
Showing with 44 additions and 1 deletion.
  1. +1 −0 src/command/list/mod.rs
  2. +29 −0 src/command/list/user.rs
  3. +14 −1 src/command/mod.rs
@@ -1 +1,2 @@
pub mod item;
pub mod user;
@@ -0,0 +1,29 @@
use std::error;
use std::option;
use std::string;

pub fn execute_list_user_command() -> Result<(), Box<dyn error::Error>> {
// Retrieve JSON
let stdout = match crate::command::execute_command_stdout(
"op",
vec!["list".to_string(), "users".to_string()],
) {
Ok(out) => out,
Err(e) => return Err(e),
};
parse_list_user_output(stdout)
}

fn parse_list_user_output(output: String) -> Result<(), Box<dyn error::Error>> {
let list: Vec<crate::command::OpUser> = serde_json::from_str(&output)?;
for (i, user) in list.iter().enumerate() {
println!("UUID: {}", user.uuid);
println!("First Name: {}", user.firstName);
if i < list.len() - 1 {
println!("Email: {}\r\n", user.email);
} else {
println!("Email: {}", user.email);
}
}
Ok(())
}
@@ -42,6 +42,14 @@ struct OpField {
value: String,
}

#[derive(Serialize, Deserialize, Debug)]
struct OpUser {
uuid: String,
firstName: String,
lastName: String,
email: String,
}

impl Default for OpDetails {
fn default() -> Self {
OpDetails { fields: vec![] }
@@ -81,11 +89,16 @@ pub fn execute_list_command(
) {
match sub {
Some(s) => match s.as_str() {
"item" => {
"items" => {
if let Err(e) = crate::command::list::item::execute_list_item_command(search) {
eprintln!("{}", e);
}
}
"users" => {
if let Err(e) = crate::command::list::user::execute_list_user_command() {
eprintln!("{}", e);
}
}
sub => eprintln!("Unkown subcommand '{}'", sub),
},
None => {

0 comments on commit 940c555

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