+244
upload/Cargo.lock
+244
upload/Cargo.lock
···
3
version = 4
4
5
[[package]]
6
+
name = "anstream"
7
+
version = "0.6.21"
8
+
source = "registry+https://github.com/rust-lang/crates.io-index"
9
+
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
10
+
dependencies = [
11
+
"anstyle",
12
+
"anstyle-parse",
13
+
"anstyle-query",
14
+
"anstyle-wincon",
15
+
"colorchoice",
16
+
"is_terminal_polyfill",
17
+
"utf8parse",
18
+
]
19
+
20
+
[[package]]
21
+
name = "anstyle"
22
+
version = "1.0.13"
23
+
source = "registry+https://github.com/rust-lang/crates.io-index"
24
+
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
25
+
26
+
[[package]]
27
+
name = "anstyle-parse"
28
+
version = "0.2.7"
29
+
source = "registry+https://github.com/rust-lang/crates.io-index"
30
+
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
31
+
dependencies = [
32
+
"utf8parse",
33
+
]
34
+
35
+
[[package]]
36
+
name = "anstyle-query"
37
+
version = "1.1.4"
38
+
source = "registry+https://github.com/rust-lang/crates.io-index"
39
+
checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
40
+
dependencies = [
41
+
"windows-sys",
42
+
]
43
+
44
+
[[package]]
45
+
name = "anstyle-wincon"
46
+
version = "3.0.10"
47
+
source = "registry+https://github.com/rust-lang/crates.io-index"
48
+
checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
49
+
dependencies = [
50
+
"anstyle",
51
+
"once_cell_polyfill",
52
+
"windows-sys",
53
+
]
54
+
55
+
[[package]]
56
name = "atcities-upload"
57
version = "0.1.0"
58
+
dependencies = [
59
+
"clap",
60
+
]
61
+
62
+
[[package]]
63
+
name = "clap"
64
+
version = "4.5.49"
65
+
source = "registry+https://github.com/rust-lang/crates.io-index"
66
+
checksum = "f4512b90fa68d3a9932cea5184017c5d200f5921df706d45e853537dea51508f"
67
+
dependencies = [
68
+
"clap_builder",
69
+
"clap_derive",
70
+
]
71
+
72
+
[[package]]
73
+
name = "clap_builder"
74
+
version = "4.5.49"
75
+
source = "registry+https://github.com/rust-lang/crates.io-index"
76
+
checksum = "0025e98baa12e766c67ba13ff4695a887a1eba19569aad00a472546795bd6730"
77
+
dependencies = [
78
+
"anstream",
79
+
"anstyle",
80
+
"clap_lex",
81
+
"strsim",
82
+
]
83
+
84
+
[[package]]
85
+
name = "clap_derive"
86
+
version = "4.5.49"
87
+
source = "registry+https://github.com/rust-lang/crates.io-index"
88
+
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
89
+
dependencies = [
90
+
"heck",
91
+
"proc-macro2",
92
+
"quote",
93
+
"syn",
94
+
]
95
+
96
+
[[package]]
97
+
name = "clap_lex"
98
+
version = "0.7.6"
99
+
source = "registry+https://github.com/rust-lang/crates.io-index"
100
+
checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
101
+
102
+
[[package]]
103
+
name = "colorchoice"
104
+
version = "1.0.4"
105
+
source = "registry+https://github.com/rust-lang/crates.io-index"
106
+
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
107
+
108
+
[[package]]
109
+
name = "heck"
110
+
version = "0.5.0"
111
+
source = "registry+https://github.com/rust-lang/crates.io-index"
112
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
113
+
114
+
[[package]]
115
+
name = "is_terminal_polyfill"
116
+
version = "1.70.1"
117
+
source = "registry+https://github.com/rust-lang/crates.io-index"
118
+
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
119
+
120
+
[[package]]
121
+
name = "once_cell_polyfill"
122
+
version = "1.70.1"
123
+
source = "registry+https://github.com/rust-lang/crates.io-index"
124
+
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
125
+
126
+
[[package]]
127
+
name = "proc-macro2"
128
+
version = "1.0.101"
129
+
source = "registry+https://github.com/rust-lang/crates.io-index"
130
+
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
131
+
dependencies = [
132
+
"unicode-ident",
133
+
]
134
+
135
+
[[package]]
136
+
name = "quote"
137
+
version = "1.0.41"
138
+
source = "registry+https://github.com/rust-lang/crates.io-index"
139
+
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
140
+
dependencies = [
141
+
"proc-macro2",
142
+
]
143
+
144
+
[[package]]
145
+
name = "strsim"
146
+
version = "0.11.1"
147
+
source = "registry+https://github.com/rust-lang/crates.io-index"
148
+
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
149
+
150
+
[[package]]
151
+
name = "syn"
152
+
version = "2.0.106"
153
+
source = "registry+https://github.com/rust-lang/crates.io-index"
154
+
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
155
+
dependencies = [
156
+
"proc-macro2",
157
+
"quote",
158
+
"unicode-ident",
159
+
]
160
+
161
+
[[package]]
162
+
name = "unicode-ident"
163
+
version = "1.0.19"
164
+
source = "registry+https://github.com/rust-lang/crates.io-index"
165
+
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
166
+
167
+
[[package]]
168
+
name = "utf8parse"
169
+
version = "0.2.2"
170
+
source = "registry+https://github.com/rust-lang/crates.io-index"
171
+
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
172
+
173
+
[[package]]
174
+
name = "windows-link"
175
+
version = "0.2.1"
176
+
source = "registry+https://github.com/rust-lang/crates.io-index"
177
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
178
+
179
+
[[package]]
180
+
name = "windows-sys"
181
+
version = "0.60.2"
182
+
source = "registry+https://github.com/rust-lang/crates.io-index"
183
+
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
184
+
dependencies = [
185
+
"windows-targets",
186
+
]
187
+
188
+
[[package]]
189
+
name = "windows-targets"
190
+
version = "0.53.5"
191
+
source = "registry+https://github.com/rust-lang/crates.io-index"
192
+
checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
193
+
dependencies = [
194
+
"windows-link",
195
+
"windows_aarch64_gnullvm",
196
+
"windows_aarch64_msvc",
197
+
"windows_i686_gnu",
198
+
"windows_i686_gnullvm",
199
+
"windows_i686_msvc",
200
+
"windows_x86_64_gnu",
201
+
"windows_x86_64_gnullvm",
202
+
"windows_x86_64_msvc",
203
+
]
204
+
205
+
[[package]]
206
+
name = "windows_aarch64_gnullvm"
207
+
version = "0.53.1"
208
+
source = "registry+https://github.com/rust-lang/crates.io-index"
209
+
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
210
+
211
+
[[package]]
212
+
name = "windows_aarch64_msvc"
213
+
version = "0.53.1"
214
+
source = "registry+https://github.com/rust-lang/crates.io-index"
215
+
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
216
+
217
+
[[package]]
218
+
name = "windows_i686_gnu"
219
+
version = "0.53.1"
220
+
source = "registry+https://github.com/rust-lang/crates.io-index"
221
+
checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
222
+
223
+
[[package]]
224
+
name = "windows_i686_gnullvm"
225
+
version = "0.53.1"
226
+
source = "registry+https://github.com/rust-lang/crates.io-index"
227
+
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
228
+
229
+
[[package]]
230
+
name = "windows_i686_msvc"
231
+
version = "0.53.1"
232
+
source = "registry+https://github.com/rust-lang/crates.io-index"
233
+
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
234
+
235
+
[[package]]
236
+
name = "windows_x86_64_gnu"
237
+
version = "0.53.1"
238
+
source = "registry+https://github.com/rust-lang/crates.io-index"
239
+
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
240
+
241
+
[[package]]
242
+
name = "windows_x86_64_gnullvm"
243
+
version = "0.53.1"
244
+
source = "registry+https://github.com/rust-lang/crates.io-index"
245
+
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
246
+
247
+
[[package]]
248
+
name = "windows_x86_64_msvc"
249
+
version = "0.53.1"
250
+
source = "registry+https://github.com/rust-lang/crates.io-index"
251
+
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
+1
upload/Cargo.toml
+1
upload/Cargo.toml
-102
upload/src/config.rs
-102
upload/src/config.rs
···
1
-
use std::{fmt, fs};
2
-
3
-
#[derive(Debug)]
4
-
pub struct Config {
5
-
pub user: String,
6
-
pub pword: String,
7
-
pub dir: String,
8
-
}
9
-
10
-
#[derive(Debug)]
11
-
pub enum ConfigErr {
12
-
TooManyDirectories,
13
-
NotEnoughArgs(String),
14
-
UnknownArg(String),
15
-
NotADirectory,
16
-
}
17
-
18
-
impl fmt::Display for ConfigErr {
19
-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20
-
match self {
21
-
ConfigErr::TooManyDirectories => write!(f, "Too many directories"),
22
-
ConfigErr::NotEnoughArgs(args) => write!(f, "Missing {}", args),
23
-
ConfigErr::UnknownArg(arg) => write!(f, "Unknown arg {}", arg),
24
-
ConfigErr::NotADirectory => write!(f, "Not a directory"),
25
-
}
26
-
}
27
-
}
28
-
29
-
pub fn extract() -> Result<Config, ConfigErr> {
30
-
let mut user: Option<String> = None;
31
-
let mut pword: Option<String> = None;
32
-
let mut dir: Option<String> = None;
33
-
34
-
let mut args = std::env::args().into_iter();
35
-
// skip first arg
36
-
args.next();
37
-
while let Some(arg) = args.next() {
38
-
match arg.as_str() {
39
-
"--user" => user = args.next(),
40
-
"--password" => pword = args.next(),
41
-
_ => {
42
-
if arg.starts_with("--") {
43
-
return Err(ConfigErr::UnknownArg(arg));
44
-
}
45
-
if dir.is_some() {
46
-
return Err(ConfigErr::TooManyDirectories);
47
-
}
48
-
dir = Some(arg);
49
-
}
50
-
}
51
-
}
52
-
53
-
if let Some(user) = user.clone()
54
-
&& let Some(pword) = pword.clone()
55
-
&& let Some(dir) = dir.clone()
56
-
{
57
-
if let Ok(metadata) = fs::metadata(dir.clone())
58
-
&& metadata.is_dir()
59
-
{
60
-
return Ok(Config {
61
-
user,
62
-
pword,
63
-
dir: dir.to_owned(),
64
-
});
65
-
} else {
66
-
return Err(ConfigErr::NotADirectory);
67
-
}
68
-
}
69
-
70
-
return Err(ConfigErr::NotEnoughArgs(String::from(
71
-
// xxx
72
-
if user.is_none() && pword.is_none() && dir.is_none() {
73
-
"--user, --password, and <dir>"
74
-
}
75
-
// yxx
76
-
else if user.is_some() && pword.is_none() && dir.is_none() {
77
-
"--password and <dir>"
78
-
}
79
-
// xyx
80
-
else if user.is_none() && pword.is_some() && dir.is_none() {
81
-
"--user and <dir>"
82
-
}
83
-
// yyx
84
-
else if user.is_some() && pword.is_some() && dir.is_none() {
85
-
"<dir>"
86
-
}
87
-
// xxy
88
-
else if user.is_none() && pword.is_none() && dir.is_some() {
89
-
"--user and --password"
90
-
}
91
-
// yxy
92
-
else if user.is_some() && pword.is_none() && dir.is_some() {
93
-
"--password"
94
-
}
95
-
// xyy
96
-
else if user.is_none() && pword.is_some() && dir.is_some() {
97
-
"--user"
98
-
} else {
99
-
"Invalid State, as all values are provided here"
100
-
},
101
-
)));
102
-
}
···
+25
-9
upload/src/main.rs
+25
-9
upload/src/main.rs
···
1
-
mod config;
2
3
fn main() -> Result<(), ()> {
4
// get config items
5
-
let config = config::extract().or_else(|x| {
6
-
println!("{}", x);
7
-
Err(())
8
-
})?;
9
10
println!(
11
"user: {}
12
pword: {}
13
-
dir: {}",
14
-
config.user, config.pword, config.dir
15
);
16
17
-
// create session
18
-
19
// get local site info
20
21
// upload local site blobs
22
···
1
+
use clap::Parser;
2
+
use std::path::PathBuf;
3
+
4
+
#[derive(Parser, Debug)]
5
+
#[command(version, about, long_about = None)]
6
+
struct Config {
7
+
/// Handle or DID to authenticate
8
+
#[arg(verbatim_doc_comment, short, long)]
9
+
user: String,
10
+
/// App password to authenticate the client
11
+
/// Normal passwords also work but are not advised
12
+
#[arg(verbatim_doc_comment, short, long)]
13
+
password: String,
14
+
15
+
/// Directory to upload
16
+
#[arg(verbatim_doc_comment)]
17
+
dir: PathBuf,
18
+
}
19
20
fn main() -> Result<(), ()> {
21
// get config items
22
+
let config = Config::parse();
23
24
println!(
25
"user: {}
26
pword: {}
27
+
dir: {:?}",
28
+
config.user,
29
+
config.password,
30
+
config.dir.to_str(),
31
);
32
33
// get local site info
34
+
35
+
// create session
36
37
// upload local site blobs
38