63 lines
1.9 KiB
Rust
63 lines
1.9 KiB
Rust
// SPDX-FileCopyrightText: Matteo Settenvini <matteo.settenvini@montecristosoftware.eu>
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use clap::{builder::{PathBufValueParser, TypedValueParser}, Parser};
|
|
|
|
#[derive(Clone, Default)]
|
|
struct AbsolutePathBufValueParser;
|
|
|
|
impl TypedValueParser for AbsolutePathBufValueParser {
|
|
type Value = PathBuf;
|
|
|
|
fn parse_ref(
|
|
&self,
|
|
cmd: &clap::Command,
|
|
arg: Option<&clap::Arg>,
|
|
value: &std::ffi::OsStr,
|
|
) -> Result<Self::Value, clap::Error> {
|
|
let pathbuf_parser = PathBufValueParser::new();
|
|
let v = pathbuf_parser.parse_ref(cmd, arg, value)?;
|
|
|
|
v.canonicalize().map_err(|e| clap::Error::raw(
|
|
clap::error::ErrorKind::Io,
|
|
e,
|
|
))
|
|
}
|
|
}
|
|
|
|
/// A tool to clean up sysroots for Linux embedded devices to save storage space.
|
|
#[derive(Parser, Debug)]
|
|
#[command(version, about, long_about = None)]
|
|
pub struct Args {
|
|
/// Simulate operations without carrying them out
|
|
#[arg(short = 'n', long, default_value_t = false)]
|
|
pub dry_run: bool,
|
|
|
|
/// Instead of simply removing files, move them to the
|
|
/// given location, preserving their relative folder structure
|
|
#[arg(long)]
|
|
pub split_to: Option<PathBuf>,
|
|
|
|
/// An allowlist of files to keep, in .gitignore format.
|
|
/// Can be passed multiple times.
|
|
/// Note: this will take precedence over all other removal decisions.
|
|
#[arg(long, value_parser = AbsolutePathBufValueParser::default())]
|
|
pub allowlist: Vec<PathBuf>,
|
|
|
|
/// A blocklist of files to remove, in .gitignore format.
|
|
/// Can be passed multiple times.
|
|
#[arg(long)]
|
|
pub blocklist: Vec<PathBuf>,
|
|
|
|
/// An optional path to save the file graph of the DSO cleaner
|
|
/// in GraphViz format. Useful for debugging.
|
|
#[arg(long)]
|
|
pub output_dotfile: Option<PathBuf>,
|
|
|
|
/// The location of the sysroot to clean up
|
|
pub sysroot_location: PathBuf,
|
|
}
|
|
|