1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-03 06:27:45 +00:00

shred: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-30 16:32:48 +02:00
parent 4cfc90c077
commit dfdd55b428
2 changed files with 19 additions and 16 deletions

View file

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

View file

@ -8,7 +8,7 @@
// spell-checker:ignore (words) writeback wipesync // spell-checker:ignore (words) writeback wipesync
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use rand::prelude::SliceRandom; use rand::prelude::SliceRandom;
use rand::Rng; use rand::Rng;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
@ -296,15 +296,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// TODO: implement --random-source // TODO: implement --random-source
let force = matches.contains_id(options::FORCE); let force = matches.get_flag(options::FORCE);
let remove = matches.contains_id(options::REMOVE); let remove = matches.get_flag(options::REMOVE);
let size_arg = matches let size_arg = matches
.get_one::<String>(options::SIZE) .get_one::<String>(options::SIZE)
.map(|s| s.to_string()); .map(|s| s.to_string());
let size = get_size(size_arg); let size = get_size(size_arg);
let exact = matches.contains_id(options::EXACT) && size.is_none(); // if -s is given, ignore -x let exact = matches.get_flag(options::EXACT) && size.is_none(); // if -s is given, ignore -x
let zero = matches.contains_id(options::ZERO); let zero = matches.get_flag(options::ZERO);
let verbose = matches.contains_id(options::VERBOSE); let verbose = matches.get_flag(options::VERBOSE);
for path_str in matches.get_many::<String>(options::FILE).unwrap() { for path_str in matches.get_many::<String>(options::FILE).unwrap() {
show_if_err!(wipe_file( show_if_err!(wipe_file(
@ -314,7 +314,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(()) Ok(())
} }
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)
@ -325,7 +325,8 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::FORCE) Arg::new(options::FORCE)
.long(options::FORCE) .long(options::FORCE)
.short('f') .short('f')
.help("change permissions to allow writing if necessary"), .help("change permissions to allow writing if necessary")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::ITERATIONS) Arg::new(options::ITERATIONS)
@ -339,7 +340,6 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::SIZE) Arg::new(options::SIZE)
.long(options::SIZE) .long(options::SIZE)
.short('s') .short('s')
.takes_value(true)
.value_name("N") .value_name("N")
.help("shred this many bytes (suffixes like K, M, G accepted)"), .help("shred this many bytes (suffixes like K, M, G accepted)"),
) )
@ -347,13 +347,15 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::REMOVE) Arg::new(options::REMOVE)
.short('u') .short('u')
.long(options::REMOVE) .long(options::REMOVE)
.help("truncate and remove file after overwriting; See below"), .help("truncate and remove file after overwriting; See below")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::VERBOSE) Arg::new(options::VERBOSE)
.long(options::VERBOSE) .long(options::VERBOSE)
.short('v') .short('v')
.help("show progress"), .help("show progress")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::EXACT) Arg::new(options::EXACT)
@ -362,19 +364,20 @@ pub fn uu_app<'a>() -> Command<'a> {
.help( .help(
"do not round file sizes up to the next full block;\n\ "do not round file sizes up to the next full block;\n\
this is the default for non-regular files", this is the default for non-regular files",
), )
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::ZERO) Arg::new(options::ZERO)
.long(options::ZERO) .long(options::ZERO)
.short('z') .short('z')
.help("add a final overwrite with zeros to hide shredding"), .help("add a final overwrite with zeros to hide shredding")
.action(ArgAction::SetTrue),
) )
// Positional arguments // Positional arguments
.arg( .arg(
Arg::new(options::FILE) Arg::new(options::FILE)
.hide(true) .action(ArgAction::Append)
.multiple_occurrences(true)
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
) )
} }