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)
  • Loading branch information
DilumAluthge authored May 31, 2021
1 parent 6cf6b95 commit 2341a06
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 @@ -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

0 comments on commit 2341a06

Please sign in to comment.