From d9225f4794cdd40162df32c3f7261513a4d7a1e0 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sun, 8 Sep 2024 08:11:25 -0400 Subject: [PATCH] add option to create ext when adding weakdeps --- src/Operations.jl | 26 +++++++++++++++++++++++++- src/project.jl | 23 ++++++++++++----------- src/utils.jl | 5 +++-- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/Operations.jl b/src/Operations.jl index 8efa29c042..b9379fa7ed 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -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 diff --git a/src/project.jl b/src/project.jl index f7a7e83757..b97c3d69d7 100644 --- a/src/project.jl +++ b/src/project.jl @@ -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 diff --git a/src/utils.jl b/src/utils.jl index 12826de397..320c15a640 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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])