pimalaya-cli 0.1.1

CLI utils for Pimalaya
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! Reusable clap value parsers.

use std::path::PathBuf;

/// Shell-expands then canonicalizes a path argument, falling back to
/// the expanded path when it does not yet exist.
pub fn path_parser(path: &str) -> Result<PathBuf, String> {
    match shellexpand::full(path) {
        Ok(path) => {
            let path = PathBuf::from(&*path);
            Ok(path.canonicalize().unwrap_or(path))
        }
        Err(err) => Err(err.to_string()),
    }
}