cli: Add --quiet option to patch open

This commit is contained in:
Alexis Sellier
2023-04-26 16:42:58 +02:00
parent 182c9592c0
commit f111681dd6
3 changed files with 56 additions and 16 deletions
+13 -6
View File
@@ -85,6 +85,7 @@ pub fn run(
workdir: &git::raw::Repository,
message: term::patch::Message,
draft: bool,
quiet: bool,
options: Options,
) -> anyhow::Result<()> {
let mut patches = patch::Patches::open(storage)?;
@@ -107,9 +108,10 @@ pub fn run(
// to date, and error out, unless the user specifies manually the merge
// base.
show_patch_commit_info(workdir, profile.id(), &head_branch, &target_ref, target_oid)?;
term::blank();
if !quiet {
show_patch_commit_info(workdir, profile.id(), &head_branch, &target_ref, target_oid)?;
term::blank();
}
// TODO: List matching working copy refs for all targets.
@@ -139,8 +141,10 @@ pub fn run(
)
}?;
term::success!("Patch {} created", term::format::highlight(patch.id));
term::blank();
if !quiet {
term::success!("Patch {} created", term::format::highlight(patch.id));
term::blank();
}
if options.announce {
let mut node = Node::new(profile.socket());
@@ -153,10 +157,13 @@ pub fn run(
return Err(e.into());
}
}
} else {
} else if !quiet {
term::info!("To publish your patch to the network, run:");
term::indented(term::format::secondary("git push rad"));
}
if quiet {
term::print(patch.id);
}
Ok(())
}
+15 -6
View File
@@ -66,6 +66,7 @@ pub fn run(
workdir: &git::raw::Repository,
patch_id: Option<patch::PatchId>,
message: term::patch::Message,
quiet: bool,
options: &Options,
) -> anyhow::Result<()> {
// `HEAD`; This is what we are proposing as a patch.
@@ -87,11 +88,15 @@ pub fn run(
// TODO(cloudhead): Handle error.
let (_, current_revision) = patch.latest().unwrap();
if current_revision.head() == branch_oid(&head_branch)? {
term::info!("Nothing to do, patch is already up to date.");
if !quiet {
term::info!("Nothing to do, patch is already up to date.");
}
return Ok(());
}
show_update_commit_info(workdir, current_revision, &head_branch)?;
if !quiet {
show_update_commit_info(workdir, current_revision, &head_branch)?;
}
let head_oid = branch_oid(&head_branch)?;
let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
@@ -101,10 +106,14 @@ pub fn run(
let signer = term::signer(profile)?;
let revision = patch.update(message, base_oid, *head_oid, &signer)?;
term::success!(
"Patch updated to revision {}",
term::format::tertiary(revision),
);
if quiet {
term::print(revision);
} else {
term::success!(
"Patch updated to revision {}",
term::format::tertiary(revision),
);
}
if options.announce {
// TODO