Compare commits
4 commits
f05461f1f7
...
7af1f40188
Author | SHA1 | Date | |
---|---|---|---|
7af1f40188 | |||
086dbb8af0 | |||
054d66bf9c | |||
a3352aa892 |
6 changed files with 47 additions and 9 deletions
|
@ -12,6 +12,7 @@ pub struct Cli {
|
|||
pub enum FormatMode {
|
||||
Pretty,
|
||||
Json,
|
||||
Compact,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for FormatMode {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::cli::FormatMode;
|
||||
use crate::jira_config::JiraConfig;
|
||||
use crate::types::issue::{display_issues_json, display_issues_pretty};
|
||||
use crate::types::issue::{display_issues_compact, display_issues_json, display_issues_pretty};
|
||||
|
||||
pub async fn exec(output: FormatMode, jql: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = JiraConfig::load().map_err(|e| format!("Configuration error: {}", e))?;
|
||||
|
@ -26,6 +26,10 @@ pub async fn exec(output: FormatMode, jql: &str) -> Result<(), Box<dyn std::erro
|
|||
}
|
||||
(FormatMode::Json, false) => display_issues_json(&result.issues)?,
|
||||
(FormatMode::Json, true) => println!("[]"),
|
||||
(FormatMode::Compact, false) => display_issues_compact(&result.issues)?,
|
||||
(FormatMode::Compact, true) => {
|
||||
println!("No results found for query.");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::cli::FormatMode;
|
||||
use crate::jira_config::JiraConfig;
|
||||
use crate::term::hyperlink;
|
||||
use crate::types::issue::JiraIssue;
|
||||
use crossterm::style::{Color, Stylize};
|
||||
use std::io::Write;
|
||||
|
@ -99,9 +100,11 @@ fn pretty_print(issue: &JiraIssue) -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
println!("\n== Actions {:=<69}", "");
|
||||
println!(
|
||||
"\u{1b}]8;;{}\u{7}{}\u{1b}]8;;\u{7}",
|
||||
issue.href,
|
||||
"Open Issue".green().underline(Color::Green)
|
||||
"{}",
|
||||
hyperlink(
|
||||
&issue.href,
|
||||
&"Open Issue".green().underline(Color::Green).to_string()
|
||||
)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
@ -142,6 +145,7 @@ pub async fn exec(output: FormatMode, issue_key: &str) -> Result<(), Box<dyn std
|
|||
match output {
|
||||
FormatMode::Pretty => pretty_print(&fetched_issue)?,
|
||||
FormatMode::Json => json_print(&fetched_issue)?,
|
||||
FormatMode::Compact => todo!(),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -2,6 +2,7 @@ mod cli;
|
|||
mod cmd;
|
||||
mod jira_config;
|
||||
mod jql;
|
||||
mod term;
|
||||
mod types;
|
||||
|
||||
use clap::Parser;
|
||||
|
@ -19,7 +20,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
markdown_file,
|
||||
} => cmd::create::create(project, open, markdown_file).await?,
|
||||
Commands::List { output } => {
|
||||
let jql = "assignee = currentUser() AND resolution = Unresolved order by updated DESC";
|
||||
let jql =
|
||||
"assignee = currentUser() AND resolution = Unresolved order by project,updated ASC";
|
||||
cmd::search::exec(output, jql).await?
|
||||
}
|
||||
Commands::Search { output, jql } => cmd::search::exec(output, &jql).await?,
|
||||
|
|
3
src/term.rs
Normal file
3
src/term.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub fn hyperlink(url: &str, text: &str) -> String {
|
||||
format!("\u{1b}]8;;{}\u{7}{}\u{1b}]8;;\u{7}", url, text)
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
use crossterm::style::Stylize;
|
||||
use crate::term::hyperlink;
|
||||
use crossterm::style::{Color, Stylize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::Write;
|
||||
|
||||
|
@ -107,9 +108,8 @@ pub fn display_issues_pretty(issues: &[JiraIssue]) -> Result<(), Box<dyn std::er
|
|||
)?;
|
||||
writeln!(
|
||||
tw,
|
||||
"\u{1b}]8;;{}\u{7}{}\u{1b}]8;;\u{7}",
|
||||
issue.href,
|
||||
"Open Issue".green()
|
||||
"{}",
|
||||
&hyperlink(&issue.href, &"Open Issue".green().to_string())
|
||||
)?;
|
||||
|
||||
tw.flush().unwrap();
|
||||
|
@ -122,6 +122,30 @@ pub fn display_issues_pretty(issues: &[JiraIssue]) -> Result<(), Box<dyn std::er
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn display_issues_compact(issues: &[JiraIssue]) -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Found {} issues:", issues.len());
|
||||
println!("{:-<80}", "");
|
||||
|
||||
let mut tw = tabwriter::TabWriter::new(vec![]);
|
||||
for issue in issues {
|
||||
writeln!(
|
||||
tw,
|
||||
"{}:\t{}",
|
||||
hyperlink(
|
||||
&issue.href,
|
||||
&issue.key.clone().blue().underline(Color::Blue).to_string()
|
||||
),
|
||||
issue.fields.summary.clone().green()
|
||||
)?;
|
||||
}
|
||||
|
||||
tw.flush().unwrap();
|
||||
let written = String::from_utf8(tw.into_inner().unwrap()).unwrap();
|
||||
print!("{}", written);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn display_issues_json(issues: &[JiraIssue]) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let j = serde_json::to_string_pretty(issues)?;
|
||||
println!("{}", j);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue