Create either a file (for `kind == PathKind::File`) or a directory (for `kind == PathKind::Directory`). Provides additional options in the form of `UntreeOptions`. If `options.verbose` is set, print out the creation of the file or directory. If `options.dry_run` is set, print out the creation of the file or directory, but don't actually create it (`options.dry_run` implies verbose)
(
path: &Path,
kind: PathKind,
options: UntreeOptions,
)
| 72 | /// or directory, but don't actually create it (`options.dry_run` implies |
| 73 | /// verbose) |
| 74 | pub fn create_path( |
| 75 | path: &Path, |
| 76 | kind: PathKind, |
| 77 | options: UntreeOptions, |
| 78 | ) -> Result<()> { |
| 79 | let name = path.to_str().unwrap_or("<unprintable>"); |
| 80 | |
| 81 | match (options.is_verbose(), kind) { |
| 82 | (false, _) => {} // Print nothing if is_verbose() is false |
| 83 | (_, FilePath) => { |
| 84 | println!("{} {}", "touch".bold().green(), name.bold().white()) |
| 85 | } |
| 86 | (_, Directory) => { |
| 87 | println!("{} -p {}", "mkdir".bold().green(), name.bold().blue()) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | match (options.dry_run, kind) { |
| 92 | (true, _) => Ok(()), // Do nothing when dry_run is true |
| 93 | (_, FilePath) => touch_file(path), |
| 94 | (_, Directory) => touch_directory(path), |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | fn normalize_path(path: &Path) -> PathBuf { |
| 99 | let mut result = PathBuf::new(); |
no test coverage detected