cli: show debug for patch and issue

It's useful to be able to print out the Rust data of a Radicle defined
COB for debugging purposes, since the current CLI commands will only
show a subset of the data.

Add `--debug` flags to `rad patch show` and `rad issue show` that
print the data to stdout.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2024-01-08 14:52:57 +00:00 committed by cloudhead
parent 6349c1c559
commit 3323082ce3
No known key found for this signature in database
3 changed files with 64 additions and 26 deletions

View File

@ -58,6 +58,10 @@ Label options
Note: --add takes precedence over --delete
Show options
--debug Show the issue as Rust debug output
Options
--no-announce Don't announce issue to peers
@ -106,6 +110,7 @@ pub enum Operation {
Show {
id: Rev,
format: Format,
debug: bool,
},
Comment {
id: Rev,
@ -177,6 +182,7 @@ impl Args for Options {
let mut reply_to = None;
let mut announce = true;
let mut quiet = false;
let mut debug = false;
let mut assign_opts = AssignOptions::default();
let mut label_opts = LabelOptions::default();
@ -185,6 +191,8 @@ impl Args for Options {
Long("help") | Short('h') => {
return Err(Error::Help.into());
}
// List options.
Long("all") if op.is_none() || op == Some(OperationName::List) => {
state = None;
}
@ -201,6 +209,8 @@ impl Args for Options {
reason: CloseReason::Solved,
});
}
// Open options.
Long("title") if op == Some(OperationName::Open) => {
title = Some(parser.value()?.to_string_lossy().into());
}
@ -217,6 +227,11 @@ impl Args for Options {
assignees.push(did);
}
Long("description") if op == Some(OperationName::Open) => {
description = Some(parser.value()?.to_string_lossy().into());
}
// State options.
Long("closed") if op == Some(OperationName::State) => {
state = Some(State::Closed {
reason: CloseReason::Other,
@ -230,6 +245,8 @@ impl Args for Options {
reason: CloseReason::Solved,
});
}
// React options.
Long("emoji") if op == Some(OperationName::React) => {
if let Some(emoji) = parser.value()?.to_str() {
reaction =
@ -240,17 +257,8 @@ impl Args for Options {
let oid: String = parser.value()?.to_string_lossy().into();
comment_id = Some(oid.parse()?);
}
Long("description") if op == Some(OperationName::Open) => {
description = Some(parser.value()?.to_string_lossy().into());
}
Long("assigned") | Short('a') if assigned.is_none() => {
if let Ok(val) = parser.value() {
let peer = term::args::did(&val)?;
assigned = Some(Assigned::Peer(peer));
} else {
assigned = Some(Assigned::Me);
}
}
// Show options.
Long("format") if op == Some(OperationName::Show) => {
let val = parser.value()?;
let val = term::args::string(&val);
@ -261,6 +269,11 @@ impl Args for Options {
_ => anyhow::bail!("unknown format '{val}'"),
}
}
Long("debug") if op == Some(OperationName::Show) => {
debug = true;
}
// Comment options.
Long("message") | Short('m') if op == Some(OperationName::Comment) => {
let val = parser.value()?;
let txt = term::args::string(&val);
@ -273,9 +286,6 @@ impl Args for Options {
reply_to = Some(rev);
}
Long("no-announce") => {
announce = false;
}
// Assign options
Short('a') | Long("add") if op == Some(OperationName::Assign) => {
@ -286,6 +296,14 @@ impl Args for Options {
.delete
.insert(term::args::did(&parser.value()?)?);
}
Long("assigned") | Short('a') if assigned.is_none() => {
if let Ok(val) = parser.value() {
let peer = term::args::did(&val)?;
assigned = Some(Assigned::Peer(peer));
} else {
assigned = Some(Assigned::Me);
}
}
// Label options
Short('a') | Long("add") if matches!(op, Some(OperationName::Label)) => {
@ -303,9 +321,14 @@ impl Args for Options {
label_opts.delete.insert(label);
}
// Options.
Long("no-announce") => {
announce = false;
}
Long("quiet") | Short('q') => {
quiet = true;
}
Value(val) if op.is_none() => match val.to_string_lossy().as_ref() {
"c" | "comment" => op = Some(OperationName::Comment),
"w" | "show" => op = Some(OperationName::Show),
@ -350,6 +373,7 @@ impl Args for Options {
OperationName::Show => Operation::Show {
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
format,
debug,
},
OperationName::State => Operation::State {
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
@ -442,12 +466,16 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
term::comment::widget(&comment_id, comment, &profile).print();
}
}
Operation::Show { id, format } => {
Operation::Show { id, format, debug } => {
let id = id.resolve(&repo.backend)?;
let issue = issues
.get(&id)?
.context("No issue with the given ID exists")?;
term::issue::show(&issue, &id, format, &profile)?;
if debug {
println!("{:#?}", issue);
} else {
term::issue::show(&issue, &id, format, &profile)?;
}
}
Operation::State { id, state } => {
let id = id.resolve(&repo.backend)?;

View File

@ -73,6 +73,7 @@ Show options
-p, --patch Show the actual patch diff
-v, --verbose Show additional information about the patch
--debug Show the patch as Rust debug output
Diff options
@ -206,6 +207,7 @@ pub enum Operation {
Show {
patch_id: Rev,
diff: bool,
debug: bool,
},
Diff {
patch_id: Rev,
@ -290,7 +292,6 @@ impl Operation {
pub struct Options {
pub op: Operation,
pub announce: bool,
pub push: bool,
pub verbose: bool,
pub quiet: bool,
pub authored: bool,
@ -311,9 +312,9 @@ impl Args for Options {
let mut patch_id = None;
let mut revision_id = None;
let mut message = Message::default();
let mut push = true;
let mut filter = Filter::default();
let mut diff = false;
let mut debug = false;
let mut undo = false;
let mut reply_to: Option<Rev> = None;
let mut checkout_opts = checkout::Options::default();
@ -341,17 +342,14 @@ impl Args for Options {
Long("no-announce") => {
announce = false;
}
Long("push") => {
push = true;
}
Long("no-push") => {
push = false;
}
// Show options.
Long("patch") | Short('p') if op == Some(OperationName::Show) => {
diff = true;
}
Long("debug") if op == Some(OperationName::Show) => {
debug = true;
}
// Ready options.
Long("undo") if op == Some(OperationName::Ready) => {
@ -570,6 +568,7 @@ impl Args for Options {
OperationName::Show => Operation::Show {
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
diff,
debug,
},
OperationName::Diff => Operation::Diff {
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
@ -633,7 +632,6 @@ impl Args for Options {
Ok((
Options {
op,
push,
verbose,
quiet,
announce,
@ -663,11 +661,16 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
}
list::run(f, authors, &repository, &profile)?;
}
Operation::Show { patch_id, diff } => {
Operation::Show {
patch_id,
diff,
debug,
} => {
let patch_id = patch_id.resolve(&repository.backend)?;
show::run(
&patch_id,
diff,
debug,
options.verbose,
&profile,
&repository,

View File

@ -56,6 +56,7 @@ fn patch_commits(patch: &patch::Patch, stored: &Repository) -> anyhow::Result<Ve
pub fn run(
patch_id: &PatchId,
diff: bool,
debug: bool,
verbose: bool,
profile: &Profile,
stored: &Repository,
@ -66,6 +67,12 @@ pub fn run(
let Some(patch) = patches.get(patch_id)? else {
anyhow::bail!("Patch `{patch_id}` not found");
};
if debug {
println!("{:#?}", patch);
return Ok(());
}
let (_, revision) = patch.latest();
let state = patch.state();
let branches = common::branches(&revision.head(), workdir)?;