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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
use clap::{Args, Parser, Subcommand, ValueEnum};

/// Command line arguments base
/// subcommands: Config, Version
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct JirustCliArgs {
    #[clap(subcommand)]
    pub subcmd: Commands,
}

/// Available CLI commands
/// Config, Project, Version
#[derive(Subcommand, Debug)]
pub enum Commands {
    Config(ConfigArgs),
    Project(ProjectArgs),
    Version(VersionArgs),
}

/// Available pagination command line arguments
///
/// * page_size: Option<i32>
/// * page_offset: Option<i64>
#[derive(Args, Debug)]
pub struct PaginationArgs {
    #[clap(
        long,
        short = 'l',
        value_name = "page_size",
        help = "page size for lists"
    )]
    pub page_size: Option<i32>,
    #[clap(
        long,
        short = 'o',
        value_name = "page_offset",
        help = "page offset for list"
    )]
    pub page_offset: Option<i64>,
}

/// Available configuration command line arguments
/// cfg_act: ConfigActionValues
///    Auth, Jira, Setup, Show
///
#[derive(Args, Debug)]
pub struct ConfigArgs {
    #[arg(
        value_name = "auth|jira|setup|show",
        help_heading = "Configuration management"
    )]
    pub cfg_act: ConfigActionValues,
}

/// Available configuration action values
/// Auth, Jira, Setup, Show
#[derive(ValueEnum, Debug, Clone, Copy)]
#[value(rename_all = "kebab-case")]
pub enum ConfigActionValues {
    #[value(name = "auth", help = "Set Jira API authentication (username, apikey)")]
    Auth,
    #[value(name = "jira", help = "Set Jira API base URL")]
    Jira,
    #[value(
        name = "setup",
        help = "Setup Jira API configuration (authentication data, jira base URL)"
    )]
    Setup,
    #[value(name = "show", help = "Show current configuration")]
    Show,
}

/// Available version command line arguments
/// version_act: VersionActionValues
///   Create, List, Update, Delete, Release, Archive
#[derive(Args, Debug)]
pub struct VersionArgs {
    #[arg(
        value_name = "create|list|update|delete|release",
        help_heading = "Jira Project versions (a.k.a \"Releases\") management"
    )]
    pub version_act: VersionActionValues,
    #[clap(
        long,
        short = 'k',
        value_name = "project_key",
        required = true,
        help = "Jira Project key"
    )]
    pub project_key: String,
    #[clap(long, short = 'i', value_name = "project_id", help = "Jira Project ID")]
    pub project_id: Option<i64>,
    #[clap(
        long,
        short = 'v',
        value_name = "version_id",
        help = "Jira Project version ID"
    )]
    pub version_id: Option<String>,
    #[clap(
        long,
        short = 'n',
        value_name = "version_name",
        help = "Jira Project version name"
    )]
    pub version_name: Option<String>,
    #[clap(
        long,
        short = 'd',
        value_name = "version_description",
        help = "Jira Project version description"
    )]
    pub version_description: Option<String>,
    #[clap(
        long,
        value_name = "version_start_date",
        help = "Jira Project version start date"
    )]
    pub version_start_date: Option<String>,
    #[clap(
        long,
        value_name = "version_release_date",
        help = "Jira Project version release date"
    )]
    pub version_release_date: Option<String>,
    #[clap(
        long,
        short = 'a',
        value_name = "version_archived",
        help = "Jira Project version archived"
    )]
    pub version_archived: Option<bool>,
    #[clap(
        long,
        short = 'r',
        value_name = "version_released",
        help = "Jira Project version released"
    )]
    pub version_released: Option<bool>,
    #[clap(flatten)]
    pub pagination: PaginationArgs,
}

/// Available version action values
/// Archive, Create, Delete, List, Release, Update
#[derive(ValueEnum, Debug, Clone, Copy)]
#[value(rename_all = "kebab-case")]
pub enum VersionActionValues {
    #[value(name = "archive", help = "Archive a Jira Project version")]
    Archive,
    #[value(name = "create", help = "Create a Jira Project version")]
    Create,
    #[value(name = "delete", help = "Delete a Jira Project version")]
    Delete,
    #[value(name = "list", help = "List Jira Project versions")]
    List,
    #[value(name = "release", help = "Release a Jira Project version")]
    Release,
    #[value(name = "update", help = "Update a Jira Project version")]
    Update,
}

/// Available project command line arguments
/// version_act: ProjectActionValues
/// GetIssueTypes, GetIssueTypeFields, List
#[derive(Args, Debug)]
pub struct ProjectArgs {
    #[arg(
        value_name = "get-issue-types|get-issue-type-fields|list",
        help_heading = "Jira Project management"
    )]
    pub project_act: ProjectActionValues,
    #[clap(
        long,
        short = 'k',
        value_name = "project_key",
        help = "Jira Project key"
    )]
    pub project_key: Option<String>,
    #[clap(
        long,
        short = 'i',
        value_name = "project_issue_type",
        help = "Jira Project issue type ID"
    )]
    pub project_issue_type: Option<String>,
    #[clap(flatten)]
    pub pagination: PaginationArgs,
}

/// Available project action values
/// GetIssueTypes, GetIssueTypeFields, List
#[derive(ValueEnum, Debug, Clone, Copy)]
#[value(rename_all = "kebab-case")]
pub enum ProjectActionValues {
    #[value(
        name = "get-issue-types",
        help = "Get Jira Project issue types by Jira project key"
    )]
    GetIssueTypes,
    #[value(
        name = "get-issue-type-fields",
        help = "Get Jira Project issue type fields by Jira project key and issue type ID"
    )]
    GetIssueTypeFields,
    #[value(name = "list", help = "List Jira Projects")]
    List,
}