mirror of
https://github.com/ruuda/rcl.git
synced 2025-12-23 04:47:19 +00:00
Make --output respect --directory
I should really add a test for this too ... but goldens are not really suitable for this. Let's leave it untested for now then?
This commit is contained in:
parent
b76e8d7a4b
commit
d88cbb2a83
4 changed files with 18 additions and 6 deletions
|
|
@ -45,7 +45,10 @@ output format is `json`.
|
|||
|
||||
### `-o` `--output <outfile>`
|
||||
|
||||
Write the output to the given file instead of stdout.
|
||||
Write the output to the given file instead of stdout. When [`--directory`][dir]
|
||||
is set, the output path is relative to that directory.
|
||||
|
||||
[dir]: rcl.md#-c-directory-dir
|
||||
|
||||
### `--sandbox <mode>`
|
||||
|
||||
|
|
|
|||
|
|
@ -29,9 +29,12 @@ exactly one input file.
|
|||
|
||||
### `-o` `--output <outfile>`
|
||||
|
||||
Write the output to the given file instead of stdout. This option is
|
||||
Write the output to the given file instead of stdout. When [`--directory`][dir]
|
||||
is set, the output path is relative to that directory. This option is
|
||||
incompatible with `--in-place`.
|
||||
|
||||
[dir]: rcl.md#-c-directory-dir
|
||||
|
||||
### `-w` `--width <width>`
|
||||
|
||||
Target width in columns. Must be an integer. Defaults to 80. Note that the
|
||||
|
|
|
|||
|
|
@ -50,10 +50,10 @@ pub struct PathLookup {
|
|||
/// A friendly name displayed to the user.
|
||||
///
|
||||
/// This is the path relative to the working directory if possible.
|
||||
name: String,
|
||||
pub name: String,
|
||||
|
||||
/// The absolute path on the file system to load the data from.
|
||||
path: PathBuf,
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
/// A filesystem resolves import paths to file contents.
|
||||
|
|
@ -328,6 +328,11 @@ impl Loader {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolve a path specified on the CLI so it respects the workdir.
|
||||
pub fn resolve_cli_path(&self, path: &str) -> Result<PathLookup> {
|
||||
self.filesystem.resolve_entrypoint(path)
|
||||
}
|
||||
|
||||
/// Borrow all documents.
|
||||
pub fn as_inputs(&self) -> Vec<Doc> {
|
||||
self.documents.iter().map(Document::as_doc).collect()
|
||||
|
|
|
|||
|
|
@ -35,11 +35,12 @@ impl App {
|
|||
|
||||
/// Write a string to a file.
|
||||
fn print_to_file(&self, out_path: &str, data: String) -> Result<()> {
|
||||
std::fs::write(out_path, data).map_err(|err| {
|
||||
let out_path = self.loader.resolve_cli_path(out_path)?;
|
||||
std::fs::write(&out_path.path, data).map_err(|err| {
|
||||
// The concat! macro is not exported, we'll make do with a vec here.
|
||||
let parts = vec![
|
||||
"Failed to write to file '".into(),
|
||||
Doc::highlight(out_path).into_owned(),
|
||||
Doc::highlight(&out_path.name).into_owned(),
|
||||
"': ".into(),
|
||||
err.to_string().into(),
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue