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