forked from matteo/sysroot-cleaner
fix: allow relative paths in allowlist and blocklist
This commit is contained in:
parent
085893c2ef
commit
8983863ffa
27
src/args.rs
27
src/args.rs
|
@ -3,7 +3,29 @@
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
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.
|
/// A tool to clean up sysroots for Linux embedded devices to save storage space.
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
@ -20,7 +42,7 @@ pub struct Args {
|
||||||
|
|
||||||
/// An allowlist of files to keep, in .gitignore format.
|
/// An allowlist of files to keep, in .gitignore format.
|
||||||
/// Note: this will take precedence over all other removal decisions.
|
/// Note: this will take precedence over all other removal decisions.
|
||||||
#[arg(long)]
|
#[arg(long, value_parser = AbsolutePathBufValueParser::default())]
|
||||||
pub allowlist: Option<PathBuf>,
|
pub allowlist: Option<PathBuf>,
|
||||||
|
|
||||||
/// A blocklist of files to remove, in .gitignore format.
|
/// A blocklist of files to remove, in .gitignore format.
|
||||||
|
@ -35,3 +57,4 @@ pub struct Args {
|
||||||
/// The location of the sysroot to clean up
|
/// The location of the sysroot to clean up
|
||||||
pub sysroot_location: PathBuf,
|
pub sysroot_location: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue