1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 20:47:46 +00:00

dircolors: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-29 16:59:51 +02:00
parent 811a06fd66
commit aaf1e362bf
2 changed files with 15 additions and 17 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/dircolors.rs" path = "src/dircolors.rs"
[dependencies] [dependencies]
clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
glob = "0.3.0" glob = "0.3.0"
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }

View file

@ -13,7 +13,7 @@ use std::env;
use std::fs::File; use std::fs::File;
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError, UUsageError}; use uucore::error::{UResult, USimpleError, UUsageError};
@ -75,9 +75,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// 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.contains_id(options::C_SHELL) || matches.contains_id(options::BOURNE_SHELL)) if (matches.get_flag(options::C_SHELL) || matches.get_flag(options::BOURNE_SHELL))
&& (matches.contains_id(options::PRINT_DATABASE) && (matches.get_flag(options::PRINT_DATABASE) || matches.get_flag(options::PRINT_LS_COLORS))
|| matches.contains_id(options::PRINT_LS_COLORS))
{ {
return Err(UUsageError::new( return Err(UUsageError::new(
1, 1,
@ -86,15 +85,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
)); ));
} }
if matches.contains_id(options::PRINT_DATABASE) && matches.contains_id(options::PRINT_LS_COLORS) if matches.get_flag(options::PRINT_DATABASE) && matches.get_flag(options::PRINT_LS_COLORS) {
{
return Err(UUsageError::new( return Err(UUsageError::new(
1, 1,
"options --print-database and --print-ls-colors are mutually exclusive", "options --print-database and --print-ls-colors are mutually exclusive",
)); ));
} }
if matches.contains_id(options::PRINT_DATABASE) { if matches.get_flag(options::PRINT_DATABASE) {
if !files.is_empty() { if !files.is_empty() {
return Err(UUsageError::new( return Err(UUsageError::new(
1, 1,
@ -109,11 +107,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
return Ok(()); return Ok(());
} }
let mut out_format = if matches.contains_id(options::C_SHELL) { let mut out_format = if matches.get_flag(options::C_SHELL) {
OutputFmt::CShell OutputFmt::CShell
} else if matches.contains_id(options::BOURNE_SHELL) { } else if matches.get_flag(options::BOURNE_SHELL) {
OutputFmt::Shell OutputFmt::Shell
} else if matches.contains_id(options::PRINT_LS_COLORS) { } else if matches.get_flag(options::PRINT_LS_COLORS) {
OutputFmt::Display OutputFmt::Display
} else { } else {
OutputFmt::Unknown OutputFmt::Unknown
@ -168,7 +166,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
} }
pub fn uu_app<'a>() -> Command<'a> { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) Command::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
@ -182,7 +180,7 @@ pub fn uu_app<'a>() -> Command<'a> {
.visible_alias("bourne-shell") .visible_alias("bourne-shell")
.overrides_with(options::C_SHELL) .overrides_with(options::C_SHELL)
.help("output Bourne shell code to set LS_COLORS") .help("output Bourne shell code to set LS_COLORS")
.display_order(1), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::C_SHELL) Arg::new(options::C_SHELL)
@ -191,26 +189,26 @@ pub fn uu_app<'a>() -> Command<'a> {
.visible_alias("c-shell") .visible_alias("c-shell")
.overrides_with(options::BOURNE_SHELL) .overrides_with(options::BOURNE_SHELL)
.help("output C shell code to set LS_COLORS") .help("output C shell code to set LS_COLORS")
.display_order(2), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::PRINT_DATABASE) Arg::new(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(3), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::PRINT_LS_COLORS) Arg::new(options::PRINT_LS_COLORS)
.long("print-ls-colors") .long("print-ls-colors")
.help("output fully escaped colors for display") .help("output fully escaped colors for display")
.display_order(4), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::FILE) Arg::new(options::FILE)
.hide(true) .hide(true)
.value_hint(clap::ValueHint::FilePath) .value_hint(clap::ValueHint::FilePath)
.multiple_occurrences(true), .action(ArgAction::Append),
) )
} }