Skip to content

Commit

Permalink
add list subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jun 23, 2021
1 parent 8864b3d commit c35616d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main.rs
Expand Up @@ -36,6 +36,11 @@ pub enum Subcommand {
#[structopt(name = "ENTRY_ID", help = "The entry id")]
entry_id: EntryId,
},
#[structopt(name = "list", about = "Lists the entries")]
List {
#[structopt(long = "page", name = "PAGE", help = "The page")]
page: Option<String>,
},
#[structopt(name = "update", about = "Updates the entry")]
Update {
#[structopt(name = "ENTRY_ID", help = "The entry id")]
Expand Down Expand Up @@ -87,6 +92,31 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let entry = client.get_entry(&entry_id).await?;
println!("{}", entry.to_json());
}
Subcommand::List { page } => {
let (next_page, entry_ids) = client.list_entries_in_page(page.as_deref()).await?;
println!(
"{}",
serde_json::Value::Object({
let mut map = serde_json::Map::new();
if let Some(next_page) = next_page {
map.insert(
"next_page".to_string(),
serde_json::Value::String(next_page),
);
}
map.insert(
"entry_ids".to_string(),
serde_json::Value::Array(
entry_ids
.into_iter()
.map(|entry_id| serde_json::Value::String(entry_id.to_string()))
.collect(),
),
);
map
})
);
}
Subcommand::Update {
entry_id,
content,
Expand Down

0 comments on commit c35616d

Please sign in to comment.