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
|
use structopt::StructOpt;
use std::path::PathBuf;
#[derive(Debug, StructOpt)]
#[structopt(
author = "me",
name = "khalessi",
about = "Command line calendar tool."
)]
pub struct CommandLine {
/// verbosity
#[structopt(short = "v", parse(from_occurrences))]
pub verbosity: u64,
#[structopt(subcommand)]
pub cmd: Command,
}
#[derive(Debug, StructOpt)]
pub enum Command {
/// Show agenda view
#[structopt(name = "agenda")]
Agenda(Agenda),
/// Copy event
#[structopt(name = "copy")]
Copy,
/// Interact with the cursor
#[structopt(name = "cursor")]
Cursor(Cursor),
/// Delete event
#[structopt(name = "delete")]
Delete,
/// Edit event
#[structopt(name = "edit")]
Edit,
/// Rebuild index
#[structopt(name = "index")]
Index(Index),
}
#[derive(Debug, StructOpt)]
pub struct Agenda {
/// Show agenda view
#[structopt(name = "args")]
pub args: Vec<String>,
}
#[derive(Debug, StructOpt)]
pub struct Cursor {
/// Move the cursor on the selection. Uses "next" and "prev".
#[structopt(name = "direction")]
pub direction: Option<Direction>,
}
#[derive(Debug, StructOpt)]
pub enum Direction {
Next,
Prev,
}
impl std::str::FromStr for Direction{
type Err = String;
fn from_str(s: &str) -> Result<Self, <Self as std::str::FromStr>::Err> {
match s {
"prev" => Ok(Direction::Prev),
"next" => Ok(Direction::Next),
&_ => Err("Expected 'prev' or 'next'".to_string())
}
}
}
#[derive(Debug, StructOpt)]
pub struct Index {
/// Rebuild index
#[structopt(short = "r", long = "reindex")]
pub reindex: bool,
/// index path
#[structopt(name = "path", parse(from_os_str))]
pub path: Option<PathBuf>,
}
|