From 50ab8aabcec26d07f4b4d9652dbceac1b89a6b22 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 18 Apr 2020 05:18:45 -0400 Subject: implement edit command --- src/actions.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/actions.rs') diff --git a/src/actions.rs b/src/actions.rs index 60cc61d..634fa9a 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -102,6 +102,41 @@ fn add_once( Ok(()) } +pub fn edit( + access_token: &str, + refresh_token: &str, + id: &str, + name: &str, + username: Option<&str>, + password: Option<&str>, + notes: Option<&str>, +) -> Result> { + match edit_once(access_token, id, name, username, password, notes) { + Ok(()) => Ok(None), + Err(crate::error::Error::RequestUnauthorized) => { + let access_token = exchange_refresh_token(refresh_token)?; + edit_once(&access_token, id, name, username, password, notes)?; + Ok(Some(access_token)) + } + Err(e) => Err(e), + } +} + +fn edit_once( + access_token: &str, + id: &str, + name: &str, + username: Option<&str>, + password: Option<&str>, + notes: Option<&str>, +) -> Result<()> { + let config = crate::config::Config::load()?; + let client = + crate::api::Client::new(&config.base_url(), &config.identity_url()); + client.edit(access_token, id, name, username, password, notes)?; + Ok(()) +} + pub fn remove( access_token: &str, refresh_token: &str, -- cgit v1.2.3-54-g00ecf