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
//! Commands that *jobber* can process.
use super::prelude::*;
/// Encapsulates a duration or an end time.
#[derive(PartialEq, Clone, Debug)]
pub enum EndOrDuration {
/// None of both
None,
/// End time
End(DateTime),
/// Duration
Duration(Duration),
}
/// Commands which can be applied to jobber's database.
#[derive(PartialEq, Clone, Debug)]
pub enum Command {
Intro,
/// Start a new job by specifying start time if there is no open job-
Start {
start: DateTime,
message: Option<Option<String>>,
tags: Option<TagSet>,
},
/// Add a new job by specifying start and end time if there is no open job.
Add {
start: DateTime,
end: DateTime,
message: Option<Option<String>>,
tags: Option<TagSet>,
},
/// Like `Start` but re-use message an tags of previous job.
Back {
start: DateTime,
message: Option<Option<String>>,
tags: Option<TagSet>,
},
/// Like `Add` but re-use message an tags of previous job.
BackAdd {
start: DateTime,
end: DateTime,
message: Option<Option<String>>,
tags: Option<TagSet>,
},
/// End existing job by giving time.
End {
end: DateTime,
message: Option<Option<String>>,
tags: Option<TagSet>,
},
/// List jobs
List {
range: Range,
tags: Option<TagSet>,
},
/// Report jobs
Report {
range: Range,
tags: Option<TagSet>,
},
/// Report jobs as CSV
ExportCSV {
range: Range,
tags: Option<TagSet>,
columns: String,
},
/// Display whole configuration
ShowConfiguration,
/// change configuration
SetConfiguration {
tags: Option<TagSet>,
update: Properties,
},
/// Import CSV database of legacy Ruby *jobber* version
LegacyImport {
filename: String,
},
/// List all known tags
ListTags {
range: Range,
tags: Option<TagSet>,
},
/// Edit an existing job.
Edit {
pos: Option<usize>,
start: Option<DateTime>,
end: EndOrDuration,
message: Option<Option<String>>,
tags: Option<TagSet>,
},
/// Delete an existing job.
Delete {
range: Range,
tags: Option<TagSet>,
},
}
impl Command {
/// enrich this command by adding a message (or overwrite existing one)
pub fn set_message(&mut self, new_message: String) {
match *self {
Command::Start {
start: _,
ref mut message,
tags: _,
} => *message = Some(Some(new_message)),
Command::Add {
start: _,
end: _,
ref mut message,
tags: _,
} => *message = Some(Some(new_message)),
Command::Back {
start: _,
ref mut message,
tags: _,
} => *message = Some(Some(new_message)),
Command::BackAdd {
start: _,
end: _,
ref mut message,
tags: _,
} => *message = Some(Some(new_message)),
Command::End {
end: _,
ref mut message,
tags: _,
} => *message = Some(Some(new_message)),
_ => panic!("try to set message of command which has no message"),
}
}
}