lsmem: Add noheadings

This commit is contained in:
Yang Hau
2024-08-26 00:56:31 +08:00
parent 7e0160b0c7
commit f83d22b3ea

View File

@@ -16,7 +16,11 @@ use std::str::FromStr;
use uucore::{error::UResult, format_usage, help_about, help_usage}; use uucore::{error::UResult, format_usage, help_about, help_usage};
use tabled::{ use tabled::{
settings::{location::ByColumnName, object, Alignment, Disable, Modify, Style}, settings::{
location::ByColumnName,
object::{self, Rows},
Alignment, Disable, Modify, Style,
},
Table, Tabled, Table, Tabled,
}; };
@@ -25,6 +29,7 @@ const USAGE: &str = help_usage!("lsmem.md");
mod options { mod options {
pub const BYTES: &str = "bytes"; pub const BYTES: &str = "bytes";
pub const NOHEADINGS: &str = "noheadings";
} }
// const BUFSIZ: usize = 1024; // const BUFSIZ: usize = 1024;
@@ -209,7 +214,7 @@ struct Options {
// raw: bool, // raw: bool,
// export: bool, // export: bool,
// json: bool, // json: bool,
// noheadings: bool, noheadings: bool,
// summary: bool, // summary: bool,
list_all: bool, list_all: bool,
bytes: bool, bytes: bool,
@@ -253,7 +258,7 @@ impl Options {
// raw: false, // raw: false,
// export: false, // export: false,
// json: false, // json: false,
// noheadings: false, noheadings: false,
// summary: false, // summary: false,
list_all: false, list_all: false,
bytes: false, bytes: false,
@@ -475,6 +480,10 @@ fn print_table(lsmem: &Lsmem, opts: &Options) {
table.with(Disable::column(ByColumnName::new("NODE"))); table.with(Disable::column(ByColumnName::new("NODE")));
table.with(Disable::column(ByColumnName::new("ZONES"))); table.with(Disable::column(ByColumnName::new("ZONES")));
if opts.noheadings {
table.with(Disable::row(Rows::first()));
}
println!("{table}"); println!("{table}");
} }
@@ -516,11 +525,11 @@ where
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches: clap::ArgMatches = uu_app().try_get_matches_from(args)?; let matches: clap::ArgMatches = uu_app().try_get_matches_from(args)?;
let opt_bytes = matches.get_flag(options::BYTES);
let mut lsmem = Lsmem::new(); let mut lsmem = Lsmem::new();
let mut opts = Options::new(); let mut opts = Options::new();
opts.bytes = opt_bytes; opts.bytes = matches.get_flag(options::BYTES);
opts.noheadings = matches.get_flag(options::NOHEADINGS);
read_info(&mut lsmem, &mut opts); read_info(&mut lsmem, &mut opts);
@@ -548,4 +557,11 @@ pub fn uu_app() -> Command {
.help("print SIZE in bytes rather than in human readable format") .help("print SIZE in bytes rather than in human readable format")
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg(
Arg::new(options::NOHEADINGS)
.short('n')
.long("noheadings")
.help("don't print headings")
.action(ArgAction::SetTrue),
)
} }