Skip to content

Commit

Permalink
Refactor write_project, and add a method for write_project that p…
Browse files Browse the repository at this point in the history
…rints the project to an IO (#2581)

(cherry picked from commit 2341a06)
  • Loading branch information
DilumAluthge authored and KristofferC committed Jun 7, 2021
1 parent d6c5399 commit 36f71aa
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,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

0 comments on commit 36f71aa

Please sign in to comment.