Permalink
Browse files

Added 'uninstall' command

  • Loading branch information...
yrashk committed Jan 29, 2011
1 parent 7677742 commit dd5550e68434744ad2cc0cd7f480d820da5757f3
Showing with 46 additions and 0 deletions.
  1. +5 −0 README.md
  2. +41 −0 src/agner_main.erl
View
@@ -128,6 +128,11 @@ Alias for `agner fetch --build --install PACKAGE /tmp/<uniq_filename>`. A typica
or `agner install rebar -v @agner` to get `rebar` binary in your PATH. It is assumed that `install_command`
property will make use of AGNER_PREFIX OS environment variable (which defaults to `/usr/local`).
+ agner uninstall PACKAGE [-v/--version VERSION] [-s/--spec-file SPECFILE]
+
+Uninstall given package (and a particular VERSION of it, if specified). Will use local SPECFILE is `--spec-file`/`-s`
+option is passed.
+
agner versions PACKAGE
List the versions of the given `PACKAGE`
View
@@ -71,6 +71,14 @@ arg_proplist() ->
{version, $v, "version", {string, "@master"}, "Version"},
{spec, $s, "spec-file", string, "Use local specification file"}
]}},
+ {"uninstall",
+ {uninstall,
+ "Uninstalls previously installed package",
+ [
+ {package, undefined, undefined, string, "Package name"},
+ {version, $v, "version", {string, "@master"}, "Version"},
+ {spec, $s, "spec-file", string, "Use local specification file"}
+ ]}},
{"prefix",
{prefix,
"Shows location where particular package is installed",
@@ -258,6 +266,39 @@ handle_command(prefix, Opts) ->
end
end;
+handle_command(uninstall, Opts) ->
+ case proplists:get_value(package, Opts) of
+ undefined ->
+ io:format("ERROR: Package name required.~n");
+ Package ->
+ Version = proplists:get_value(version, Opts),
+ InstallPrefix = filename:join([os:getenv("AGNER_PREFIX"),"packages",Package ++ "-" ++ Version]),
+ case filelib:is_dir(InstallPrefix) of
+ true ->
+ io:format("Uninstalling...~n"),
+ Spec =
+ case proplists:get_value(spec, Opts) of
+ undefined ->
+ agner:spec(Package, Version);
+ File ->
+ {ok, T} = file:consult(File),
+ T
+ end,
+ os:cmd("rm -rf " ++ InstallPrefix),
+ case proplists:get_value(bin_files, Spec) of
+ undefined ->
+ ignore;
+ Files ->
+ lists:foreach(fun (File) ->
+ Symlink = filename:join(os:getenv("AGNER_BIN"),filename:basename(File)),
+ file:delete(Symlink)
+ end, Files)
+ end;
+ false ->
+ io:format("ERROR: This package hasn't been installed~n")
+ end
+ end;
+
handle_command(install, Opts) ->
TmpFile = temp_name(),
handle_command(fetch, [{build, true},{directory, TmpFile},{install, true},{addpath, false}|Opts]),

0 comments on commit dd5550e

Please sign in to comment.