diff --git a/.github/workflows/GnuTests.yml b/.github/workflows/GnuTests.yml index fd2d66835..7c8c307ec 100644 --- a/.github/workflows/GnuTests.yml +++ b/.github/workflows/GnuTests.yml @@ -86,7 +86,7 @@ jobs: run: | ## Install dependencies sudo apt-get update - sudo apt-get install autoconf autopoint bison texinfo gperf gcc g++ gdb python3-pyinotify jq valgrind libexpect-perl + sudo apt-get install -y autoconf autopoint bison texinfo gperf gcc g++ gdb python3-pyinotify jq valgrind libexpect-perl libacl1-dev libattr1-dev libcap-dev - name: Add various locales shell: bash run: | @@ -316,8 +316,8 @@ jobs: - name: Install dependencies run: | ## Install dependencies - sudo apt update - sudo apt install autoconf autopoint bison texinfo gperf gcc g++ gdb python3-pyinotify jq valgrind libexpect-perl -y + sudo apt-get update + sudo apt-get install -y autoconf autopoint bison texinfo gperf gcc g++ gdb python3-pyinotify jq valgrind libexpect-perl libacl1-dev libattr1-dev libcap-dev - name: Add various locales run: | ## Add various locales diff --git a/src/uu/basename/basename.md b/src/uu/basename/basename.md new file mode 100644 index 000000000..b17cac74a --- /dev/null +++ b/src/uu/basename/basename.md @@ -0,0 +1,9 @@ +# basename + +``` +basename NAME [SUFFIX] +basename OPTION... NAME... +``` + +Print NAME with any leading directory components removed +If specified, also remove a trailing SUFFIX diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index 613c4d67c..ed7faee65 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -11,13 +11,11 @@ use clap::{crate_version, Arg, ArgAction, Command}; use std::path::{is_separator, PathBuf}; use uucore::display::Quotable; use uucore::error::{UResult, UUsageError}; -use uucore::format_usage; +use uucore::{format_usage, help_about, help_usage}; -static ABOUT: &str = r#"Print NAME with any leading directory components removed -If specified, also remove a trailing SUFFIX"#; +static ABOUT: &str = help_about!("basename.md"); -const USAGE: &str = "{} NAME [SUFFIX] - {} OPTION... NAME..."; +const USAGE: &str = help_usage!("basename.md"); pub mod options { pub static MULTIPLE: &str = "multiple"; diff --git a/src/uu/chcon/chcon.md b/src/uu/chcon/chcon.md new file mode 100644 index 000000000..c4266be6e --- /dev/null +++ b/src/uu/chcon/chcon.md @@ -0,0 +1,11 @@ + +# chcon + +``` +chcon [OPTION]... CONTEXT FILE... +chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... +chcon [OPTION]... --reference=RFILE FILE... +``` + +Change the SELinux security context of each FILE to CONTEXT. +With --reference, change the security context of each FILE to that of RFILE. \ No newline at end of file diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index 3acd2ea43..2f316393a 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -1,11 +1,9 @@ // spell-checker:ignore (vars) RFILE - #![allow(clippy::upper_case_acronyms)] use clap::builder::ValueParser; use uucore::error::{UResult, USimpleError, UUsageError}; -use uucore::format_usage; -use uucore::{display::Quotable, show_error, show_warning}; +use uucore::{display::Quotable, format_usage, help_about, help_usage, show_error, show_warning}; use clap::{Arg, ArgAction, Command}; use selinux::{OpaqueSecurityContext, SecurityContext}; @@ -21,13 +19,9 @@ mod fts; use errors::*; -static VERSION: &str = env!("CARGO_PKG_VERSION"); -static ABOUT: &str = "Change the SELinux security context of each FILE to CONTEXT. \n\ - With --reference, change the security context of each FILE to that of RFILE."; -const USAGE: &str = "\ - {} [OPTION]... CONTEXT FILE... \n \ - {} [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... \n \ - {} [OPTION]... --reference=RFILE FILE..."; +const VERSION: &str = env!("CARGO_PKG_VERSION"); +const ABOUT: &str = help_about!("chcon.md"); +const USAGE: &str = help_usage!("chcon.md"); pub mod options { pub static HELP: &str = "help"; diff --git a/src/uu/chown/chown.md b/src/uu/chown/chown.md new file mode 100644 index 000000000..83101c74c --- /dev/null +++ b/src/uu/chown/chown.md @@ -0,0 +1,9 @@ + +# chown + +``` +chown [OPTION]... [OWNER][:[GROUP]] FILE... +chown [OPTION]... --reference=RFILE FILE... +``` + +Change file owner and group diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index 401703cdf..3faecd571 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -9,8 +9,8 @@ use uucore::display::Quotable; pub use uucore::entries::{self, Group, Locate, Passwd}; -use uucore::format_usage; use uucore::perms::{chown_base, options, IfFrom}; +use uucore::{format_usage, help_about, help_usage}; use uucore::error::{FromIo, UResult, USimpleError}; @@ -19,11 +19,9 @@ use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; use std::fs; use std::os::unix::fs::MetadataExt; -static ABOUT: &str = "Change file owner and group"; +static ABOUT: &str = help_about!("chown.md"); -const USAGE: &str = "\ - {} [OPTION]... [OWNER][:[GROUP]] FILE... - {} [OPTION]... --reference=RFILE FILE..."; +const USAGE: &str = help_usage!("chown.md"); fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult<(Option, Option, IfFrom)> { let filter = if let Some(spec) = matches.get_one::(options::FROM) { diff --git a/src/uu/truncate/src/truncate.rs b/src/uu/truncate/src/truncate.rs index 090865313..f050b52b4 100644 --- a/src/uu/truncate/src/truncate.rs +++ b/src/uu/truncate/src/truncate.rs @@ -14,8 +14,8 @@ use std::os::unix::fs::FileTypeExt; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; -use uucore::format_usage; use uucore::parse_size::{parse_size, ParseSizeError}; +use uucore::{format_usage, help_about, help_section, help_usage}; #[derive(Debug, Eq, PartialEq)] enum TruncateMode { @@ -73,25 +73,9 @@ impl TruncateMode { } } -const ABOUT: &str = "Shrink or extend the size of each file to the specified size."; -const USAGE: &str = "{} [OPTION]... [FILE]..."; -const LONG_USAGE: &str = "\ -SIZE is an integer with an optional prefix and optional unit. -The available units (K, M, G, T, P, E, Z, and Y) use the following format: - 'KB' => 1000 (kilobytes) - 'K' => 1024 (kibibytes) - 'MB' => 1000*1000 (megabytes) - 'M' => 1024*1024 (mebibytes) - 'GB' => 1000*1000*1000 (gigabytes) - 'G' => 1024*1024*1024 (gibibytes) -SIZE may also be prefixed by one of the following to adjust the size of each -file based on its current size: - '+' => extend by - '-' => reduce by - '<' => at most - '>' => at least - '/' => round down to multiple of - '%' => round up to multiple of"; +const ABOUT: &str = help_about!("truncate.md"); +const AFTER_HELP: &str = help_section!("after help", "truncate.md"); +const USAGE: &str = help_usage!("truncate.md"); pub mod options { pub static IO_BLOCKS: &str = "io-blocks"; @@ -104,7 +88,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app() - .after_help(LONG_USAGE) + .after_help(AFTER_HELP) .try_get_matches_from(args) .map_err(|e| { e.print().expect("Error writing clap::Error"); diff --git a/src/uu/truncate/truncate.md b/src/uu/truncate/truncate.md new file mode 100644 index 000000000..841c4b16c --- /dev/null +++ b/src/uu/truncate/truncate.md @@ -0,0 +1,25 @@ +# truncate + +truncate [OPTION]... [FILE]... +``` + +Shrink or extend the size of each file to the specified size. + +## After help + +SIZE is an integer with an optional prefix and optional unit. +The available units (K, M, G, T, P, E, Z, and Y) use the following format: + 'KB' => 1000 (kilobytes) + 'K' => 1024 (kibibytes) + 'MB' => 1000*1000 (megabytes) + 'M' => 1024*1024 (mebibytes) + 'GB' => 1000*1000*1000 (gigabytes) + 'G' => 1024*1024*1024 (gibibytes) +SIZE may also be prefixed by one of the following to adjust the size of each +file based on its current size: + '+' => extend by + '-' => reduce by + '<' => at most + '>' => at least + '/' => round down to multiple of + '%' => round up to multiple of \ No newline at end of file diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 4a4838350..0b7b164a8 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -15,7 +15,7 @@ use count_fast::{count_bytes_chars_and_lines_fast, count_bytes_fast}; use countable::WordCountable; use unicode_width::UnicodeWidthChar; use utf8::{BufReadDecoder, BufReadDecoderError}; -use uucore::{format_usage, show}; +use uucore::{format_usage, help_about, help_usage, show}; use word_count::{TitledWordCount, WordCount}; use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; @@ -98,9 +98,8 @@ impl Settings { } } -static ABOUT: &str = "Display newline, word, and byte counts for each FILE, and a total line if -more than one FILE is specified. With no FILE, or when FILE is -, read standard input."; -const USAGE: &str = "{} [OPTION]... [FILE]..."; +const ABOUT: &str = help_about!("wc.md"); +const USAGE: &str = help_usage!("wc.md"); pub mod options { pub static BYTES: &str = "bytes"; diff --git a/src/uu/wc/wc.md b/src/uu/wc/wc.md new file mode 100644 index 000000000..3d0014b37 --- /dev/null +++ b/src/uu/wc/wc.md @@ -0,0 +1,7 @@ +# wc + +wc [OPTION]... [FILE]... +``` + +Display newline, word, and byte counts for each FILE, and a total line if +more than one FILE is specified. With no FILE, or when FILE is -, read standard input. diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index 1232beda9..4a3cc3530 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -391,7 +391,12 @@ fn test_du_h_flag_empty_file() { fn test_du_time() { let ts = TestScenario::new(util_name!()); + // du --time formats the timestamp according to the local timezone. We set the TZ + // environment variable to UTC in the commands below to ensure consistent outputs + // and test results regardless of the timezone of the machine this test runs in. + ts.ccmd("touch") + .env("TZ", "UTC") .arg("-a") .arg("-t") .arg("201505150000") @@ -399,19 +404,35 @@ fn test_du_time() { .succeeds(); ts.ccmd("touch") + .env("TZ", "UTC") .arg("-m") .arg("-t") .arg("201606160000") .arg("date_test") .succeeds(); - let result = ts.ucmd().arg("--time").arg("date_test").succeeds(); + let result = ts + .ucmd() + .env("TZ", "UTC") + .arg("--time") + .arg("date_test") + .succeeds(); result.stdout_only("0\t2016-06-16 00:00\tdate_test\n"); - let result = ts.ucmd().arg("--time=atime").arg("date_test").succeeds(); + let result = ts + .ucmd() + .env("TZ", "UTC") + .arg("--time=atime") + .arg("date_test") + .succeeds(); result.stdout_only("0\t2015-05-15 00:00\tdate_test\n"); - let result = ts.ucmd().arg("--time=ctime").arg("date_test").succeeds(); + let result = ts + .ucmd() + .env("TZ", "UTC") + .arg("--time=ctime") + .arg("date_test") + .succeeds(); result.stdout_only("0\t2016-06-16 00:00\tdate_test\n"); if birth_supported() {