mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-23 04:22:06 +00:00
Move help generation to its own function
This commit is contained in:
parent
aaa8876f49
commit
ded829f073
@ -1,5 +1,7 @@
|
||||
use getopts::Matches;
|
||||
|
||||
pub static OPTIONS: &str = r##"
|
||||
|
||||
static OPTIONS: &str = r##"
|
||||
-?, --help show list of command-line options
|
||||
-v, --version show version of exa
|
||||
|
||||
@ -26,7 +28,7 @@ FILTERING AND SORTING OPTIONS
|
||||
|
||||
"##;
|
||||
|
||||
pub static LONG_OPTIONS: &str = r##"
|
||||
static LONG_OPTIONS: &str = r##"
|
||||
LONG VIEW OPTIONS
|
||||
-b, --binary list file sizes with binary prefixes
|
||||
-B, --bytes list file sizes in bytes, without any prefixes
|
||||
@ -42,5 +44,28 @@ LONG VIEW OPTIONS
|
||||
-U, --created use the created timestamp field
|
||||
"##;
|
||||
|
||||
pub static GIT_HELP: &str = r##" --git list each file's Git status, if tracked"##;
|
||||
pub static EXTENDED_HELP: &str = r##" -@, --extended list each file's extended attributes and sizes"##;
|
||||
static GIT_HELP: &str = r##" --git list each file's Git status, if tracked"##;
|
||||
static EXTENDED_HELP: &str = r##" -@, --extended list each file's extended attributes and sizes"##;
|
||||
|
||||
|
||||
pub fn help_string(matches: &Matches, git: bool, xattr: bool) -> String {
|
||||
let mut help = String::from("Usage:\n exa [options] [files...]\n");
|
||||
|
||||
if !matches.opt_present("long") {
|
||||
help.push_str(OPTIONS);
|
||||
}
|
||||
|
||||
help.push_str(LONG_OPTIONS);
|
||||
|
||||
if git {
|
||||
help.push_str(GIT_HELP);
|
||||
help.push('\n');
|
||||
}
|
||||
|
||||
if xattr {
|
||||
help.push_str(EXTENDED_HELP);
|
||||
help.push('\n');
|
||||
}
|
||||
|
||||
help
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ mod filter;
|
||||
pub use self::filter::{FileFilter, SortField, SortCase};
|
||||
|
||||
mod help;
|
||||
use self::help::*;
|
||||
use self::help::help_string;
|
||||
|
||||
mod misfire;
|
||||
pub use self::misfire::Misfire;
|
||||
@ -103,25 +103,7 @@ impl Options {
|
||||
};
|
||||
|
||||
if matches.opt_present("help") {
|
||||
let mut help_string = "Usage:\n exa [options] [files...]\n".to_owned();
|
||||
|
||||
if !matches.opt_present("long") {
|
||||
help_string.push_str(OPTIONS);
|
||||
}
|
||||
|
||||
help_string.push_str(LONG_OPTIONS);
|
||||
|
||||
if cfg!(feature="git") {
|
||||
help_string.push_str(GIT_HELP);
|
||||
help_string.push('\n');
|
||||
}
|
||||
|
||||
if xattr::ENABLED {
|
||||
help_string.push_str(EXTENDED_HELP);
|
||||
help_string.push('\n');
|
||||
}
|
||||
|
||||
return Err(Misfire::Help(help_string));
|
||||
return Err(Misfire::Help(help_string(&matches, cfg!(feature="git"), xattr::ENABLED)));
|
||||
}
|
||||
else if matches.opt_present("version") {
|
||||
return Err(Misfire::Version);
|
||||
|
Loading…
Reference in New Issue
Block a user