MCPcopy Create free account
hub / github.com/codeinred/untree / create_path

Function create_path

lib/functions.rs:74–96  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

72/// or directory, but don't actually create it (`options.dry_run` implies
73/// verbose)
74pub 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
98fn normalize_path(path: &Path) -> PathBuf {
99 let mut result = PathBuf::new();

Callers 1

create_treeFunction · 0.85

Calls 3

touch_fileFunction · 0.85
touch_directoryFunction · 0.85
is_verboseMethod · 0.80

Tested by

no test coverage detected