From 94c0e078841dd9593c9a6e0a210e2d05d0535b62 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Sun, 30 May 2021 20:03:23 -0400 Subject: [PATCH] Refactor `write_project`, and add a method for `write_project` that prints the project to an IO --- src/project.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/project.jl b/src/project.jl index c0263ef16e..9472230c88 100644 --- a/src/project.jl +++ b/src/project.jl @@ -182,12 +182,14 @@ function write_project(env::EnvCache) end write_project(project::Project, project_file::AbstractString) = write_project(destructure(project), project_file) -function write_project(project::Dict, project_file::AbstractString) - str = sprint() do io - TOML.print(io, project, sorted=true, by=key -> (project_key_order(key), key)) do x - (x isa UUID || x isa VersionNumber) && return string(x) - error("unhandled type `$(typeof(x))`") - end +function write_project(io::IO, project::Dict) + TOML.print(io, project, sorted=true, by=key -> (project_key_order(key), key)) do x + x isa UUID || x isa VersionNumber || pkgerror("unhandled type `$(typeof(x))`") + return string(x) end + return nothing +end +function write_project(project::Dict, project_file::AbstractString) + str = sprint(write_project, project) write(project_file, str) end