Adapt to uucore changes

This commit is contained in:
Daniel Hofstetter
2025-12-30 11:33:27 +01:00
parent 3bc066ae6e
commit 6c04c74911
34 changed files with 61 additions and 254 deletions
-7
View File
@@ -1,7 +0,0 @@
# free
```
free [options]
```
Display amount of free and used memory in the system
+3 -9
View File
@@ -18,13 +18,7 @@ use std::ops::Mul;
use std::process;
use std::thread::sleep;
use std::time::Duration;
use uucore::{
error::{UResult, USimpleError},
format_usage, help_about, help_usage,
};
const ABOUT: &str = help_about!("free.md");
const USAGE: &str = help_usage!("free.md");
use uucore::error::{UResult, USimpleError};
/// The unit of number is [UnitMultiplier::Bytes]
#[derive(Default, Clone)]
@@ -249,8 +243,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Display amount of free and used memory in the system")
.override_usage("free [options]")
.args_override_self(true)
.infer_long_args(true)
.disable_help_flag(true)
-7
View File
@@ -1,7 +0,0 @@
# pgrep
```
pgrep [options] <pattern>
```
look up, signal, or wait for processes based on name and other attributes
+3 -6
View File
@@ -8,10 +8,7 @@ pub mod process;
pub mod process_matcher;
use clap::{arg, crate_version, Command};
use uucore::{error::UResult, format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("pgrep.md");
const USAGE: &str = help_usage!("pgrep.md");
use uucore::error::UResult;
/// # Conceptual model of `pgrep`
///
@@ -74,8 +71,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("look up, signal, or wait for processes based on name and other attributes")
.override_usage("pgrep [options] <pattern>")
.args_override_self(true)
.args([
arg!(-d --delimiter <string> "specify output delimiter")
-7
View File
@@ -1,7 +0,0 @@
# pidof
```
pidof [options] [program [...]]
```
Find the process ID of a running program
+3 -6
View File
@@ -7,12 +7,9 @@ use std::path::PathBuf;
use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
use uu_pgrep::process::{walk_process, ProcessInformation};
use uucore::error::UResult;
#[cfg(unix)]
use uucore::process::geteuid;
use uucore::{error::UResult, format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("pidof.md");
const USAGE: &str = help_usage!("pidof.md");
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
@@ -147,8 +144,8 @@ fn collect_matched_pids(matches: &ArgMatches) -> Vec<usize> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Find the process ID of a running program")
.override_usage("pidof [options] [program [...]]")
.infer_long_args(true)
.arg(
Arg::new("program-name")
-7
View File
@@ -1,7 +0,0 @@
# pidwait
```
pidwait [options] pattern
```
Wait for processes based on name.
+3 -6
View File
@@ -5,14 +5,11 @@
use clap::{arg, crate_version, Command};
use uu_pgrep::process_matcher;
use uucore::{error::UResult, format_usage, help_about, help_usage};
use uucore::error::UResult;
use wait::wait;
mod wait;
const ABOUT: &str = help_about!("pidwait.md");
const USAGE: &str = help_usage!("pidwait.md");
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;
@@ -50,8 +47,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Wait for processes based on name")
.override_usage("pidwait [options] pattern")
.infer_long_args(true)
.args([arg!(-e --echo "display PIDs before waiting")])
.args(process_matcher::clap_args(
-7
View File
@@ -1,7 +0,0 @@
# pgrep
```
pkill [options] <pattern>
```
Kills processes based on name and other attributes.
+3 -6
View File
@@ -15,16 +15,13 @@ use std::io::Error;
#[cfg(unix)]
use uu_pgrep::process::ProcessInformation;
use uu_pgrep::process_matcher;
use uucore::error::UResult;
#[cfg(unix)]
use uucore::{
error::FromIo,
show,
signals::{signal_by_name_or_value, signal_name_by_value},
};
use uucore::{error::UResult, format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("pkill.md");
const USAGE: &str = help_usage!("pkill.md");
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
@@ -133,8 +130,8 @@ fn kill(pids: &Vec<ProcessInformation>, sig: Option<Signal>, queue: Option<u32>,
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Kills processes based on name and other attributes")
.override_usage("pkill [options] <pattern>")
.args_override_self(true)
.args([
// arg!(-<sig> "signal to send (either number or name)"),
-7
View File
@@ -1,7 +0,0 @@
# pmap
```
pmap [options] pid [...]
```
Report memory map of a process
+2 -6
View File
@@ -11,15 +11,11 @@ use std::env;
use std::fs;
use std::io::{Error, ErrorKind};
use uucore::error::{set_exit_code, UResult, USimpleError};
use uucore::{format_usage, help_about, help_usage};
mod maps_format_parser;
mod pmap_config;
mod smaps_format_parser;
const ABOUT: &str = help_about!("pmap.md");
const USAGE: &str = help_usage!("pmap.md");
mod options {
pub const PID: &str = "pid";
pub const EXTENDED: &str = "extended";
@@ -440,8 +436,8 @@ fn output_device_format(pid: &str, pmap_config: &PmapConfig) -> Result<(), Error
pub fn uu_app() -> Command {
Command::new(env!("CARGO_PKG_NAME"))
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Report memory map of a process")
.override_usage("pmap [options] pid [...]")
.infer_long_args(true)
.arg(
Arg::new(options::PID)
-7
View File
@@ -1,7 +0,0 @@
# ps
```
ps [options]
```
Report a snapshot of the current processes.
+3 -9
View File
@@ -23,13 +23,7 @@ use process_selection::ProcessSelectionSettings;
use std::cell::RefCell;
#[cfg(unix)]
use uucore::entries::{grp2gid, usr2uid};
use uucore::{
error::{UError, UResult, USimpleError},
format_usage, help_about, help_usage,
};
const ABOUT: &str = help_about!("ps.md");
const USAGE: &str = help_usage!("ps.md");
use uucore::error::{UError, UResult, USimpleError};
#[cfg(not(unix))]
pub fn usr2uid(_name: &str) -> std::io::Result<u32> {
@@ -199,8 +193,8 @@ fn parse_command_list(s: &str) -> Result<Vec<String>, String> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Report a snapshot of the current processes")
.override_usage("ps [options]")
.infer_long_args(true)
.disable_help_flag(true)
.arg(Arg::new("help").long("help").action(ArgAction::Help))
-7
View File
@@ -1,7 +0,0 @@
# pwdx
```
pwdx [options] pid [...]
```
Report current working directory of a process
+2 -6
View File
@@ -7,10 +7,6 @@ use clap::{crate_version, Arg, Command};
use std::env;
use sysinfo::{Pid, System};
use uucore::error::{set_exit_code, UResult, USimpleError};
use uucore::{format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("pwdx.md");
const USAGE: &str = help_usage!("pwdx.md");
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
@@ -52,8 +48,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Report current working directory of a process")
.override_usage("pwdx [options] pid [...]")
.infer_long_args(true)
.arg(
Arg::new("pid")
-7
View File
@@ -1,7 +0,0 @@
# skill
```
skill [signal] [options] <expression>
```
Report processes matching an expression and send a signal to them.
+3 -7
View File
@@ -9,13 +9,9 @@ use nix::{sys::signal, sys::signal::Signal, unistd::Pid};
use uu_snice::{
collect_pids, construct_verbose_result, print_signals, process_matcher, ActionResult,
};
use uucore::error::USimpleError;
use uucore::error::{UResult, USimpleError};
#[cfg(unix)]
use uucore::signals::signal_by_name_or_value;
use uucore::{error::UResult, format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("skill.md");
const USAGE: &str = help_usage!("skill.md");
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
@@ -93,8 +89,8 @@ fn perform_action(
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Report processes matching an expression and send a signal to them")
.override_usage("skill [signal] [options] <expression>")
.infer_long_args(true)
.arg_required_else_help(true)
.arg(Arg::new("signal"))
-22
View File
@@ -1,22 +0,0 @@
# slabtop
```
slabtop [options]
```
Display kernel slab cache information in real time
## After Help
The following are valid sort criteria:
* `a` sort by number of active objects
* `b` sort by objects per slab
* `c` sort by cache size
* `l` sort by number of slabs
* `v` sort by (non display) number of active slabs
* `n` sort by name
* `o` sort by number of objects (the default)
* `p` sort by (non display) pages per slab
* `s` sort by object size
* `u` sort by cache utilization
+16 -7
View File
@@ -5,11 +5,7 @@
pub use crate::parse::SlabInfo;
use clap::{arg, crate_version, ArgAction, Command};
use uucore::{error::UResult, format_usage, help_about, help_section, help_usage};
const ABOUT: &str = help_about!("slabtop.md");
const AFTER_HELP: &str = help_section!("after help", "slabtop.md");
const USAGE: &str = help_usage!("slabtop.md");
use uucore::error::UResult;
mod parse;
@@ -125,10 +121,23 @@ fn output_list(info: &SlabInfo) {
#[allow(clippy::cognitive_complexity)]
pub fn uu_app() -> Command {
const AFTER_HELP: &str = "The following are valid sort criteria:
a sort by number of active objects
b sort by objects per slab
c sort by cache size
l sort by number of slabs
v sort by (non display) number of active slabs
n sort by name
o sort by number of objects (the default)
p sort by (non display) pages per slab
s sort by object size
u sort by cache utilization";
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Display kernel slab cache information in real time")
.override_usage("slabtop [options]")
.infer_long_args(true)
.args([
// arg!(-d --delay <secs> "delay updates"),
-7
View File
@@ -1,7 +0,0 @@
# snice
```
snice [priority] [options] expression
```
Send a signal or report process status
+3 -9
View File
@@ -14,15 +14,9 @@ use std::collections::HashSet;
use std::io::Write;
use sysinfo::Pid;
use uu_pgrep::process::ProcessInformation;
use uucore::error::{UResult, USimpleError};
#[cfg(target_family = "unix")]
use uucore::signals::ALL_SIGNALS;
use uucore::{
error::{UResult, USimpleError},
format_usage, help_about, help_usage,
};
const ABOUT: &str = help_about!("snice.md");
const USAGE: &str = help_usage!("snice.md");
mod action;
mod priority;
@@ -238,8 +232,8 @@ pub fn collect_pids(targets: &[SelectedTarget]) -> Vec<u32> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Send a signal or report process status")
.override_usage("snice [priority] [options] expression")
.infer_long_args(true)
.arg_required_else_help(true)
.arg(Arg::new("priority"))
+2 -6
View File
@@ -6,10 +6,6 @@
use clap::{crate_version, Arg, ArgAction, Command};
use std::env;
use uucore::error::UResult;
use uucore::{format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("sysctl.md");
const USAGE: &str = help_usage!("sysctl.md");
#[cfg(target_os = "linux")]
mod linux {
@@ -138,8 +134,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Show or modify kernel parameters at runtime")
.override_usage("sysctl [options] [variable[=value]]...")
.infer_long_args(true)
.arg(
Arg::new("variables")
-7
View File
@@ -1,7 +0,0 @@
# sysctl
```
sysctl [options] [variable[=value]]...
```
Show or modify kernel parameters at runtime.
+3 -6
View File
@@ -11,10 +11,7 @@ use std::time::Duration;
use clap::{arg, crate_version, value_parser, ArgAction, ArgMatches, Command};
use crossterm::event::{self, KeyCode, KeyEvent, KeyModifiers};
use tui::{LegacyTui, ModernTui};
use uucore::{error::UResult, format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("tload.md");
const USAGE: &str = help_usage!("tload.md");
use uucore::error::UResult;
mod tui;
@@ -143,8 +140,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("tload prints a graph of the current system load average to the specified tty (or the tty of the tload process if none is specified)")
.override_usage("tload [options] [tty]")
.infer_long_args(true)
.args([
arg!(-d --delay <secs> "update delay in seconds")
-7
View File
@@ -1,7 +0,0 @@
# tload
```
tload [options] [tty]
```
tload prints a graph of the current system load average to the specified tty (or the tty of the tload process if none is specified).
+4 -11
View File
@@ -8,21 +8,14 @@ use crate::picker::Column;
use crate::tui::stat::TuiStat;
use crate::tui::{handle_input, Tui};
use clap::{arg, crate_version, value_parser, ArgAction, ArgGroup, ArgMatches, Command};
use picker::pickers;
use picker::sysinfo;
use picker::{pickers, sysinfo};
use ratatui::crossterm::event;
use ratatui::prelude::Widget;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock};
use std::{thread, thread::sleep, time::Duration};
use sysinfo::{Pid, Users};
use uucore::{
error::{UResult, USimpleError},
format_usage, help_about, help_usage,
};
const ABOUT: &str = help_about!("top.md");
const USAGE: &str = help_usage!("top.md");
use uucore::error::{UResult, USimpleError};
mod action;
mod field;
@@ -310,8 +303,8 @@ fn construct_filter(tui_stat: &TuiStat) -> Box<dyn Fn(u32) -> bool> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Display Linux processes")
.override_usage("top [options]")
.infer_long_args(true)
.args([
// arg!(-b --"batch-mode" "run in non-interactive batch mode"),
-7
View File
@@ -1,7 +0,0 @@
# top
```
top [options]
```
Display Linux processes
+2 -6
View File
@@ -15,10 +15,6 @@ use clap::{arg, crate_version, ArgMatches, Command};
pub use parser::*;
#[allow(unused_imports)]
use uucore::error::{UResult, USimpleError};
use uucore::{format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("vmstat.md");
const USAGE: &str = help_usage!("vmstat.md");
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
@@ -292,8 +288,8 @@ fn print_data(
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Report virtual memory statistics")
.override_usage("vmstat [options]")
.infer_long_args(true)
.args([
arg!(<delay> "The delay between updates in seconds")
-9
View File
@@ -1,9 +0,0 @@
# vmstat
usage:
```bash
vmstat [options]
```
Report virtual memory statistics
+3 -6
View File
@@ -10,6 +10,7 @@ use clap::{Arg, ArgAction, Command};
#[cfg(target_os = "linux")]
use std::{collections::HashMap, fs, path::Path, time::SystemTime};
use std::{process, time::Duration};
use uucore::error::UResult;
#[cfg(target_os = "linux")]
use uucore::libc::{sysconf, _SC_CLK_TCK};
use uucore::uptime::{
@@ -17,10 +18,6 @@ use uucore::uptime::{
};
#[cfg(target_os = "linux")]
use uucore::utmpx::Utmpx;
use uucore::{error::UResult, format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("w.md");
const USAGE: &str = help_usage!("w.md");
struct UserInfo {
user: String,
@@ -316,8 +313,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Show who is logged on and what they are doing")
.override_usage("w [options] [user]")
.infer_long_args(true)
.disable_help_flag(true)
.arg(
-7
View File
@@ -1,7 +0,0 @@
# w
```
w [options] [user]
```
Show who is logged on and what they are doing
+3 -6
View File
@@ -10,10 +10,7 @@ use std::num::ParseIntError;
use std::process::{Command as SystemCommand, Stdio};
use std::thread::sleep;
use std::time::Duration;
use uucore::{error::UResult, format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("watch.md");
const USAGE: &str = help_usage!("watch.md");
use uucore::error::UResult;
fn parse_interval(input: &str) -> Result<Duration, ParseIntError> {
// Find index where to split string into seconds and nanos
@@ -109,8 +106,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.about("Execute a program periodically, showing output fullscreen")
.override_usage("watch [options] command")
.infer_long_args(true)
.arg(
Arg::new("command")
-7
View File
@@ -1,7 +0,0 @@
# watch
```
watch [options] command
```
Execute a program periodically, showing output fullscreen