Skip to content

Commit

Permalink
Add user list
Browse files Browse the repository at this point in the history
  • Loading branch information
Raggaer committed Jun 2, 2019
1 parent 986be0c commit 940c555
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/command/list/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod item;
pub mod user;
29 changes: 29 additions & 0 deletions src/command/list/user.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
15 changes: 14 additions & 1 deletion src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![] }
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 940c555

Please sign in to comment.