Skip to content

Commit

Permalink
add option to create ext when adding weakdeps
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Sep 8, 2024
1 parent 299a356 commit d9225f4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
26 changes: 25 additions & 1 deletion src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1677,9 +1677,33 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}, new_git=Set{UUID}();
else
record_project_hash(ctx.env)
write_env(ctx.env)
names_str = join(names, ", ")
names_str = join(names, ", ", " and ")
printpkgstyle(ctx.io, :Added, "$names_str to [$(target)]")
end
if target == :weakdeps
possible_extension_name = join(names) * "Ext"
if !haskey(ctx.env.project.exts, possible_extension_name)
plural = length(names) > 1 ? "these weak dependencies" : "this weak dependency"
printpkgstyle(
ctx.io,
:Option,
"Would you like to create a new entry for extension `$possible_extension_name` with $(plural)? ",
color=Base.info_color(),
newline=false
)
ans = if isinteractive()
Base.prompt(stdin, ctx.io, "[Y/n]")
else
"y"
end
if lowercase(ans) in ("y", "")
ctx.env.project.exts[possible_extension_name] = collect(names)
record_project_hash(ctx.env)
write_env(ctx.env)
printpkgstyle(ctx.io, :Created, "extension $possible_extension_name")
end
end
end
return
end

Expand Down
23 changes: 12 additions & 11 deletions src/project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,19 @@ function destructure(project::Project)::Dict
should_delete(src) ? delete!(raw, key) : (raw[key] = src)
end

entry!("name", project.name)
entry!("uuid", project.uuid)
entry!("version", project.version)
entry!("name", project.name)
entry!("uuid", project.uuid)
entry!("version", project.version)
entry!("workspace", project.workspace)
entry!("manifest", project.manifest)
entry!("entryfile", project.entryfile)
entry!("deps", merge(project.deps, project._deps_weak))
entry!("weakdeps", project.weakdeps)
entry!("sources", project.sources)
entry!("extras", project.extras)
entry!("compat", Dict(name => x.str for (name, x) in project.compat))
entry!("targets", project.targets)
entry!("manifest", project.manifest)
entry!("entryfile", project.entryfile)
entry!("deps", merge(project.deps, project._deps_weak))
entry!("weakdeps", project.weakdeps)
entry!("sources", project.sources)
entry!("extras", project.extras)
entry!("compat", Dict(name => x.str for (name, x) in project.compat))
entry!("targets", project.targets)
entry!("extensions", project.exts)
return raw
end

Expand Down
5 changes: 3 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

function printpkgstyle(io::IO, cmd::Symbol, text::String, ignore_indent::Bool=false; color=:green)
function printpkgstyle(io::IO, cmd::Symbol, text::String, ignore_indent::Bool=false; color=:green, newline::Bool=true)
indent = textwidth(string(:Precompiling)) # "Precompiling" is the longest operation
ignore_indent && (indent = 0)
printstyled(io, lpad(string(cmd), indent), color=color, bold=true)
println(io, " ", text)
print(io, " ", text)
newline && println(io)
end

function linewrap(str::String; io = stdout_f(), padding = 0, width = Base.displaysize(io)[2])
Expand Down

0 comments on commit d9225f4

Please sign in to comment.