tbl_core/filesystem/
inputs.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::TblError;
use std::path::PathBuf;

/// get file paths
pub fn get_input_paths(
    inputs: &Option<Vec<PathBuf>>,
    tree: bool,
    sort: bool,
) -> Result<Vec<PathBuf>, TblError> {
    // get paths
    let raw_paths = match inputs {
        Some(raw_paths) => raw_paths.to_vec(),
        None => vec![std::env::current_dir()?],
    };

    // expand tree if specified
    let mut paths: Vec<PathBuf> = vec![];
    for raw_path in raw_paths.into_iter() {
        if raw_path.is_dir() {
            let sub_paths = if tree {
                super::gather::get_tree_tabular_files(&raw_path)?
            } else {
                super::gather::get_directory_tabular_files(&raw_path)?
            };
            paths.extend(sub_paths);
        } else if super::gather::is_tabular_file(&raw_path) {
            paths.push(raw_path);
        } else {
            println!("skipping non-tabular file {:?}", raw_path)
        }
    }

    // sort
    if sort {
        paths.sort()
    }

    Ok(paths)
}