From 09384255dbad0dc7e5c08ae5640cbc8b54967ceb Mon Sep 17 00:00:00 2001 From: Ashley Lewis Date: Fri, 6 Sep 2019 17:11:52 -0500 Subject: [PATCH] Wee refactors --- src/commands/kv/key/key_list.rs | 34 ++++++++++++--------------------- src/commands/kv/key/list.rs | 8 ++++---- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/commands/kv/key/key_list.rs b/src/commands/kv/key/key_list.rs index f42b1aad3..09d913bc0 100644 --- a/src/commands/kv/key/key_list.rs +++ b/src/commands/kv/key/key_list.rs @@ -13,10 +13,9 @@ pub struct KeyList { keys_result: Option>, prefix: Option, client: HttpApiClient, - project: Project, + account_id: String, namespace_id: String, cursor: Option, - pub error: Option, } impl KeyList { @@ -30,44 +29,35 @@ impl KeyList { keys_result: None, prefix: prefix.map(str::to_string), client, - project: project.to_owned(), + account_id: project.account_id.to_owned(), namespace_id: namespace_id.to_string(), cursor: None, - error: None, } } fn request_params(&self) -> ListNamespaceKeys { - ListNamespaceKeys { - account_identifier: &self.project.account_id, - namespace_identifier: &self.namespace_id, - params: self.params(), - } - } - - fn params(&self) -> ListNamespaceKeysParams { - ListNamespaceKeysParams { + let params = ListNamespaceKeysParams { limit: None, // Defaults to 1000 (the maximum) cursor: None, prefix: self.prefix.to_owned(), + }; + + ListNamespaceKeys { + account_identifier: &self.account_id, + namespace_identifier: &self.namespace_id, + params: params, } } fn get_batch(&mut self) -> Option> { let response = self.client.request(&self.request_params()); - let mut result; - let mut error = None; - - match response { + let (mut result, error) = match response { Ok(success) => { - result = success.result; self.cursor = extract_cursor(success.result_info.clone()); + (success.result, None) } - Err(e) => { - result = Vec::new(); - error = Some(e); - } + Err(e) => (Vec::new(), Some(e)), }; if let Some(error) = error { diff --git a/src/commands/kv/key/list.rs b/src/commands/kv/key/list.rs index 40d789d2f..70605d0c6 100644 --- a/src/commands/kv/key/list.rs +++ b/src/commands/kv/key/list.rs @@ -20,15 +20,15 @@ pub fn list( print!("["); // Open json list bracket - let mut first_page = true; + let mut first_key = true; for key_result in key_list { match key_result { Ok(key) => { - if !(first_page) { - print!(","); + if first_key { + first_key = false; } else { - first_page = false; + print!(","); } print!("{}", serde_json::to_string(&key)?);