lsmem: Implement --all (-a)

This commit is contained in:
Foorack
2025-02-08 18:06:33 +01:00
parent 306a366900
commit b75db66f59

View File

@ -28,6 +28,7 @@ const ABOUT: &str = help_about!("lsmem.md");
const USAGE: &str = help_usage!("lsmem.md"); const USAGE: &str = help_usage!("lsmem.md");
mod options { mod options {
pub const ALL: &str = "all";
pub const BYTES: &str = "bytes"; pub const BYTES: &str = "bytes";
pub const NOHEADINGS: &str = "noheadings"; pub const NOHEADINGS: &str = "noheadings";
pub const JSON: &str = "json"; pub const JSON: &str = "json";
@ -235,6 +236,7 @@ struct TableRowJson {
} }
struct Options { struct Options {
all: bool,
have_nodes: bool, have_nodes: bool,
raw: bool, raw: bool,
export: bool, export: bool,
@ -278,6 +280,7 @@ impl Lsmem {
impl Options { impl Options {
fn new() -> Options { fn new() -> Options {
Options { Options {
all: false,
have_nodes: false, have_nodes: false,
raw: false, raw: false,
export: false, export: false,
@ -334,7 +337,7 @@ fn read_info(lsmem: &mut Lsmem, opts: &mut Options) {
} else { } else {
lsmem.mem_offline += lsmem.block_size; lsmem.mem_offline += lsmem.block_size;
} }
if is_mergeable(lsmem, opts, &blk) { if !opts.all && is_mergeable(lsmem, opts, &blk) {
lsmem.blocks[lsmem.nblocks - 1].count += 1; lsmem.blocks[lsmem.nblocks - 1].count += 1;
continue; continue;
} }
@ -591,6 +594,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut lsmem = Lsmem::new(); let mut lsmem = Lsmem::new();
let mut opts = Options::new(); let mut opts = Options::new();
opts.all = matches.get_flag(options::ALL);
opts.bytes = matches.get_flag(options::BYTES); opts.bytes = matches.get_flag(options::BYTES);
opts.noheadings = matches.get_flag(options::NOHEADINGS); opts.noheadings = matches.get_flag(options::NOHEADINGS);
opts.json = matches.get_flag(options::JSON); opts.json = matches.get_flag(options::JSON);
@ -633,6 +637,13 @@ pub fn uu_app() -> Command {
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE)) .override_usage(format_usage(USAGE))
.infer_long_args(true) .infer_long_args(true)
.arg(
Arg::new(options::ALL)
.short('a')
.long("all")
.help("list each individual memory block")
.action(ArgAction::SetTrue),
)
.arg( .arg(
Arg::new(options::BYTES) Arg::new(options::BYTES)
.short('b') .short('b')