Module uucore::backup_control
source · [−]Expand description
Implement GNU-style backup functionality.
This module implements the backup functionality as described in the GNU manual. It provides
- pre-defined
clap
-Arguments for inclusion in utilities that implement backups - determination of the backup mode
- determination of the backup suffix
- backup target path construction
- Error types for backup-related errors
- GNU-compliant help texts for backup-related errors
Backup-functionality is implemented by the following utilities:
cp
install
ln
mv
Usage example
#[macro_use]
extern crate uucore;
use clap::{Command, Arg, ArgMatches};
use std::path::{Path, PathBuf};
use uucore::backup_control::{self, BackupMode};
use uucore::error::{UError, UResult};
fn main() {
let usage = String::from("command [OPTION]... ARG");
let long_usage = String::from("And here's a detailed explanation");
let matches = Command::new("command")
.arg(backup_control::arguments::backup())
.arg(backup_control::arguments::backup_no_args())
.arg(backup_control::arguments::suffix())
.override_usage(&usage[..])
.after_help(&*format!(
"{}\n{}",
long_usage,
backup_control::BACKUP_CONTROL_LONG_HELP
))
.get_matches_from(vec![
"command", "--backup=t", "--suffix=bak~"
]);
let backup_mode = match backup_control::determine_backup_mode(&matches) {
Err(e) => {
show!(e);
return;
},
Ok(mode) => mode,
};
let backup_suffix = backup_control::determine_backup_suffix(&matches);
let target_path = Path::new("/tmp/example");
let backup_path = backup_control::get_backup_path(
backup_mode, target_path, &backup_suffix
);
// Perform your backups here.
}
Modules
Arguments for backup-related functionality.
Enums
Backup error types.
Available backup modes.
Statics
Functions
Determine the “mode” for the backup operation to perform, if any.
Obtain the suffix to use for a backup.