|
7 | 7 | // SPDX-License-Identifier: MIT |
8 | 8 | // |
9 | 9 |
|
10 | | -use clap::{CommandFactory, Parser}; |
11 | | -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; |
12 | | -use plib::PROJECT_NAME; |
| 10 | +use std::collections::BTreeMap; |
| 11 | +use std::ffi::CStr; |
13 | 12 | use std::fs::{metadata, Metadata}; |
14 | 13 | use std::io::{self, Write}; |
| 14 | +use std::os::unix::fs::MetadataExt; |
| 15 | +use std::path::{Path, PathBuf}; |
15 | 16 | use std::sync::mpsc; |
16 | 17 | use std::thread; |
17 | 18 | use std::time::Duration; |
18 | | -use std::{ |
19 | | - collections::BTreeMap, |
20 | | - ffi::CStr, |
21 | | - os::unix::fs::MetadataExt, |
22 | | - path::{Path, PathBuf}, |
23 | | -}; |
| 19 | + |
| 20 | +use clap::{CommandFactory, Parser}; |
| 21 | +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; |
24 | 22 |
|
25 | 23 | const NAME_FIELD: usize = 20; |
26 | 24 |
|
@@ -1358,39 +1356,6 @@ struct Args { |
1358 | 1356 | /// A pathname on which the file or file system is to be reported. |
1359 | 1357 | file: Vec<PathBuf>, |
1360 | 1358 | } |
1361 | | -fn main() -> Result<(), Box<dyn std::error::Error>> { |
1362 | | - setlocale(LocaleCategory::LcAll, ""); |
1363 | | - textdomain(PROJECT_NAME)?; |
1364 | | - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; |
1365 | | - |
1366 | | - let Args { |
1367 | | - mount, user, file, .. |
1368 | | - } = Args::try_parse().unwrap_or_else(|err| match err.kind() { |
1369 | | - clap::error::ErrorKind::DisplayHelp | clap::error::ErrorKind::DisplayVersion => { |
1370 | | - print!("{err}"); |
1371 | | - std::process::exit(1); |
1372 | | - } |
1373 | | - _ => { |
1374 | | - let mut stdout = std::io::stdout(); |
1375 | | - let mut cmd = Args::command(); |
1376 | | - eprintln!("No process specification given"); |
1377 | | - cmd.write_help(&mut stdout).unwrap(); |
1378 | | - std::process::exit(1); |
1379 | | - } |
1380 | | - }); |
1381 | | - |
1382 | | - #[cfg(target_os = "linux")] |
1383 | | - let mut names = linux::get_matched_procs(file, mount)?; |
1384 | | - |
1385 | | - #[cfg(target_os = "macos")] |
1386 | | - let mut names = macos::get_matched_procs(file, mount)?; |
1387 | | - |
1388 | | - for name in names.iter_mut() { |
1389 | | - print_matches(name, user)?; |
1390 | | - } |
1391 | | - |
1392 | | - std::process::exit(0); |
1393 | | -} |
1394 | 1359 |
|
1395 | 1360 | /// Prints process matches for a given `Names` object to `stderr` and `stdout`. |
1396 | 1361 | /// |
@@ -1515,3 +1480,37 @@ fn timeout(path: &str, seconds: u32) -> Result<Metadata, io::Error> { |
1515 | 1480 | } |
1516 | 1481 | } |
1517 | 1482 | } |
| 1483 | + |
| 1484 | +fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 1485 | + setlocale(LocaleCategory::LcAll, ""); |
| 1486 | + textdomain(env!("PROJECT_NAME"))?; |
| 1487 | + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; |
| 1488 | + |
| 1489 | + let Args { |
| 1490 | + mount, user, file, .. |
| 1491 | + } = Args::try_parse().unwrap_or_else(|err| match err.kind() { |
| 1492 | + clap::error::ErrorKind::DisplayHelp | clap::error::ErrorKind::DisplayVersion => { |
| 1493 | + print!("{err}"); |
| 1494 | + std::process::exit(1); |
| 1495 | + } |
| 1496 | + _ => { |
| 1497 | + let mut stdout = std::io::stdout(); |
| 1498 | + let mut cmd = Args::command(); |
| 1499 | + eprintln!("No process specification given"); |
| 1500 | + cmd.write_help(&mut stdout).unwrap(); |
| 1501 | + std::process::exit(1); |
| 1502 | + } |
| 1503 | + }); |
| 1504 | + |
| 1505 | + #[cfg(target_os = "linux")] |
| 1506 | + let mut names = linux::get_matched_procs(file, mount)?; |
| 1507 | + |
| 1508 | + #[cfg(target_os = "macos")] |
| 1509 | + let mut names = macos::get_matched_procs(file, mount)?; |
| 1510 | + |
| 1511 | + for name in names.iter_mut() { |
| 1512 | + print_matches(name, user)?; |
| 1513 | + } |
| 1514 | + |
| 1515 | + std::process::exit(0); |
| 1516 | +} |
0 commit comments