Skip to content

Commit

Permalink
Better error message for Pkg.add(url) and Pkg.add(path).
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick authored and fredrikekre committed Jan 30, 2019
1 parent c77adfd commit 3ac39e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ preview_info() = printstyled("───── Preview mode ─────\n"; c

include("generate.jl")

function check_package_name(x::AbstractString)
function check_package_name(x::AbstractString, mode=nothing)
if !(occursin(Pkg.REPLMode.name_re, x))
pkgerror("$x is not a valid packagename")
message = "$x is not a valid packagename."
if mode !== nothing && any(occursin.(['\\','/'], x)) # maybe a url or a path
message *= "\nThe argument appears to be a URL or path, perhaps you meant " *
"`Pkg.$mode(PackageSpec(url=\"...\"))` or `Pkg.$mode(PackageSpec(path=\"...\"))`."
end
pkgerror(message)
end
return PackageSpec(x)
end

add_or_develop(pkg::Union{AbstractString, PackageSpec}; kwargs...) = add_or_develop([pkg]; kwargs...)
add_or_develop(pkgs::Vector{<:AbstractString}; kwargs...) =
add_or_develop([check_package_name(pkg) for pkg in pkgs]; kwargs...)
add_or_develop(pkgs::Vector{<:AbstractString}; mode::Symbol, kwargs...) =
add_or_develop([check_package_name(pkg, mode) for pkg in pkgs]; mode = mode, kwargs...)
add_or_develop(pkgs::Vector{PackageSpec}; kwargs...) = add_or_develop(Context(), pkgs; kwargs...)

function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, shared::Bool=true, kwargs...)
Expand Down
4 changes: 2 additions & 2 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ a package, also inside that package.
```julia
Pkg.add("Example") # Add a package from registry
Pkg.add(PackageSpec(name="Example", version="0.3")) # Specify version
Pkg.add(PackageSpec(url="https://github.com/JuliaLang/Example.jl", rev="master")) # From url
Pkg.add(PackageSpec(url="/remote/mycompany/juliapackages/OurPackage"))` # From path (has to be a gitrepo)
Pkg.add(PackageSpec(url="https://github.com/JuliaLang/Example.jl", rev="master")) # From url to remote gitrepo
Pkg.add(PackageSpec(url="/remote/mycompany/juliapackages/OurPackage"))` # From path to local gitrepo
```
See also [`PackageSpec`](@ref).
Expand Down

0 comments on commit 3ac39e8

Please sign in to comment.