genpac 0.1.0

Sandbox for Gentoo ebuild development using bubblewrap
// Copyright (C) 2023 Gokul Das B
// SPDX-License-Identifier: GPL-3.0-or-later
//! CLI module for remap subcommand

use crate::GlobalsFinal;
use anyhow::Result as AResult;
use clap::Args;
use std::path::PathBuf;

/// Remap UID and GID of stage3 tarball
#[derive(Args)]
pub struct SubCmdArgs {
    /// Source tarball to convert from (usually stage3-*.tar.xz)
    source: PathBuf,
    /// Destination tarball
    destination: PathBuf,
}

impl SubCmdArgs {
    pub fn handle(&self, globals: GlobalsFinal) -> AResult<()> {
        if !self.source.is_file() {
            let e = format!("File {} doesn't exist", self.source.display());
            log::error!("{e}");
            anyhow::bail!(e);
        }
        log::debug!(
            "Source archive (PAX fmt assumed) : {}",
            self.source.display()
        );
        log::debug!(
            "Destination archive (GNU fmt)    : {}",
            self.destination.display()
        );
        super::convert::convert(&self.source, &self.destination, &globals)?;
        Ok(())
    }
}