jirust_cli/
utils.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
pub mod changelog_extractor;
pub mod json_printer;
pub mod table_printer;

use jira_v3_openapi::models::{
    CreatedIssue, FieldCreateMetadata, IssueBean, IssueTransition, IssueTypeIssueCreateMetadata,
    Project, Version,
};
use serde_json::Value;

use crate::args::commands::OutputValues;

/// Enum to hold the different types of data that can be printed in a table
///
/// # Variants
///
/// * `IssueType` - Jira Issue types available in a project data
/// * `IssueTypeField` - Fields available for a specific issue type in a project data
/// * `Project` - Projects available in Jira data
/// * `Version` - Versions available in a project data
pub enum PrintableData {
    Generic {
        data: Vec<Value>,
    },
    IssueCreated {
        issues: Vec<CreatedIssue>,
    },
    IssueData {
        issues: Vec<IssueBean>,
    },
    IssueTransitions {
        transitions: Vec<IssueTransition>,
    },
    IssueType {
        issue_types: Vec<IssueTypeIssueCreateMetadata>,
    },
    IssueTypeField {
        issue_type_fields: Vec<FieldCreateMetadata>,
    },
    Project {
        projects: Vec<Project>,
    },
    TransitionedIssue {
        issues: Vec<(String, String, String, String)>,
    },
    Version {
        versions: Vec<Version>,
    },
}

pub enum OutputType {
    Full,
    Basic,
    Single,
}

pub fn print_data(data: PrintableData, output_format: OutputValues, output_type: OutputType) {
    match output_format {
        OutputValues::Json => {
            json_printer::print_json(data);
        }
        OutputValues::Table => match output_type {
            OutputType::Full => {
                table_printer::print_table_full(data);
            }
            OutputType::Basic => {
                table_printer::print_table_basic(data);
            }
            OutputType::Single => {
                table_printer::print_table_single(data);
            }
        },
    }
}