mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 20:47:46 +00:00
dircolors: Address code review comments
This commit is contained in:
parent
850a56ccea
commit
754082886c
1 changed files with 9 additions and 33 deletions
|
@ -19,9 +19,7 @@ use std::io::{BufRead, BufReader};
|
||||||
use clap::{crate_version, App, Arg};
|
use clap::{crate_version, App, Arg};
|
||||||
|
|
||||||
mod options {
|
mod options {
|
||||||
pub const SH: &str = "sh";
|
|
||||||
pub const BOURNE_SHELL: &str = "bourne-shell";
|
pub const BOURNE_SHELL: &str = "bourne-shell";
|
||||||
pub const CSH: &str = "csh";
|
|
||||||
pub const C_SHELL: &str = "c-shell";
|
pub const C_SHELL: &str = "c-shell";
|
||||||
pub const PRINT_DATABASE: &str = "print-database";
|
pub const PRINT_DATABASE: &str = "print-database";
|
||||||
pub const FILE: &str = "FILE";
|
pub const FILE: &str = "FILE";
|
||||||
|
@ -75,52 +73,33 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
let usage = get_usage();
|
let usage = get_usage();
|
||||||
|
|
||||||
/* Clap has .visible_alias, but it generates help like this
|
|
||||||
* -b, --sh output Bourne shell code to set LS_COLORS [aliases: bourne-shell]
|
|
||||||
* whereas we want help like this
|
|
||||||
* -b, --sh output Bourne shell code to set LS_COLORS
|
|
||||||
* --bourne-shell output Bourne shell code to set LS_COLORS
|
|
||||||
* (or preferably like the original, but that doesn't seem possible with clap:)
|
|
||||||
* -b, --sh, --bourne-shell output Bourne shell code to set LS_COLORS
|
|
||||||
* therefore, command aliases are defined manually as multiple commands
|
|
||||||
*/
|
|
||||||
let matches = App::new(executable!())
|
let matches = App::new(executable!())
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about(SUMMARY)
|
.about(SUMMARY)
|
||||||
.usage(&usage[..])
|
.usage(&usage[..])
|
||||||
.after_help(LONG_HELP)
|
.after_help(LONG_HELP)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::SH)
|
Arg::with_name(options::BOURNE_SHELL)
|
||||||
.long("sh")
|
.long("sh")
|
||||||
.short("b")
|
.short("b")
|
||||||
|
.visible_alias("bourne-shell")
|
||||||
.help("output Bourne shell code to set LS_COLORS")
|
.help("output Bourne shell code to set LS_COLORS")
|
||||||
.display_order(1),
|
.display_order(1),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::BOURNE_SHELL)
|
Arg::with_name(options::C_SHELL)
|
||||||
.long("bourne-shell")
|
|
||||||
.help("output Bourne shell code to set LS_COLORS")
|
|
||||||
.display_order(2),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name(options::CSH)
|
|
||||||
.long("csh")
|
.long("csh")
|
||||||
.short("c")
|
.short("c")
|
||||||
|
.visible_alias("c-shell")
|
||||||
.help("output C shell code to set LS_COLORS")
|
.help("output C shell code to set LS_COLORS")
|
||||||
.display_order(3),
|
.display_order(2),
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name(options::C_SHELL)
|
|
||||||
.long("c-shell")
|
|
||||||
.help("output C shell code to set LS_COLORS")
|
|
||||||
.display_order(4),
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::PRINT_DATABASE)
|
Arg::with_name(options::PRINT_DATABASE)
|
||||||
.long("print-database")
|
.long("print-database")
|
||||||
.short("p")
|
.short("p")
|
||||||
.help("print the byte counts")
|
.help("print the byte counts")
|
||||||
.display_order(5),
|
.display_order(3),
|
||||||
)
|
)
|
||||||
.arg(Arg::with_name(options::FILE).hidden(true).multiple(true))
|
.arg(Arg::with_name(options::FILE).hidden(true).multiple(true))
|
||||||
.get_matches_from(&args);
|
.get_matches_from(&args);
|
||||||
|
@ -131,10 +110,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
// clap provides .conflicts_with / .conflicts_with_all, but we want to
|
// clap provides .conflicts_with / .conflicts_with_all, but we want to
|
||||||
// manually handle conflicts so we can match the output of GNU coreutils
|
// manually handle conflicts so we can match the output of GNU coreutils
|
||||||
if (matches.is_present(options::CSH)
|
if (matches.is_present(options::C_SHELL) || matches.is_present(options::BOURNE_SHELL))
|
||||||
|| matches.is_present(options::C_SHELL)
|
|
||||||
|| matches.is_present(options::SH)
|
|
||||||
|| matches.is_present(options::BOURNE_SHELL))
|
|
||||||
&& matches.is_present(options::PRINT_DATABASE)
|
&& matches.is_present(options::PRINT_DATABASE)
|
||||||
{
|
{
|
||||||
show_usage_error!(
|
show_usage_error!(
|
||||||
|
@ -158,9 +134,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut out_format = OutputFmt::Unknown;
|
let mut out_format = OutputFmt::Unknown;
|
||||||
if matches.is_present(options::CSH) || matches.is_present(options::C_SHELL) {
|
if matches.is_present(options::C_SHELL) {
|
||||||
out_format = OutputFmt::CShell;
|
out_format = OutputFmt::CShell;
|
||||||
} else if matches.is_present(options::SH) || matches.is_present(options::BOURNE_SHELL) {
|
} else if matches.is_present(options::BOURNE_SHELL) {
|
||||||
out_format = OutputFmt::Shell;
|
out_format = OutputFmt::Shell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue