pub(crate) fn resolve_output_path(
output: Option<&str>,
default_file_name: &str,
) -> Result<PathBuf>Expand description
Resolve where to write a command’s file output, porting CliUtils.saveFile’s rules exactly:
output | result |
|---|---|
| absent / empty | <cwd>/<default_file_name>, no directories created |
no path separator (report.json) | <cwd>/report.json, no directories created |
trailing separator (out/) | out/<default_file_name>, mkdir -p out |
separator, no trailing (out/x.json) | out/x.json, mkdir -p out |
The “no separator” case deliberately does not create directories — there are none to create — which is why it is distinct from the third row rather than folded into it.
Relative results are made absolute against the current directory (legacy’s
path.resolve). The resolved path is checked for .. segments; the resolution happens
first so a .. hidden behind a relative prefix is still caught.