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:
parent
6349c1c559
commit
3323082ce3
|
|
@ -58,6 +58,10 @@ Label options
|
||||||
|
|
||||||
Note: --add takes precedence over --delete
|
Note: --add takes precedence over --delete
|
||||||
|
|
||||||
|
Show options
|
||||||
|
|
||||||
|
--debug Show the issue as Rust debug output
|
||||||
|
|
||||||
Options
|
Options
|
||||||
|
|
||||||
--no-announce Don't announce issue to peers
|
--no-announce Don't announce issue to peers
|
||||||
|
|
@ -106,6 +110,7 @@ pub enum Operation {
|
||||||
Show {
|
Show {
|
||||||
id: Rev,
|
id: Rev,
|
||||||
format: Format,
|
format: Format,
|
||||||
|
debug: bool,
|
||||||
},
|
},
|
||||||
Comment {
|
Comment {
|
||||||
id: Rev,
|
id: Rev,
|
||||||
|
|
@ -177,6 +182,7 @@ impl Args for Options {
|
||||||
let mut reply_to = None;
|
let mut reply_to = None;
|
||||||
let mut announce = true;
|
let mut announce = true;
|
||||||
let mut quiet = false;
|
let mut quiet = false;
|
||||||
|
let mut debug = false;
|
||||||
let mut assign_opts = AssignOptions::default();
|
let mut assign_opts = AssignOptions::default();
|
||||||
let mut label_opts = LabelOptions::default();
|
let mut label_opts = LabelOptions::default();
|
||||||
|
|
||||||
|
|
@ -185,6 +191,8 @@ impl Args for Options {
|
||||||
Long("help") | Short('h') => {
|
Long("help") | Short('h') => {
|
||||||
return Err(Error::Help.into());
|
return Err(Error::Help.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List options.
|
||||||
Long("all") if op.is_none() || op == Some(OperationName::List) => {
|
Long("all") if op.is_none() || op == Some(OperationName::List) => {
|
||||||
state = None;
|
state = None;
|
||||||
}
|
}
|
||||||
|
|
@ -201,6 +209,8 @@ impl Args for Options {
|
||||||
reason: CloseReason::Solved,
|
reason: CloseReason::Solved,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open options.
|
||||||
Long("title") if op == Some(OperationName::Open) => {
|
Long("title") if op == Some(OperationName::Open) => {
|
||||||
title = Some(parser.value()?.to_string_lossy().into());
|
title = Some(parser.value()?.to_string_lossy().into());
|
||||||
}
|
}
|
||||||
|
|
@ -217,6 +227,11 @@ impl Args for Options {
|
||||||
|
|
||||||
assignees.push(did);
|
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) => {
|
Long("closed") if op == Some(OperationName::State) => {
|
||||||
state = Some(State::Closed {
|
state = Some(State::Closed {
|
||||||
reason: CloseReason::Other,
|
reason: CloseReason::Other,
|
||||||
|
|
@ -230,6 +245,8 @@ impl Args for Options {
|
||||||
reason: CloseReason::Solved,
|
reason: CloseReason::Solved,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// React options.
|
||||||
Long("emoji") if op == Some(OperationName::React) => {
|
Long("emoji") if op == Some(OperationName::React) => {
|
||||||
if let Some(emoji) = parser.value()?.to_str() {
|
if let Some(emoji) = parser.value()?.to_str() {
|
||||||
reaction =
|
reaction =
|
||||||
|
|
@ -240,17 +257,8 @@ impl Args for Options {
|
||||||
let oid: String = parser.value()?.to_string_lossy().into();
|
let oid: String = parser.value()?.to_string_lossy().into();
|
||||||
comment_id = Some(oid.parse()?);
|
comment_id = Some(oid.parse()?);
|
||||||
}
|
}
|
||||||
Long("description") if op == Some(OperationName::Open) => {
|
|
||||||
description = Some(parser.value()?.to_string_lossy().into());
|
// Show options.
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Long("format") if op == Some(OperationName::Show) => {
|
Long("format") if op == Some(OperationName::Show) => {
|
||||||
let val = parser.value()?;
|
let val = parser.value()?;
|
||||||
let val = term::args::string(&val);
|
let val = term::args::string(&val);
|
||||||
|
|
@ -261,6 +269,11 @@ impl Args for Options {
|
||||||
_ => anyhow::bail!("unknown format '{val}'"),
|
_ => 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) => {
|
Long("message") | Short('m') if op == Some(OperationName::Comment) => {
|
||||||
let val = parser.value()?;
|
let val = parser.value()?;
|
||||||
let txt = term::args::string(&val);
|
let txt = term::args::string(&val);
|
||||||
|
|
@ -273,9 +286,6 @@ impl Args for Options {
|
||||||
|
|
||||||
reply_to = Some(rev);
|
reply_to = Some(rev);
|
||||||
}
|
}
|
||||||
Long("no-announce") => {
|
|
||||||
announce = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assign options
|
// Assign options
|
||||||
Short('a') | Long("add") if op == Some(OperationName::Assign) => {
|
Short('a') | Long("add") if op == Some(OperationName::Assign) => {
|
||||||
|
|
@ -286,6 +296,14 @@ impl Args for Options {
|
||||||
.delete
|
.delete
|
||||||
.insert(term::args::did(&parser.value()?)?);
|
.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
|
// Label options
|
||||||
Short('a') | Long("add") if matches!(op, Some(OperationName::Label)) => {
|
Short('a') | Long("add") if matches!(op, Some(OperationName::Label)) => {
|
||||||
|
|
@ -303,9 +321,14 @@ impl Args for Options {
|
||||||
label_opts.delete.insert(label);
|
label_opts.delete.insert(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Options.
|
||||||
|
Long("no-announce") => {
|
||||||
|
announce = false;
|
||||||
|
}
|
||||||
Long("quiet") | Short('q') => {
|
Long("quiet") | Short('q') => {
|
||||||
quiet = true;
|
quiet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value(val) if op.is_none() => match val.to_string_lossy().as_ref() {
|
Value(val) if op.is_none() => match val.to_string_lossy().as_ref() {
|
||||||
"c" | "comment" => op = Some(OperationName::Comment),
|
"c" | "comment" => op = Some(OperationName::Comment),
|
||||||
"w" | "show" => op = Some(OperationName::Show),
|
"w" | "show" => op = Some(OperationName::Show),
|
||||||
|
|
@ -350,6 +373,7 @@ impl Args for Options {
|
||||||
OperationName::Show => Operation::Show {
|
OperationName::Show => Operation::Show {
|
||||||
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
|
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
|
||||||
format,
|
format,
|
||||||
|
debug,
|
||||||
},
|
},
|
||||||
OperationName::State => Operation::State {
|
OperationName::State => Operation::State {
|
||||||
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
|
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();
|
term::comment::widget(&comment_id, comment, &profile).print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Operation::Show { id, format } => {
|
Operation::Show { id, format, debug } => {
|
||||||
let id = id.resolve(&repo.backend)?;
|
let id = id.resolve(&repo.backend)?;
|
||||||
let issue = issues
|
let issue = issues
|
||||||
.get(&id)?
|
.get(&id)?
|
||||||
.context("No issue with the given ID exists")?;
|
.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 } => {
|
Operation::State { id, state } => {
|
||||||
let id = id.resolve(&repo.backend)?;
|
let id = id.resolve(&repo.backend)?;
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ Show options
|
||||||
|
|
||||||
-p, --patch Show the actual patch diff
|
-p, --patch Show the actual patch diff
|
||||||
-v, --verbose Show additional information about the patch
|
-v, --verbose Show additional information about the patch
|
||||||
|
--debug Show the patch as Rust debug output
|
||||||
|
|
||||||
Diff options
|
Diff options
|
||||||
|
|
||||||
|
|
@ -206,6 +207,7 @@ pub enum Operation {
|
||||||
Show {
|
Show {
|
||||||
patch_id: Rev,
|
patch_id: Rev,
|
||||||
diff: bool,
|
diff: bool,
|
||||||
|
debug: bool,
|
||||||
},
|
},
|
||||||
Diff {
|
Diff {
|
||||||
patch_id: Rev,
|
patch_id: Rev,
|
||||||
|
|
@ -290,7 +292,6 @@ impl Operation {
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
pub op: Operation,
|
pub op: Operation,
|
||||||
pub announce: bool,
|
pub announce: bool,
|
||||||
pub push: bool,
|
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
pub quiet: bool,
|
pub quiet: bool,
|
||||||
pub authored: bool,
|
pub authored: bool,
|
||||||
|
|
@ -311,9 +312,9 @@ impl Args for Options {
|
||||||
let mut patch_id = None;
|
let mut patch_id = None;
|
||||||
let mut revision_id = None;
|
let mut revision_id = None;
|
||||||
let mut message = Message::default();
|
let mut message = Message::default();
|
||||||
let mut push = true;
|
|
||||||
let mut filter = Filter::default();
|
let mut filter = Filter::default();
|
||||||
let mut diff = false;
|
let mut diff = false;
|
||||||
|
let mut debug = false;
|
||||||
let mut undo = false;
|
let mut undo = false;
|
||||||
let mut reply_to: Option<Rev> = None;
|
let mut reply_to: Option<Rev> = None;
|
||||||
let mut checkout_opts = checkout::Options::default();
|
let mut checkout_opts = checkout::Options::default();
|
||||||
|
|
@ -341,17 +342,14 @@ impl Args for Options {
|
||||||
Long("no-announce") => {
|
Long("no-announce") => {
|
||||||
announce = false;
|
announce = false;
|
||||||
}
|
}
|
||||||
Long("push") => {
|
|
||||||
push = true;
|
|
||||||
}
|
|
||||||
Long("no-push") => {
|
|
||||||
push = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show options.
|
// Show options.
|
||||||
Long("patch") | Short('p') if op == Some(OperationName::Show) => {
|
Long("patch") | Short('p') if op == Some(OperationName::Show) => {
|
||||||
diff = true;
|
diff = true;
|
||||||
}
|
}
|
||||||
|
Long("debug") if op == Some(OperationName::Show) => {
|
||||||
|
debug = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Ready options.
|
// Ready options.
|
||||||
Long("undo") if op == Some(OperationName::Ready) => {
|
Long("undo") if op == Some(OperationName::Ready) => {
|
||||||
|
|
@ -570,6 +568,7 @@ impl Args for Options {
|
||||||
OperationName::Show => Operation::Show {
|
OperationName::Show => Operation::Show {
|
||||||
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
|
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
|
||||||
diff,
|
diff,
|
||||||
|
debug,
|
||||||
},
|
},
|
||||||
OperationName::Diff => Operation::Diff {
|
OperationName::Diff => Operation::Diff {
|
||||||
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
|
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
|
||||||
|
|
@ -633,7 +632,6 @@ impl Args for Options {
|
||||||
Ok((
|
Ok((
|
||||||
Options {
|
Options {
|
||||||
op,
|
op,
|
||||||
push,
|
|
||||||
verbose,
|
verbose,
|
||||||
quiet,
|
quiet,
|
||||||
announce,
|
announce,
|
||||||
|
|
@ -663,11 +661,16 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
list::run(f, authors, &repository, &profile)?;
|
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)?;
|
let patch_id = patch_id.resolve(&repository.backend)?;
|
||||||
show::run(
|
show::run(
|
||||||
&patch_id,
|
&patch_id,
|
||||||
diff,
|
diff,
|
||||||
|
debug,
|
||||||
options.verbose,
|
options.verbose,
|
||||||
&profile,
|
&profile,
|
||||||
&repository,
|
&repository,
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ fn patch_commits(patch: &patch::Patch, stored: &Repository) -> anyhow::Result<Ve
|
||||||
pub fn run(
|
pub fn run(
|
||||||
patch_id: &PatchId,
|
patch_id: &PatchId,
|
||||||
diff: bool,
|
diff: bool,
|
||||||
|
debug: bool,
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
stored: &Repository,
|
stored: &Repository,
|
||||||
|
|
@ -66,6 +67,12 @@ pub fn run(
|
||||||
let Some(patch) = patches.get(patch_id)? else {
|
let Some(patch) = patches.get(patch_id)? else {
|
||||||
anyhow::bail!("Patch `{patch_id}` not found");
|
anyhow::bail!("Patch `{patch_id}` not found");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
println!("{:#?}", patch);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let (_, revision) = patch.latest();
|
let (_, revision) = patch.latest();
|
||||||
let state = patch.state();
|
let state = patch.state();
|
||||||
let branches = common::branches(&revision.head(), workdir)?;
|
let branches = common::branches(&revision.head(), workdir)?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue