cli: Add `--quiet` option to `patch open`
This commit is contained in:
parent
182c9592c0
commit
f111681dd6
|
|
@ -53,6 +53,7 @@ Show options
|
||||||
Open/Update options
|
Open/Update options
|
||||||
|
|
||||||
--draft Open patch in draft mode
|
--draft Open patch in draft mode
|
||||||
|
-q, --quiet Supress most output, only print the revision id
|
||||||
--[no-]announce Announce patch to network (default: false)
|
--[no-]announce Announce patch to network (default: false)
|
||||||
--[no-]push Push patch head to storage (default: true)
|
--[no-]push Push patch head to storage (default: true)
|
||||||
-m, --message [<string>] Provide a comment message to the patch or revision (default: prompt)
|
-m, --message [<string>] Provide a comment message to the patch or revision (default: prompt)
|
||||||
|
|
@ -88,6 +89,7 @@ pub enum Operation {
|
||||||
Open {
|
Open {
|
||||||
message: Message,
|
message: Message,
|
||||||
draft: bool,
|
draft: bool,
|
||||||
|
quiet: bool,
|
||||||
},
|
},
|
||||||
Show {
|
Show {
|
||||||
patch_id: Rev,
|
patch_id: Rev,
|
||||||
|
|
@ -96,6 +98,7 @@ pub enum Operation {
|
||||||
Update {
|
Update {
|
||||||
patch_id: Option<Rev>,
|
patch_id: Option<Rev>,
|
||||||
message: Message,
|
message: Message,
|
||||||
|
quiet: bool,
|
||||||
},
|
},
|
||||||
Archive {
|
Archive {
|
||||||
patch_id: Rev,
|
patch_id: Rev,
|
||||||
|
|
@ -135,6 +138,7 @@ impl Args for Options {
|
||||||
let mut filter = Some(patch::State::Open);
|
let mut filter = Some(patch::State::Open);
|
||||||
let mut diff = false;
|
let mut diff = false;
|
||||||
let mut draft = false;
|
let mut draft = false;
|
||||||
|
let mut quiet = false;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
match arg {
|
match arg {
|
||||||
|
|
@ -168,10 +172,15 @@ impl Args for Options {
|
||||||
push = false;
|
push = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open options.
|
// Open/update options.
|
||||||
Long("draft") if op == Some(OperationName::Open) => {
|
Long("draft") if op == Some(OperationName::Open) => {
|
||||||
draft = true;
|
draft = true;
|
||||||
}
|
}
|
||||||
|
Long("quiet") | Short('q')
|
||||||
|
if op == Some(OperationName::Open) || op == Some(OperationName::Update) =>
|
||||||
|
{
|
||||||
|
quiet = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Show options.
|
// Show options.
|
||||||
Long("patch") | Short('p') if op == Some(OperationName::Show) => {
|
Long("patch") | Short('p') if op == Some(OperationName::Show) => {
|
||||||
|
|
@ -229,7 +238,11 @@ impl Args for Options {
|
||||||
}
|
}
|
||||||
|
|
||||||
let op = match op.unwrap_or_default() {
|
let op = match op.unwrap_or_default() {
|
||||||
OperationName::Open => Operation::Open { message, draft },
|
OperationName::Open => Operation::Open {
|
||||||
|
message,
|
||||||
|
draft,
|
||||||
|
quiet,
|
||||||
|
},
|
||||||
OperationName::List => Operation::List { filter },
|
OperationName::List => Operation::List { filter },
|
||||||
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"))?,
|
||||||
|
|
@ -238,7 +251,11 @@ impl Args for Options {
|
||||||
OperationName::Delete => Operation::Delete {
|
OperationName::Delete => Operation::Delete {
|
||||||
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"))?,
|
||||||
},
|
},
|
||||||
OperationName::Update => Operation::Update { patch_id, message },
|
OperationName::Update => Operation::Update {
|
||||||
|
patch_id,
|
||||||
|
message,
|
||||||
|
quiet,
|
||||||
|
},
|
||||||
OperationName::Archive => Operation::Archive {
|
OperationName::Archive => Operation::Archive {
|
||||||
patch_id: patch_id.ok_or_else(|| anyhow!("a patch id must be provided"))?,
|
patch_id: patch_id.ok_or_else(|| anyhow!("a patch id must be provided"))?,
|
||||||
},
|
},
|
||||||
|
|
@ -274,13 +291,18 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match options.op {
|
match options.op {
|
||||||
Operation::Open { ref message, draft } => {
|
Operation::Open {
|
||||||
|
ref message,
|
||||||
|
draft,
|
||||||
|
quiet,
|
||||||
|
} => {
|
||||||
create::run(
|
create::run(
|
||||||
&repository,
|
&repository,
|
||||||
&profile,
|
&profile,
|
||||||
&workdir,
|
&workdir,
|
||||||
message.clone(),
|
message.clone(),
|
||||||
draft,
|
draft,
|
||||||
|
quiet,
|
||||||
options,
|
options,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
@ -294,6 +316,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
Operation::Update {
|
Operation::Update {
|
||||||
ref patch_id,
|
ref patch_id,
|
||||||
ref message,
|
ref message,
|
||||||
|
quiet,
|
||||||
} => {
|
} => {
|
||||||
let patch_id = patch_id
|
let patch_id = patch_id
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
@ -305,6 +328,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
&workdir,
|
&workdir,
|
||||||
patch_id,
|
patch_id,
|
||||||
message.clone(),
|
message.clone(),
|
||||||
|
quiet,
|
||||||
&options,
|
&options,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ pub fn run(
|
||||||
workdir: &git::raw::Repository,
|
workdir: &git::raw::Repository,
|
||||||
message: term::patch::Message,
|
message: term::patch::Message,
|
||||||
draft: bool,
|
draft: bool,
|
||||||
|
quiet: bool,
|
||||||
options: Options,
|
options: Options,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mut patches = patch::Patches::open(storage)?;
|
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
|
// to date, and error out, unless the user specifies manually the merge
|
||||||
// base.
|
// base.
|
||||||
|
|
||||||
|
if !quiet {
|
||||||
show_patch_commit_info(workdir, profile.id(), &head_branch, &target_ref, target_oid)?;
|
show_patch_commit_info(workdir, profile.id(), &head_branch, &target_ref, target_oid)?;
|
||||||
|
|
||||||
term::blank();
|
term::blank();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: List matching working copy refs for all targets.
|
// TODO: List matching working copy refs for all targets.
|
||||||
|
|
||||||
|
|
@ -139,8 +141,10 @@ pub fn run(
|
||||||
)
|
)
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
|
if !quiet {
|
||||||
term::success!("Patch {} created", term::format::highlight(patch.id));
|
term::success!("Patch {} created", term::format::highlight(patch.id));
|
||||||
term::blank();
|
term::blank();
|
||||||
|
}
|
||||||
|
|
||||||
if options.announce {
|
if options.announce {
|
||||||
let mut node = Node::new(profile.socket());
|
let mut node = Node::new(profile.socket());
|
||||||
|
|
@ -153,10 +157,13 @@ pub fn run(
|
||||||
return Err(e.into());
|
return Err(e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if !quiet {
|
||||||
term::info!("To publish your patch to the network, run:");
|
term::info!("To publish your patch to the network, run:");
|
||||||
term::indented(term::format::secondary("git push rad"));
|
term::indented(term::format::secondary("git push rad"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if quiet {
|
||||||
|
term::print(patch.id);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ pub fn run(
|
||||||
workdir: &git::raw::Repository,
|
workdir: &git::raw::Repository,
|
||||||
patch_id: Option<patch::PatchId>,
|
patch_id: Option<patch::PatchId>,
|
||||||
message: term::patch::Message,
|
message: term::patch::Message,
|
||||||
|
quiet: bool,
|
||||||
options: &Options,
|
options: &Options,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
// `HEAD`; This is what we are proposing as a patch.
|
// `HEAD`; This is what we are proposing as a patch.
|
||||||
|
|
@ -87,11 +88,15 @@ pub fn run(
|
||||||
// TODO(cloudhead): Handle error.
|
// TODO(cloudhead): Handle error.
|
||||||
let (_, current_revision) = patch.latest().unwrap();
|
let (_, current_revision) = patch.latest().unwrap();
|
||||||
if current_revision.head() == branch_oid(&head_branch)? {
|
if current_revision.head() == branch_oid(&head_branch)? {
|
||||||
|
if !quiet {
|
||||||
term::info!("Nothing to do, patch is already up to date.");
|
term::info!("Nothing to do, patch is already up to date.");
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !quiet {
|
||||||
show_update_commit_info(workdir, current_revision, &head_branch)?;
|
show_update_commit_info(workdir, current_revision, &head_branch)?;
|
||||||
|
}
|
||||||
|
|
||||||
let head_oid = branch_oid(&head_branch)?;
|
let head_oid = branch_oid(&head_branch)?;
|
||||||
let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
|
let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
|
||||||
|
|
@ -101,10 +106,14 @@ pub fn run(
|
||||||
let signer = term::signer(profile)?;
|
let signer = term::signer(profile)?;
|
||||||
let revision = patch.update(message, base_oid, *head_oid, &signer)?;
|
let revision = patch.update(message, base_oid, *head_oid, &signer)?;
|
||||||
|
|
||||||
|
if quiet {
|
||||||
|
term::print(revision);
|
||||||
|
} else {
|
||||||
term::success!(
|
term::success!(
|
||||||
"Patch updated to revision {}",
|
"Patch updated to revision {}",
|
||||||
term::format::tertiary(revision),
|
term::format::tertiary(revision),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if options.announce {
|
if options.announce {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue