-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
204 lines (190 loc) · 6.57 KB
/
build.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
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
/*
* Vento, a CLI inventory for your files.
* Copyright (C) 2022 Lux Aliaga
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use anyhow::Result;
use man::prelude::*;
use std::env;
use std::fs::{create_dir_all, File};
use std::io::Write;
struct Page {
content: String,
file: String,
}
fn main() -> Result<()> {
if cfg!(unix) {
let pages = [vento()?, take()?, drop()?, ventotoml()?];
let tempdir = env::temp_dir().join("vento-man");
create_dir_all(tempdir.clone())?;
for page in &pages {
let tempfile = tempdir.join(&page.file);
let mut file = File::create(tempfile).unwrap();
write!(&mut file, "{}", &page.content).unwrap();
}
}
Ok(())
}
fn vento() -> Result<Page> {
let content = Manual::new("vento")
.about("a CLI inventory for your files")
.author(Author::new("Lux Aliaga").email("[email protected]"))
.description("List files and directories in the currently active inventory, the files in SLOT, the files in DIRECTORY or the files in DIRECTORY in SLOT.")
.flag(
Flag::new()
.short("-c")
.long("--switch")
.help("Switches inventory slots"),
)
.flag(
Flag::new()
.short("-u")
.long("--undo")
.help("Undoes actions by a certain amount of steps"),
)
.flag(
Flag::new()
.short("-r")
.long("--redo")
.help("Redoes actions by a certain amount of steps"),
)
.flag(
Flag::new()
.short("-v")
.long("--view")
.help("Shows log of actions"),
)
.flag(
Flag::new()
.short("-m")
.long("--migrate")
.help("Migrates history file to database"),
)
.flag(
Flag::new()
.short("-e")
.long("--export-inv")
.help("Exports an inventory"),
)
.flag(
Flag::new()
.short("-E")
.long("--export-dir")
.help("Exports the Vento directory"),
)
.flag(
Flag::new()
.short("-g")
.long("--import-inv")
.help("Imports an inventory archive"),
)
.flag(
Flag::new()
.short("-G")
.long("--import-dir")
.help("Imports a Vento directory archive"),
)
.flag(
Flag::new()
.short("-i")
.long("--init")
.help("Initializes Vento with all its respective directories"),
)
.flag(
Flag::new()
.short("-h")
.long("--help")
.help("Shows the help message"),
)
.option(
Opt::new("slot")
.short("-s")
.long("--slot")
.help("The slot to list"),
)
.arg(Arg::new("[DIRECTORY]"))
.custom(
Section::new("before starting")
.paragraph("Vento will first need to initialize the respective directories before usage. Do this by running vento -i.")
)
.render();
Ok(Page {
content,
file: String::from("vento.1"),
})
}
fn take() -> Result<Page> {
let content = Manual::new("take")
.about("a file grabber for Vento")
.author(Author::new("Lux Aliaga").email("[email protected]"))
.description("Take FILE and put it in the inventory.")
.option(
Opt::new("slot")
.short("-s")
.long("--slot")
.help("The slot to put the file in"),
)
.arg(Arg::new("FILE"))
.render();
Ok(Page {
content,
file: String::from("take.1"),
})
}
fn drop() -> Result<Page> {
let content = Manual::new("drop")
.about("a file dropper for Vento")
.author(Author::new("Lux Aliaga").email("[email protected]"))
.description("Take FILE off the inventory and drop it in DESTINATION.")
.option(
Opt::new("slot")
.short("-s")
.long("--slot")
.help("The slot to take the file from"),
)
.arg(Arg::new("FILE"))
.arg(Arg::new("[DESTINATION]"))
.render();
Ok(Page {
content,
file: String::from("drop.1"),
})
}
fn ventotoml() -> Result<Page> {
let content = Manual::new("vento.toml")
.about("configuration file for Vento")
.author(Author::new("Lux Aliaga").email("[email protected]"))
.description("This is the configuration file for the vento(1), take(1) and drop(1) utilities. Its presence and all its directives are optional. Directives prefixed with \"name.directive\" indicate a separate section in config file, denoted by brackets.")
.custom (
Section::new("supported directives")
.paragraph("directory = \"PATH\": Changes the path in which Vento's inventories are saved in.")
.paragraph("display_emoji = (true | false): Sets whether emojis will be prefixed on messages or not.")
.paragraph("display_colors = (true | false): Sets whether messages will be colored.")
.paragraph("item.display_dir = (true | false): Sets whether item actions will show the paths involved in the operation.")
.paragraph("history.display_dir = (true | false): Sets whether history actions will show the paths involved in the operation.")
)
.custom (
Section::new("files")
.paragraph("Linux: $XDG_CONFIG_HOME/vento.toml")
.paragraph("macOS: $HOME/Library/Application Support/vento.toml")
.paragraph("Windows: {FOLDERID_RoamingAppData}\\\\vento.toml")
)
.render();
Ok(Page {
content,
file: String::from("vento.toml.1"),
})
}