Module uucore::backup_control[][src]

Expand description

Implement GNU-style backup functionality.

This module implements the backup functionality as described in the GNU manual. It provides

Backup-functionality is implemented by the following utilities:

  • cp
  • install
  • ln
  • mv

Usage example

#[macro_use]
extern crate uucore;

use clap::{App, Arg, ArgMatches};
use std::path::{Path, PathBuf};
use uucore::backup_control::{self, BackupMode};
use uucore::error::{UError, UResult};

fn main() {
    let usage = String::from("app [OPTION]... ARG");
    let long_usage = String::from("And here's a detailed explanation");

    let matches = App::new("app")
        .arg(backup_control::arguments::backup())
        .arg(backup_control::arguments::backup_no_args())
        .arg(backup_control::arguments::suffix())
        .usage(&usage[..])
        .after_help(&*format!(
            "{}\n{}",
            long_usage,
            backup_control::BACKUP_CONTROL_LONG_HELP
        ))
        .get_matches_from(vec![
            "app", "--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.