patch-list: Return JSON output

This commit is contained in:
Erik Kundt
2024-01-17 15:34:50 +01:00
parent 109a240857
commit 2fa65d0025
5 changed files with 54 additions and 73 deletions
Generated
+18 -16
View File
@@ -987,7 +987,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex",
"syn 2.0.28",
"syn 2.0.48",
]
[[package]]
@@ -1495,18 +1495,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.66"
version = "1.0.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.32"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
@@ -1660,6 +1660,8 @@ dependencies = [
"radicle",
"radicle-surf",
"radicle-term",
"serde",
"serde_json",
"simple-logging",
"textwrap 0.16.0",
"thiserror",
@@ -1855,22 +1857,22 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.181"
version = "1.0.195"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d3e73c93c3240c0bda063c239298e633114c69a888c3e37ca8bb33f343e9890"
checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.181"
version = "1.0.195"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be02f6cb0cd3a5ec20bbcfbcbd749f57daddb1a0882dc2e46a6c236c90b977ed"
checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.48",
]
[[package]]
@@ -2111,7 +2113,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.28",
"syn 2.0.48",
]
[[package]]
@@ -2133,9 +2135,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.28"
version = "2.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
dependencies = [
"proc-macro2",
"quote",
@@ -2229,7 +2231,7 @@ checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.48",
]
[[package]]
@@ -2484,7 +2486,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.48",
"wasm-bindgen-shared",
]
@@ -2506,7 +2508,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.48",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
+2
View File
@@ -19,6 +19,8 @@ radicle = { git = "https://github.com/radicle-dev/heartwood" }
radicle-term = { git = "https://github.com/radicle-dev/heartwood", package = "radicle-term" }
radicle-surf = { version = "0.18.0" }
simple-logging = { version = "2.0.2" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
timeago = { version = "0.4.1" }
textwrap = { version = "0.16.0" }
thiserror = { version = "1" }
+5 -41
View File
@@ -8,7 +8,6 @@ mod select;
mod suite;
use std::ffi::OsString;
use std::process::Command;
use anyhow::anyhow;
@@ -17,8 +16,6 @@ use radicle_tui::{context, log, Window};
use crate::terminal;
use crate::terminal::args::{Args, Error, Help};
use self::list::PatchCommand;
pub const FPS: u64 = 60;
pub const HELP: Help = Help {
name: "patch",
@@ -92,45 +89,12 @@ pub fn run(options: Options, _ctx: impl terminal::Context) -> anyhow::Result<()>
log::enable(context.profile(), "patch", "list")?;
let mut app = list::App::new(context);
if let Some(command) = Window::default().run(&mut app, 1000 / FPS)? {
match command {
PatchCommand::Show(id) => {
match Command::new("rad")
.arg("patch")
.arg("show")
.arg(id.to_string())
.spawn()
{
Ok(_) => {}
Err(_) => {}
}
},
PatchCommand::Edit(id) => {
match Command::new("rad")
.arg("patch")
.arg("edit")
.arg(id.to_string())
.spawn()
{
Ok(_) => {}
Err(_) => {}
}
}
PatchCommand::Checkout(id) => {
match Command::new("rad")
.arg("patch")
.arg("checkout")
.arg(id.to_string())
.spawn()
{
Ok(_) => {}
Err(_) => {}
}
}
}
}
let command = Window::default().run(&mut app, 1000 / FPS)?;
let output = command
.map(|command| serde_json::to_string(&command).unwrap_or_default())
.unwrap_or_default();
// eprint!("{patch_id}");
eprint!("{output}");
}
Operation::Select => {
let context = context::Context::new(id)?.with_patches();
+16 -5
View File
@@ -8,8 +8,7 @@ mod ui;
use std::hash::Hash;
use anyhow::Result;
use radicle::cob::patch::PatchId;
use serde::{Serialize, Serializer};
use tuirealm::application::PollStrategy;
use tuirealm::event::Key;
@@ -25,10 +24,22 @@ use tui::{Exit, PageStack, Tui};
use page::ListView;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PatchId(radicle::cob::patch::PatchId);
impl Serialize for PatchId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&format!("{}", *self.0))
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub enum PatchCommand {
Show(PatchId),
Edit(PatchId),
Checkout(PatchId),
Show { id: PatchId },
Edit { id: PatchId },
Checkout { id: PatchId },
}
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
+13 -11
View File
@@ -58,37 +58,39 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<common::ui::PatchBrows
match result {
CmdResult::Submit(State::One(StateValue::Usize(selected))) => {
let item = self.items().get(selected)?;
Some(Message::Quit(Some(PatchCommand::Show(
item.id().to_owned(),
))))
Some(Message::Quit(Some(PatchCommand::Show {
id: super::PatchId(item.id().to_owned()),
})))
}
_ => None,
}
}
Event::Keyboard(KeyEvent {
code: Key::Char('e'), ..
code: Key::Char('e'),
..
}) => {
let result = self.perform(Cmd::Submit);
match result {
CmdResult::Submit(State::One(StateValue::Usize(selected))) => {
let item = self.items().get(selected)?;
Some(Message::Quit(Some(PatchCommand::Edit(
item.id().to_owned(),
))))
Some(Message::Quit(Some(PatchCommand::Edit {
id: super::PatchId(item.id().to_owned()),
})))
}
_ => None,
}
}
Event::Keyboard(KeyEvent {
code: Key::Char('c'), ..
code: Key::Char('c'),
..
}) => {
let result = self.perform(Cmd::Submit);
match result {
CmdResult::Submit(State::One(StateValue::Usize(selected))) => {
let item = self.items().get(selected)?;
Some(Message::Quit(Some(PatchCommand::Checkout(
item.id().to_owned(),
))))
Some(Message::Quit(Some(PatchCommand::Checkout {
id: super::PatchId(item.id().to_owned()),
})))
}
_ => None,
}