Skip to main content

twodo/
cli.rs

1#![deny(missing_docs)]
2
3use std::path::PathBuf;
4
5use clap::{Args, Parser, Subcommand};
6
7/// Twodo CLI
8#[derive(Parser, Debug)]
9#[command(author, version, about, long_about = None)]
10pub struct Cli {
11    /// Operation for twodo
12    #[command(subcommand)]
13    pub op: Option<Op>,
14}
15
16/// Operations on twodos
17#[derive(Subcommand, Debug)]
18pub enum Op {
19    /// List all twodo
20    List(ListArg),
21
22    /// Add a twodo
23    Add(AddArg),
24
25    /// Complete a twodo
26    Done,
27
28    /// Edit a twodo
29    Edit(EditArg),
30
31    /// Delete a twodo
32    Delete(DeleteArg),
33}
34
35/// List arguments for twodo
36#[derive(Debug, Default, Args)]
37pub struct ListArg {
38    /// Output format
39    #[arg(short, long)]
40    output: Option<bool>,
41
42    /// Number of twodo to list
43    #[arg(short)]
44    number: Option<usize>,
45}
46
47/// Add arguments for twodo
48#[derive(Args, Debug)]
49pub struct AddArg {
50    /// Title of twodo
51    pub title: String,
52
53    /// Description for twodo
54    #[arg(short, long, requires = "title")]
55    pub description: Option<String>,
56}
57
58/// Edit arguments for twodo
59#[derive(Debug, Args)]
60pub struct EditArg {
61    /// Id of twodo to edit
62    pub id: i64,
63
64    /// Title of twodo
65    #[arg(short, long)]
66    pub title: Option<String>,
67
68    /// Description of twodo
69    #[arg(short, long)]
70    pub description: Option<String>,
71}
72
73/// Delete arguments for twodo
74#[derive(Debug, Args)]
75pub struct DeleteArg {
76    /// Id of twodo to delete
77    pub id: i64,
78}
79
80// region:    --- Tests
81
82#[cfg(test)]
83mod tests {
84    use super::*;
85
86    #[test]
87    fn verify_cli() {
88        use clap::CommandFactory;
89        Cli::command().debug_assert();
90    }
91}
92
93// endregion: --- Tests