mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-04 10:50:39 +08:00
bin: Allow executing rad silently
This commit is contained in:
@@ -22,7 +22,7 @@ use cli::terminal::{Args, Error, Help};
|
||||
|
||||
use crate::cob;
|
||||
use crate::commands::tui_issue::common::IssueOperation;
|
||||
use crate::terminal;
|
||||
use crate::terminal::{self, Quiet};
|
||||
use crate::ui::TerminalInfo;
|
||||
|
||||
lazy_static! {
|
||||
@@ -234,17 +234,19 @@ pub async fn run(options: Options, ctx: impl Context) -> anyhow::Result<()> {
|
||||
if let Some(operation) = selection.operation.clone() {
|
||||
match operation {
|
||||
IssueOperation::Show { id } => {
|
||||
let _ = terminal::run_rad(
|
||||
terminal::run_rad(
|
||||
Some("issue"),
|
||||
&["show".into(), id.to_string().into()],
|
||||
);
|
||||
Quiet::No,
|
||||
)?;
|
||||
break;
|
||||
}
|
||||
IssueOperation::Edit { id } => {
|
||||
let _ = terminal::run_rad(
|
||||
terminal::run_rad(
|
||||
Some("issue"),
|
||||
&["edit".into(), id.to_string().into(), "--quiet".into()],
|
||||
);
|
||||
&["edit".into(), id.to_string().into()],
|
||||
Quiet::Yes,
|
||||
)?;
|
||||
}
|
||||
IssueOperation::Comment {
|
||||
id,
|
||||
@@ -272,7 +274,7 @@ pub async fn run(options: Options, ctx: impl Context) -> anyhow::Result<()> {
|
||||
}
|
||||
}
|
||||
Operation::Other { args } => {
|
||||
let _ = crate::terminal::run_rad(Some("issue"), &args);
|
||||
terminal::run_rad(Some("issue"), &args, Quiet::No)?;
|
||||
}
|
||||
Operation::Unknown { .. } => {
|
||||
anyhow::bail!("unknown operation provided");
|
||||
|
||||
+14
-10
@@ -20,6 +20,7 @@ use radicle_cli::terminal::args::{string, Args, Error, Help};
|
||||
|
||||
use crate::cob::patch;
|
||||
use crate::commands::tui_patch::common::PatchOperation;
|
||||
use crate::terminal::Quiet;
|
||||
|
||||
pub const HELP: Help = Help {
|
||||
name: "patch",
|
||||
@@ -266,22 +267,25 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
|
||||
if let Some(operation) = selection.operation.clone() {
|
||||
match operation {
|
||||
PatchOperation::Show { id } => {
|
||||
let _ = crate::terminal::run_rad(
|
||||
crate::terminal::run_rad(
|
||||
Some("patch"),
|
||||
&[OsString::from("show"), OsString::from(id.to_string())],
|
||||
);
|
||||
&["show".into(), id.to_string().into()],
|
||||
Quiet::No,
|
||||
)?;
|
||||
}
|
||||
PatchOperation::Diff { id } => {
|
||||
let _ = crate::terminal::run_rad(
|
||||
crate::terminal::run_rad(
|
||||
Some("patch"),
|
||||
&[OsString::from("diff"), OsString::from(id.to_string())],
|
||||
);
|
||||
&["diff".into(), id.to_string().into()],
|
||||
Quiet::No,
|
||||
)?;
|
||||
}
|
||||
PatchOperation::Checkout { id } => {
|
||||
let _ = crate::terminal::run_rad(
|
||||
crate::terminal::run_rad(
|
||||
Some("patch"),
|
||||
&[OsString::from("checkout"), OsString::from(id.to_string())],
|
||||
);
|
||||
&["checkout".into(), id.to_string().into()],
|
||||
Quiet::No,
|
||||
)?;
|
||||
}
|
||||
PatchOperation::_Review { id } => {
|
||||
let opts = ReviewOptions::default();
|
||||
@@ -308,7 +312,7 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
|
||||
interface::review(opts.clone(), profile, rid, patch_id).await?;
|
||||
}
|
||||
Operation::Other { args } => {
|
||||
let _ = crate::terminal::run_rad(Some("patch"), &args);
|
||||
crate::terminal::run_rad(Some("patch"), &args, Quiet::No)?;
|
||||
}
|
||||
Operation::Unknown { .. } => {
|
||||
anyhow::bail!("unknown operation provided");
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ use radicle_cli::terminal as cli_term;
|
||||
use commands::*;
|
||||
use terminal as term;
|
||||
|
||||
use crate::terminal::ForwardError;
|
||||
use crate::terminal::{ForwardError, Quiet};
|
||||
|
||||
pub const NAME: &str = "rad-tui";
|
||||
pub const DESCRIPTION: &str = "Radicle terminal interfaces";
|
||||
@@ -224,7 +224,7 @@ fn run_other(command: Option<&str>, args: &[OsString]) -> Result<(), Error> {
|
||||
args.to_vec(),
|
||||
);
|
||||
}
|
||||
command => term::run_rad(command, args).map_err(|err| err.into()),
|
||||
command => term::run_rad(command, args, Quiet::No).map_err(|err| err.into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-4
@@ -12,6 +12,11 @@ use radicle_cli::terminal::io;
|
||||
use radicle_cli::terminal::patch::Message;
|
||||
use radicle_cli::terminal::{Args, Command, DefaultContext, Error, Help};
|
||||
|
||||
pub enum Quiet {
|
||||
Yes,
|
||||
No,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ForwardError {
|
||||
#[error("an internal error occured while executing 'rad'")]
|
||||
@@ -20,8 +25,15 @@ pub enum ForwardError {
|
||||
Io(#[from] std::io::Error),
|
||||
}
|
||||
|
||||
fn _run_rad(args: &[OsString]) -> Result<(), ForwardError> {
|
||||
let status = process::Command::new("rad").args(args).status();
|
||||
fn _run_rad(args: &[OsString], quiet: Quiet) -> Result<(), ForwardError> {
|
||||
let status = match quiet {
|
||||
Quiet::Yes => process::Command::new("rad")
|
||||
.args(args)
|
||||
.stdout(process::Stdio::null())
|
||||
.stderr(process::Stdio::null())
|
||||
.status(),
|
||||
Quiet::No => process::Command::new("rad").args(args).status(),
|
||||
};
|
||||
|
||||
match status {
|
||||
Ok(status) => {
|
||||
@@ -34,14 +46,14 @@ fn _run_rad(args: &[OsString]) -> Result<(), ForwardError> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_rad(command: Option<&str>, args: &[OsString]) -> Result<(), ForwardError> {
|
||||
pub fn run_rad(command: Option<&str>, args: &[OsString], quiet: Quiet) -> Result<(), ForwardError> {
|
||||
let args = if let Some(command) = command {
|
||||
[vec![command.into()], args.to_vec()].concat()
|
||||
} else {
|
||||
args.to_vec()
|
||||
};
|
||||
|
||||
_run_rad(&args)
|
||||
_run_rad(&args, quiet)
|
||||
}
|
||||
|
||||
pub fn run_command_args<A, C>(help: Help, cmd: C, args: Vec<OsString>) -> !
|
||||
|
||||
Reference in New Issue
Block a user