@@ -835,7 +835,7 @@ function open_browser(url::AbstractString)
835835end
836836
837837"""
838- install(server::AbstractString; maxcount = 3)
838+ install(server::AbstractString; maxcount = 3) -> PkgAuthentication.Uninstall
839839
840840Install Pkg authentication hooks for the Pkg server specified by `server`. Also
841841sets the `$(pkg_server_env_var_name) ` environment variable to `server`.
@@ -858,12 +858,11 @@ julia> PkgAuthentication.install("my-pkg-server.example.com"; maxcount = 5)
858858"""
859859function install (server:: AbstractString ; maxcount:: Integer = 3 )
860860 ENV [pkg_server_env_var_name] = server
861- install (; maxcount= maxcount)
862- return nothing
861+ return install (; maxcount= maxcount)
863862end
864863
865864"""
866- install(; maxcount = 3)
865+ install(; maxcount = 3) -> PkgAuthentication.Uninstall
867866
868867Install Pkg authentication hooks for the Pkg server specified in the `$(pkg_server_env_var_name) `
869868environment variable.
@@ -873,6 +872,8 @@ must be set to the URL of a valid Pkg server.
873872
874873`maxcount` determines the number of retries.
875874
875+ You can call the returned object (no arguments) to uninstall the Pkg authentication hooks.
876+
876877!!! compat "Julia 1.4"
877878 Pkg authentication hooks require at least Julia 1.4. On earlier versions, this
878879 method will instead force authentication immediately.
@@ -881,8 +882,10 @@ must be set to the URL of a valid Pkg server.
881882
882883```julia
883884julia> PkgAuthentication.install()
885+ PkgAuthentication.Uninstall (call this object to remove Pkg hooks)
884886
885887julia> PkgAuthentication.install(; maxcount = 5)
888+ PkgAuthentication.Uninstall (call this object to remove Pkg hooks)
886889```
887890"""
888891function install (; maxcount:: Integer = 3 )
@@ -892,13 +895,15 @@ function install(; maxcount::Integer=3)
892895 _assert_pkg_server_env_var_is_set ()
893896 server = String (pkg_server ())
894897 auth_handler = generate_auth_handler (maxcount)
895- @static if PkgAuthentication. is_new_auth_mechanism ()
898+ uninstall_hook = @static if PkgAuthentication. is_new_auth_mechanism ()
896899 Pkg. PlatformEngines. register_auth_error_handler (server, auth_handler)
897900 else
898901 # old Julia versions don't support auth hooks, so let's authenticate now and be done with it
899902 authenticate (server)
903+ # the returned Uninstall will be a silent no-op
904+ nothing
900905 end
901- return nothing
906+ return Uninstall (uninstall_hook)
902907end
903908
904909function generate_auth_handler (maxcount:: Integer )
@@ -923,6 +928,27 @@ function generate_auth_handler(maxcount::Integer)
923928 return auth_handler
924929end
925930
931+ """
932+ struct Uninstall
933+
934+ Wrapper around the closure returned by `Pkg.PlatformEngines.register_auth_error_handler`.
935+ Callin
936+
937+ ```julia
938+ julia> uninstall = PkgAuthentication.install()
939+ PkgAuthentication.Uninstall (call this object to remove Pkg hooks)
940+
941+ julia> uninstall()
942+ ```
943+ """
944+ struct Uninstall
945+ f:: Union{Base.Callable, Nothing}
946+ end
947+ (c:: Uninstall )() = isnothing (c. f) ? nothing : c. f ()
948+ function Base. show (io:: IO , :: MIME"text/plain" , :: Uninstall )
949+ print (io, " PkgAuthentication.Uninstall (call this object to remove Pkg hooks)" )
950+ end
951+
926952include (" precompile.jl" )
927953
928954end # module
0 commit comments