pub(crate) mod attachment;
pub(crate) mod board;
pub(crate) mod changelog;
pub(crate) mod comment;
pub(crate) mod create;
pub(crate) mod delete;
pub(crate) mod edit;
pub(crate) mod field;
pub(crate) mod link;
pub(crate) mod project;
pub(crate) mod read;
pub(crate) mod search;
pub(crate) mod sprint;
pub(crate) mod transition;
pub(crate) mod write;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Parser)]
pub struct JiraCommand {
#[command(subcommand)]
pub command: JiraSubcommands,
}
#[derive(Subcommand)]
pub enum JiraSubcommands {
Read(read::ReadCommand),
Write(write::WriteCommand),
Edit(edit::EditCommand),
Search(search::SearchCommand),
Create(create::CreateCommand),
Transition(transition::TransitionCommand),
Comment(comment::CommentCommand),
Delete(delete::DeleteCommand),
Project(project::ProjectCommand),
Field(field::FieldCommand),
Board(board::BoardCommand),
Sprint(sprint::SprintCommand),
Link(link::LinkCommand),
Changelog(changelog::ChangelogCommand),
Attachment(attachment::AttachmentCommand),
}
impl JiraCommand {
pub async fn execute(self) -> Result<()> {
match self.command {
JiraSubcommands::Read(cmd) => cmd.execute().await,
JiraSubcommands::Write(cmd) => cmd.execute().await,
JiraSubcommands::Edit(cmd) => cmd.execute().await,
JiraSubcommands::Search(cmd) => cmd.execute().await,
JiraSubcommands::Create(cmd) => cmd.execute().await,
JiraSubcommands::Transition(cmd) => cmd.execute().await,
JiraSubcommands::Comment(cmd) => cmd.execute().await,
JiraSubcommands::Delete(cmd) => cmd.execute().await,
JiraSubcommands::Project(cmd) => cmd.execute().await,
JiraSubcommands::Field(cmd) => cmd.execute().await,
JiraSubcommands::Board(cmd) => cmd.execute().await,
JiraSubcommands::Sprint(cmd) => cmd.execute().await,
JiraSubcommands::Link(cmd) => cmd.execute().await,
JiraSubcommands::Changelog(cmd) => cmd.execute().await,
JiraSubcommands::Attachment(cmd) => cmd.execute().await,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::cli::atlassian::format::{ContentFormat, OutputFormat};
#[test]
fn jira_subcommands_read_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Read(read::ReadCommand {
key: "PROJ-1".to_string(),
output: None,
format: ContentFormat::Jfm,
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Read(_)));
}
#[test]
fn jira_subcommands_write_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Write(write::WriteCommand {
key: "PROJ-1".to_string(),
file: None,
format: ContentFormat::Jfm,
force: false,
dry_run: false,
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Write(_)));
}
#[test]
fn jira_subcommands_edit_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Edit(edit::EditCommand {
key: "PROJ-1".to_string(),
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Edit(_)));
}
#[test]
fn jira_subcommands_create_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Create(create::CreateCommand {
file: None,
format: ContentFormat::Jfm,
project: Some("PROJ".to_string()),
r#type: None,
summary: Some("Test".to_string()),
dry_run: false,
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Create(_)));
}
#[test]
fn jira_subcommands_search_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Search(search::SearchCommand {
jql: Some("project = PROJ".to_string()),
project: None,
assignee: None,
status: None,
limit: 50,
output: OutputFormat::Table,
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Search(_)));
}
#[test]
fn jira_subcommands_transition_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Transition(transition::TransitionCommand {
key: "PROJ-1".to_string(),
transition: Some("Done".to_string()),
list: false,
output: OutputFormat::Table,
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Transition(_)));
}
#[test]
fn jira_subcommands_comment_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Comment(comment::CommentCommand {
command: comment::CommentSubcommands::List(comment::ListCommand {
key: "PROJ-1".to_string(),
output: OutputFormat::Table,
}),
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Comment(_)));
}
#[test]
fn jira_subcommands_delete_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Delete(delete::DeleteCommand {
key: "PROJ-1".to_string(),
force: true,
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Delete(_)));
}
#[test]
fn jira_subcommands_project_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Project(project::ProjectCommand {
command: project::ProjectSubcommands::List(project::ListCommand {
limit: 50,
output: OutputFormat::Table,
}),
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Project(_)));
}
#[test]
fn jira_subcommands_field_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Field(field::FieldCommand {
command: field::FieldSubcommands::List(field::ListCommand {
search: None,
output: OutputFormat::Table,
}),
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Field(_)));
}
#[test]
fn jira_subcommands_board_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Board(board::BoardCommand {
command: board::BoardSubcommands::List(board::ListCommand {
project: None,
r#type: None,
limit: 50,
output: OutputFormat::Table,
}),
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Board(_)));
}
#[test]
fn jira_subcommands_sprint_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Sprint(sprint::SprintCommand {
command: sprint::SprintSubcommands::List(sprint::ListCommand {
board_id: 1,
state: None,
limit: 50,
output: OutputFormat::Table,
}),
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Sprint(_)));
}
#[test]
fn jira_subcommands_link_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Link(link::LinkCommand {
command: link::LinkSubcommands::Types(link::TypesCommand {
output: OutputFormat::Table,
}),
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Link(_)));
}
#[test]
fn jira_subcommands_changelog_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Changelog(changelog::ChangelogCommand {
keys: "PROJ-1".to_string(),
limit: 50,
output: OutputFormat::Table,
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Changelog(_)));
}
#[test]
fn jira_subcommands_attachment_variant() {
let cmd = JiraCommand {
command: JiraSubcommands::Attachment(attachment::AttachmentCommand {
command: attachment::AttachmentSubcommands::Download(attachment::DownloadCommand {
key: "PROJ-1".to_string(),
output_dir: ".".to_string(),
filter: None,
}),
}),
};
assert!(matches!(cmd.command, JiraSubcommands::Attachment(_)));
}
}