mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-01-13 09:01:47 +00:00
Help text changes
This changes the --help text, and gets rid of the special behaviour for --help --long, which I thought was a really good idea at the time, but now I just think it's inconsistent and unexpected behaviour. --help should return the same help, no matter what other arguments you have typed. Other things: • Put --help and --version in a section • Capitalisation consistency • Alignment • Move the --octal-permissions line up a bit • Simplify the printing implementation (HelpString is now a unit struct) This _finally_ makes all the extended tests pass.
This commit is contained in:
parent
91f1541e85
commit
86de17b788
@ -81,11 +81,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OptionsResult::Help(help_text) => {
|
OptionsResult::Help(help_text) => {
|
||||||
println!("{}", help_text);
|
print!("{}", help_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionsResult::Version(version_str) => {
|
OptionsResult::Version(version_str) => {
|
||||||
println!("{}", version_str);
|
print!("{}", version_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionsResult::InvalidOptions(error) => {
|
OptionsResult::InvalidOptions(error) => {
|
||||||
|
@ -5,7 +5,10 @@ use crate::options::flags;
|
|||||||
use crate::options::parser::MatchedFlags;
|
use crate::options::parser::MatchedFlags;
|
||||||
|
|
||||||
|
|
||||||
static OPTIONS: &str = r##"
|
static USAGE: &str = r##"Usage:
|
||||||
|
exa [options] [files...]
|
||||||
|
|
||||||
|
META OPTIONS
|
||||||
-?, --help show list of command-line options
|
-?, --help show list of command-line options
|
||||||
-v, --version show version of exa
|
-v, --version show version of exa
|
||||||
|
|
||||||
@ -30,52 +33,40 @@ FILTERING AND SORTING OPTIONS
|
|||||||
--group-directories-first list directories before other files
|
--group-directories-first list directories before other files
|
||||||
-D, --only-dirs list only directories
|
-D, --only-dirs list only directories
|
||||||
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
|
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
|
||||||
--git-ignore Ignore files mentioned in '.gitignore'
|
--git-ignore ignore files mentioned in '.gitignore'
|
||||||
Valid sort fields: name, Name, extension, Extension, size, type,
|
Valid sort fields: name, Name, extension, Extension, size, type,
|
||||||
modified, accessed, created, inode, and none.
|
modified, accessed, created, inode, and none.
|
||||||
date, time, old, and new all refer to modified.
|
date, time, old, and new all refer to modified.
|
||||||
"##;
|
|
||||||
|
|
||||||
static LONG_OPTIONS: &str = r##"
|
|
||||||
LONG VIEW OPTIONS
|
LONG VIEW OPTIONS
|
||||||
-b, --binary list file sizes with binary prefixes
|
-b, --binary list file sizes with binary prefixes
|
||||||
-B, --bytes list file sizes in bytes, without any prefixes
|
-B, --bytes list file sizes in bytes, without any prefixes
|
||||||
-g, --group list each file's group
|
-g, --group list each file's group
|
||||||
-h, --header add a header row to each column
|
-h, --header add a header row to each column
|
||||||
-H, --links list each file's number of hard links
|
-H, --links list each file's number of hard links
|
||||||
-i, --inode list each file's inode number
|
-i, --inode list each file's inode number
|
||||||
-m, --modified use the modified timestamp field
|
-m, --modified use the modified timestamp field
|
||||||
-S, --blocks show number of file system blocks
|
-S, --blocks show number of file system blocks
|
||||||
-t, --time FIELD which timestamp field to list (modified, accessed, created)
|
-t, --time FIELD which timestamp field to list (modified, accessed, created)
|
||||||
-u, --accessed use the accessed timestamp field
|
-u, --accessed use the accessed timestamp field
|
||||||
-U, --created use the created timestamp field
|
-U, --created use the created timestamp field
|
||||||
--changed use the changed timestamp field
|
--changed use the changed timestamp field
|
||||||
--time-style how to format timestamps (default, iso, long-iso, full-iso)
|
--time-style how to format timestamps (default, iso, long-iso, full-iso)
|
||||||
--no-permissions suppress the permissions field
|
--no-permissions suppress the permissions field
|
||||||
--no-filesize suppress the filesize field
|
--octal-permissions list each file's permission in octal format
|
||||||
--no-user suppress the user field
|
--no-filesize suppress the filesize field
|
||||||
--no-time suppress the time field"##;
|
--no-user suppress the user field
|
||||||
|
--no-time suppress the time field"##;
|
||||||
|
|
||||||
static GIT_HELP: &str = r##" --git list each file's Git status, if tracked or ignored"##;
|
static GIT_HELP: &str = r##" --git list each file's Git status, if tracked or ignored"##;
|
||||||
static EXTENDED_HELP: &str = r##" -@, --extended list each file's extended attributes and sizes"##;
|
static EXTENDED_HELP: &str = r##" -@, --extended list each file's extended attributes and sizes"##;
|
||||||
static OCTAL_HELP: &str = r##" --octal-permissions list each file's permission in octal format"##;
|
|
||||||
|
|
||||||
|
|
||||||
/// All the information needed to display the help text, which depends
|
/// All the information needed to display the help text, which depends
|
||||||
/// on which features are enabled and whether the user only wants to
|
/// on which features are enabled and whether the user only wants to
|
||||||
/// see one section’s help.
|
/// see one section’s help.
|
||||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||||
pub struct HelpString {
|
pub struct HelpString;
|
||||||
|
|
||||||
/// Only show the help for the long section, not all the help.
|
|
||||||
only_long: bool,
|
|
||||||
|
|
||||||
/// Whether the --git option should be included in the help.
|
|
||||||
git: bool,
|
|
||||||
|
|
||||||
/// Whether the --extended option should be included in the help.
|
|
||||||
xattrs: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HelpString {
|
impl HelpString {
|
||||||
|
|
||||||
@ -88,10 +79,7 @@ impl HelpString {
|
|||||||
/// errors when the user wants help is kind of petty!
|
/// errors when the user wants help is kind of petty!
|
||||||
pub fn deduce(matches: &MatchedFlags<'_>) -> Option<Self> {
|
pub fn deduce(matches: &MatchedFlags<'_>) -> Option<Self> {
|
||||||
if matches.count(&flags::HELP) > 0 {
|
if matches.count(&flags::HELP) > 0 {
|
||||||
let only_long = matches.count(&flags::LONG) > 0;
|
Some(Self)
|
||||||
let git = cfg!(feature="git");
|
|
||||||
let xattrs = xattr::ENABLED;
|
|
||||||
Some(Self { only_long, git, xattrs })
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
None
|
None
|
||||||
@ -104,24 +92,16 @@ impl fmt::Display for HelpString {
|
|||||||
/// Format this help options into an actual string of help
|
/// Format this help options into an actual string of help
|
||||||
/// text to be displayed to the user.
|
/// text to be displayed to the user.
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||||
writeln!(f, "Usage:\n exa [options] [files...]")?;
|
writeln!(f, "{}", USAGE)?;
|
||||||
|
|
||||||
if ! self.only_long {
|
if cfg!(feature="git") {
|
||||||
write!(f, "{}", OPTIONS)?;
|
writeln!(f, "{}", GIT_HELP)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, "{}", LONG_OPTIONS)?;
|
if xattr::ENABLED {
|
||||||
|
writeln!(f, "{}", EXTENDED_HELP)?;
|
||||||
if self.git {
|
|
||||||
write!(f, "\n{}", GIT_HELP)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.xattrs {
|
|
||||||
write!(f, "\n{}", EXTENDED_HELP)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
write!(f, "\n{}", OCTAL_HELP)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ impl VersionString {
|
|||||||
|
|
||||||
impl fmt::Display for VersionString {
|
impl fmt::Display for VersionString {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||||
write!(f, "{}", include!(concat!(env!("OUT_DIR"), "/version_string.txt")))
|
writeln!(f, "{}", include!(concat!(env!("OUT_DIR"), "/version_string.txt")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
xtests/help
42
xtests/help
@ -1,6 +1,7 @@
|
|||||||
Usage:
|
Usage:
|
||||||
exa [options] [files...]
|
exa [options] [files...]
|
||||||
|
|
||||||
|
META OPTIONS
|
||||||
-?, --help show list of command-line options
|
-?, --help show list of command-line options
|
||||||
-v, --version show version of exa
|
-v, --version show version of exa
|
||||||
|
|
||||||
@ -25,28 +26,29 @@ FILTERING AND SORTING OPTIONS
|
|||||||
--group-directories-first list directories before other files
|
--group-directories-first list directories before other files
|
||||||
-D, --only-dirs list only directories
|
-D, --only-dirs list only directories
|
||||||
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
|
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
|
||||||
--git-ignore Ignore files mentioned in '.gitignore'
|
--git-ignore ignore files mentioned in '.gitignore'
|
||||||
Valid sort fields: name, Name, extension, Extension, size, type,
|
Valid sort fields: name, Name, extension, Extension, size, type,
|
||||||
modified, accessed, created, inode, and none.
|
modified, accessed, created, inode, and none.
|
||||||
date, time, old, and new all refer to modified.
|
date, time, old, and new all refer to modified.
|
||||||
|
|
||||||
LONG VIEW OPTIONS
|
LONG VIEW OPTIONS
|
||||||
-b, --binary list file sizes with binary prefixes
|
-b, --binary list file sizes with binary prefixes
|
||||||
-B, --bytes list file sizes in bytes, without any prefixes
|
-B, --bytes list file sizes in bytes, without any prefixes
|
||||||
-g, --group list each file's group
|
-g, --group list each file's group
|
||||||
-h, --header add a header row to each column
|
-h, --header add a header row to each column
|
||||||
-H, --links list each file's number of hard links
|
-H, --links list each file's number of hard links
|
||||||
-i, --inode list each file's inode number
|
-i, --inode list each file's inode number
|
||||||
-m, --modified use the modified timestamp field
|
-m, --modified use the modified timestamp field
|
||||||
-S, --blocks show number of file system blocks
|
-S, --blocks show number of file system blocks
|
||||||
-t, --time FIELD which timestamp field to list (modified, accessed, created)
|
-t, --time FIELD which timestamp field to list (modified, accessed, created)
|
||||||
-u, --accessed use the accessed timestamp field
|
-u, --accessed use the accessed timestamp field
|
||||||
-U, --created use the created timestamp field
|
-U, --created use the created timestamp field
|
||||||
--changed use the changed timestamp field
|
--changed use the changed timestamp field
|
||||||
--time-style how to format timestamps (default, iso, long-iso, full-iso)
|
--time-style how to format timestamps (default, iso, long-iso, full-iso)
|
||||||
--no-permissions suppress the permissions field
|
--no-permissions suppress the permissions field
|
||||||
--no-filesize suppress the filesize field
|
--octal-permissions list each file's permission in octal format
|
||||||
--no-user suppress the user field
|
--no-filesize suppress the filesize field
|
||||||
--no-time suppress the time field
|
--no-user suppress the user field
|
||||||
--git list each file's Git status, if tracked or ignored
|
--no-time suppress the time field
|
||||||
-@, --extended list each file's extended attributes and sizes
|
--git list each file's Git status, if tracked or ignored
|
||||||
|
-@, --extended list each file's extended attributes and sizes
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
Usage:
|
|
||||||
exa [options] [files...]
|
|
||||||
|
|
||||||
LONG VIEW OPTIONS
|
|
||||||
-b, --binary list file sizes with binary prefixes
|
|
||||||
-B, --bytes list file sizes in bytes, without any prefixes
|
|
||||||
-g, --group list each file's group
|
|
||||||
-h, --header add a header row to each column
|
|
||||||
-H, --links list each file's number of hard links
|
|
||||||
-i, --inode list each file's inode number
|
|
||||||
-m, --modified use the modified timestamp field
|
|
||||||
-S, --blocks show number of file system blocks
|
|
||||||
-t, --time FIELD which timestamp field to list (modified, accessed, created)
|
|
||||||
-u, --accessed use the accessed timestamp field
|
|
||||||
-U, --created use the created timestamp field
|
|
||||||
--changed use the changed timestamp field
|
|
||||||
--time-style how to format timestamps (default, iso, long-iso, full-iso)
|
|
||||||
--no-permissions suppress the permissions field
|
|
||||||
--no-filesize suppress the filesize field
|
|
||||||
--no-user suppress the user field
|
|
||||||
--no-time suppress the time field
|
|
||||||
--git list each file's Git status, if tracked or ignored
|
|
||||||
-@, --extended list each file's extended attributes and sizes
|
|
@ -290,7 +290,6 @@ fi
|
|||||||
|
|
||||||
# And finally...
|
# And finally...
|
||||||
$exa --help | diff -q - $results/help || exit 1
|
$exa --help | diff -q - $results/help || exit 1
|
||||||
$exa --help --long | diff -q - $results/help_long || exit 1
|
|
||||||
|
|
||||||
|
|
||||||
echo "All the tests passed!"
|
echo "All the tests passed!"
|
||||||
|
Loading…
Reference in New Issue
Block a user