cli: Add `--quiet` flag to `rad issue`

This commit is contained in:
Alexis Sellier 2023-04-18 11:21:56 +02:00
parent d74535a5a5
commit 86feebe4d8
No known key found for this signature in database
2 changed files with 21 additions and 3 deletions

View File

@ -31,6 +31,7 @@ Usage
rad id (accept|reject|close|commit) [--rev <revision-id>] [--no-confirm] [<option>...] rad id (accept|reject|close|commit) [--rev <revision-id>] [--no-confirm] [<option>...]
Options Options
--help Print help --help Print help
"#, "#,
}; };

View File

@ -35,6 +35,7 @@ Usage
Options Options
--no-announce Don't announce issue to peers --no-announce Don't announce issue to peers
--quiet, -q Don't print anything
--help Print help --help Print help
"#, "#,
}; };
@ -95,6 +96,7 @@ pub enum Operation {
pub struct Options { pub struct Options {
pub op: Operation, pub op: Operation,
pub announce: bool, pub announce: bool,
pub quiet: bool,
} }
impl Args for Options { impl Args for Options {
@ -111,6 +113,7 @@ impl Args for Options {
let mut state: Option<State> = None; let mut state: Option<State> = None;
let mut tags = Vec::new(); let mut tags = Vec::new();
let mut announce = true; let mut announce = true;
let mut quiet = false;
while let Some(arg) = parser.next()? { while let Some(arg) = parser.next()? {
match arg { match arg {
@ -160,6 +163,9 @@ impl Args for Options {
Long("no-announce") => { Long("no-announce") => {
announce = false; announce = false;
} }
Long("quiet") | Short('q') => {
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" | "show" => op = Some(OperationName::Show), "c" | "show" => op = Some(OperationName::Show),
"d" | "delete" => op = Some(OperationName::Delete), "d" | "delete" => op = Some(OperationName::Delete),
@ -203,7 +209,14 @@ impl Args for Options {
OperationName::List => Operation::List { assigned }, OperationName::List => Operation::List { assigned },
}; };
Ok((Options { op, announce }, vec![])) Ok((
Options {
op,
announce,
quiet,
},
vec![],
))
} }
} }
@ -231,8 +244,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
tags, tags,
} => { } => {
let issue = issues.create(title, description, tags.as_slice(), &[], &signer)?; let issue = issues.create(title, description, tags.as_slice(), &[], &signer)?;
if !options.quiet {
show_issue(&issue)?; show_issue(&issue)?;
} }
}
Operation::Show { id } => { Operation::Show { id } => {
let id = id.resolve(&repo.backend)?; let id = id.resolve(&repo.backend)?;
let issue = issues let issue = issues
@ -304,9 +319,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
.as_slice(), .as_slice(),
&signer, &signer,
)?; )?;
if !options.quiet {
show_issue(&issue)?; show_issue(&issue)?;
} }
} }
}
Operation::List { assigned } => { Operation::List { assigned } => {
let assignee = match assigned { let assignee = match assigned {
Some(Assigned::Me) => Some(*profile.id()), Some(Assigned::Me) => Some(*profile.id()),