Add a search command
This commit is contained in:
parent
8423cc1240
commit
0c459e2770
5 changed files with 80 additions and 12 deletions
34
readme.md
34
readme.md
|
@ -24,9 +24,10 @@ cargo install jirac
|
|||
Usage: jirac <COMMAND>
|
||||
|
||||
Commands:
|
||||
create Create a ticket
|
||||
list Find tickets currently assigned to you
|
||||
init Setup the configuration
|
||||
create Create an issue
|
||||
list Find issues currently assigned to you
|
||||
search Search for issues
|
||||
init Set up the configuration
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
Options:
|
||||
|
@ -68,7 +69,7 @@ jirac create ticket.md
|
|||
jirac create --project KEY
|
||||
```
|
||||
|
||||
## Listing tickets
|
||||
### Listing tickets
|
||||
|
||||
```
|
||||
Find tickets currently assigned to you
|
||||
|
@ -80,6 +81,29 @@ Options:
|
|||
-h, --help Print help
|
||||
```
|
||||
|
||||
### Search for tickets
|
||||
|
||||
```
|
||||
Search for issues
|
||||
|
||||
Usage: jirac search [OPTIONS] <JQL>
|
||||
|
||||
Arguments:
|
||||
<JQL> A JQL string
|
||||
|
||||
Options:
|
||||
--json Print JSON rather than pretty print
|
||||
-h, --help Print help
|
||||
```
|
||||
|
||||
Use [JQL](https://support.atlassian.com/jira-software-cloud/docs/use-advanced-search-with-jira-query-language-jql/) to search for Issues.
|
||||
|
||||
*Find all in-progress tickets in a project*
|
||||
|
||||
```
|
||||
jirac search 'project = KEY AND status = "In Progress" ORDER BY created DESC'
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Get the following information:
|
||||
|
@ -88,7 +112,7 @@ Get the following information:
|
|||
* You email
|
||||
* [An API key](https://id.atlassian.com/manage-profile/security/api-tokens)
|
||||
|
||||
Then run the the `jirac init` command
|
||||
Then run the `jirac init` command
|
||||
|
||||
```
|
||||
Setup the configuration
|
||||
|
|
24
src/cli.rs
24
src/cli.rs
|
@ -10,27 +10,37 @@ pub struct Cli {
|
|||
|
||||
#[derive(Subcommand)]
|
||||
pub enum Commands {
|
||||
/// Create a ticket
|
||||
/// Create an issue
|
||||
Create {
|
||||
/// The project key in which to create the ticket
|
||||
/// The project key in which to create the issue
|
||||
#[arg(long)]
|
||||
project: Option<String>,
|
||||
|
||||
/// Open the new ticket in a browser
|
||||
/// Open the new issue in a browser
|
||||
#[arg(long)]
|
||||
open: bool,
|
||||
|
||||
/// A markdown file
|
||||
/// A Markdown file
|
||||
#[arg(value_name = "MARKDOWN_FILE")]
|
||||
markdown_file: Option<PathBuf>,
|
||||
},
|
||||
/// Find tickets currently assigned to you
|
||||
/// Find issues currently assigned to you
|
||||
List {
|
||||
/// Print json rather than pretty print
|
||||
/// Print JSON rather than pretty print
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
},
|
||||
/// Setup the configuration
|
||||
/// Search for issues
|
||||
Search {
|
||||
/// Print JSON rather than pretty print
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
|
||||
/// A JQL string
|
||||
#[arg(value_name = "JQL")]
|
||||
jql: String,
|
||||
},
|
||||
/// Set up the configuration
|
||||
Init {
|
||||
/// Jira instance URL
|
||||
#[arg(long)]
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
pub mod create;
|
||||
pub mod list;
|
||||
pub mod search;
|
||||
|
|
32
src/cmd/search.rs
Normal file
32
src/cmd/search.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use crate::jira_config::JiraConfig;
|
||||
use crate::types::issue::{display_issues_json, display_issues_pretty};
|
||||
|
||||
pub async fn exec(json: bool, jql: String) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = JiraConfig::load().map_err(|e| format!("Configuration error: {}", e))?;
|
||||
if !json {
|
||||
println!("Searching for issues...");
|
||||
}
|
||||
|
||||
match crate::jql::run(&config, &jql).await {
|
||||
Ok(response) => {
|
||||
if json {
|
||||
if response.issues.is_empty() {
|
||||
println!("[]");
|
||||
} else {
|
||||
display_issues_json(&response.issues)?;
|
||||
}
|
||||
} else if response.issues.is_empty() {
|
||||
println!("No results found for query.");
|
||||
} else {
|
||||
display_issues_pretty(&response.issues)?;
|
||||
println!("Total issues: {}", response.total);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error fetching issues: {}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -19,6 +19,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
markdown_file,
|
||||
} => cmd::create::create(project, open, markdown_file).await?,
|
||||
Commands::List { json } => cmd::list::list(json).await?,
|
||||
Commands::Search { json, jql } => cmd::search::exec(json, jql).await?,
|
||||
Commands::Init { url, email, token } => {
|
||||
JiraConfig::init(url, email, token).await?;
|
||||
println!("Configuration initialized successfully!");
|
||||
|
|
Loading…
Reference in a new issue