Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Wee refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleymichal committed Sep 6, 2019
1 parent 30000fb commit 15c8388
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
34 changes: 12 additions & 22 deletions src/commands/kv/key/key_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ pub struct KeyList {
keys_result: Option<Vec<Key>>,
prefix: Option<String>,
client: HttpApiClient,
project: Project,
account_id: String,
namespace_id: String,
cursor: Option<String>,
pub error: Option<ApiFailure>,
}

impl KeyList {
Expand All @@ -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<Result<Key, ApiFailure>> {
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 {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/kv/key/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if !(first_key) {
print!(",");
} else {
first_page = false;
first_key = false;
}

print!("{}", serde_json::to_string(&key)?);
Expand Down

0 comments on commit 15c8388

Please sign in to comment.