jirust_cli/
utils.rs

1pub mod changelog_extractor;
2pub mod json_printer;
3pub mod macros;
4pub mod table_printer;
5
6use jira_v3_openapi::models::{
7    CreatedIssue, FieldCreateMetadata, IssueBean, IssueTransition, IssueTypeIssueCreateMetadata,
8    Project, Version, VersionRelatedWork,
9};
10use serde::Serialize;
11use serde_json::Value;
12
13use crate::args::commands::{OutputTypes, OutputValues};
14
15/// Enum to hold the different types of data that can be printed in a table
16///
17/// # Variants
18///
19/// * `IssueType` - Jira Issue types available in a project data
20/// * `IssueTypeField` - Fields available for a specific issue type in a project data
21/// * `Project` - Projects available in Jira data
22/// * `Version` - Versions available in a project data
23/// * `IssueCreated` - Issues created in a project data
24/// * `IssueTransition` - Issues transitions in a project data
25/// * `TransitionedIssue` - Issues transitioned data
26/// * `VersionRelatedWork` - Version related work items data
27#[derive(Serialize)]
28pub enum PrintableData {
29    Generic {
30        data: Vec<Value>,
31    },
32    IssueCreated {
33        issues: Vec<CreatedIssue>,
34    },
35    IssueData {
36        issues: Vec<IssueBean>,
37    },
38    IssueTransitions {
39        transitions: Vec<IssueTransition>,
40    },
41    IssueType {
42        issue_types: Vec<IssueTypeIssueCreateMetadata>,
43    },
44    IssueTypeField {
45        issue_type_fields: Vec<FieldCreateMetadata>,
46    },
47    Project {
48        projects: Vec<Project>,
49    },
50    TransitionedIssue {
51        issues: Vec<(String, String, String, String)>,
52    },
53    Version {
54        versions: Vec<Version>,
55    },
56    VersionRelatedWork {
57        version_related_work_items: Vec<VersionRelatedWork>,
58    },
59}
60
61#[derive(Clone)]
62pub enum OutputType {
63    Full,
64    Basic,
65    Single,
66}
67
68impl From<OutputTypes> for OutputType {
69    fn from(output_type: OutputTypes) -> Self {
70        match output_type {
71            OutputTypes::Full => OutputType::Full,
72            OutputTypes::Basic => OutputType::Basic,
73            OutputTypes::Single => OutputType::Single,
74        }
75    }
76}
77
78pub fn print_data(data: PrintableData, output_format: OutputValues, output_type: OutputType) {
79    match output_format {
80        OutputValues::Json => {
81            json_printer::print_json(data);
82        }
83        OutputValues::Table => match output_type {
84            OutputType::Full => {
85                table_printer::print_table_full(data);
86            }
87            OutputType::Basic => {
88                table_printer::print_table_basic(data);
89            }
90            OutputType::Single => {
91                table_printer::print_table_single(data);
92            }
93        },
94    }
95}