|
2 | 2 | # Refract: App |
3 | 3 | */ |
4 | 4 |
|
5 | | -use argyle::Argument; |
6 | 5 | use crate::{ |
7 | 6 | Candidate, |
8 | 7 | Skin, |
@@ -242,37 +241,51 @@ impl App { |
242 | 241 | /// `--help` or `--version` were requested instead, in which case the |
243 | 242 | /// corresponding "error" is returned. |
244 | 243 | pub(super) fn new() -> Result<Self, RefractError> { |
| 244 | + argyle::argue! { |
| 245 | + ExitAuto "-e" "--exit-auto", |
| 246 | + Help "-h" "--help", |
| 247 | + NoAvif "--no-avif", |
| 248 | + NoJxl "--no-jxl", |
| 249 | + NoWebp "--no-webp", |
| 250 | + NoLossless "--no-lossless", |
| 251 | + NoLossy "--no-lossy", |
| 252 | + NoYcbcr "--no-ycbcr", |
| 253 | + SaveAuto "-s" "--save-auto", |
| 254 | + Version "-V" "--version", |
| 255 | + |
| 256 | + @options |
| 257 | + List "-l" "--list", |
| 258 | + |
| 259 | + @catchall-paths Path, |
| 260 | + } |
| 261 | + |
245 | 262 | let mut paths = Dowser::default(); |
246 | 263 | let mut flags = DEFAULT_FLAGS; |
247 | 264 |
|
248 | 265 | // Load CLI arguments, if any. |
249 | | - let args = argyle::args() |
250 | | - .with_keywords(include!(concat!(env!("OUT_DIR"), "/argyle.rs"))); |
251 | | - for arg in args { |
| 266 | + for arg in Argument::args_os() { |
252 | 267 | match arg { |
253 | | - Argument::Key("-e" | "--exit-auto") => { flags |= OTHER_EXIT_AUTO; }, |
254 | | - Argument::Key("-h" | "--help") => return Err(RefractError::PrintHelp), |
255 | | - Argument::Key("--no-avif") => { flags &= ! FMT_AVIF; }, |
256 | | - Argument::Key("--no-jxl") => { flags &= ! FMT_JXL; }, |
257 | | - Argument::Key("--no-webp") => { flags &= ! FMT_WEBP; }, |
258 | | - Argument::Key("--no-lossless") => { flags &= ! MODE_LOSSLESS; }, |
259 | | - Argument::Key("--no-lossy") => { flags &= ! MODE_LOSSY; }, |
260 | | - Argument::Key("--no-ycbcr") => { flags &= ! MODE_LOSSY_YCBCR; }, |
261 | | - Argument::Key("-s" | "--save-auto") => { flags |= OTHER_SAVE_AUTO; }, |
262 | | - Argument::Key("-V" | "--version") => return Err(RefractError::PrintVersion), |
263 | | - |
264 | | - Argument::KeyWithValue("-l" | "--list", s) => { |
265 | | - let _res = paths.push_paths_from_file(s); |
266 | | - }, |
267 | | - |
| 268 | + Argument::ExitAuto => { flags |= OTHER_EXIT_AUTO; }, |
| 269 | + Argument::Help => return Err(RefractError::PrintHelp), |
| 270 | + Argument::NoAvif => { flags &= ! FMT_AVIF; }, |
| 271 | + Argument::NoJxl => { flags &= ! FMT_JXL; }, |
| 272 | + Argument::NoWebp => { flags &= ! FMT_WEBP; }, |
| 273 | + Argument::NoLossless => { flags &= ! MODE_LOSSLESS; }, |
| 274 | + Argument::NoLossy => { flags &= ! MODE_LOSSY; }, |
| 275 | + Argument::NoYcbcr => { flags &= ! MODE_LOSSY_YCBCR; }, |
| 276 | + Argument::SaveAuto => { flags |= OTHER_SAVE_AUTO; }, |
| 277 | + Argument::Version => return Err(RefractError::PrintVersion), |
| 278 | + |
| 279 | + Argument::List(s) => |
| 280 | + if s == "-" { paths.push_paths_from_stdin(); } |
| 281 | + else { |
| 282 | + let _res = paths.push_paths_from_file(s); |
| 283 | + }, |
268 | 284 | Argument::Path(s) => { paths = paths.with_path(s); }, |
269 | 285 |
|
270 | 286 | // Mistake? |
271 | | - Argument::Other(s) => { cli_log_arg(&s); }, |
272 | | - Argument::InvalidUtf8(s) => { cli_log_arg(&s.to_string_lossy()); }, |
273 | | - |
274 | | - // Nothing else is relevant. |
275 | | - _ => {}, |
| 287 | + Argument::Other(s) => { cli_log_arg(&s); }, |
| 288 | + Argument::OtherOs(s) => { cli_log_arg(&s.to_string_lossy()); }, |
276 | 289 | } |
277 | 290 | } |
278 | 291 |
|
|
0 commit comments