Commit 610c2545 authored by Michael Hanus 's avatar Michael Hanus

Uninstall for local packages added

parent ea6c5e60
......@@ -527,6 +527,8 @@ packages in the central package index for a term.
to the newest available version.
\item[\fbox{\code{install}}] Installs all dependencies of the current package.
Furthermore, if the current package contains an executable application,
the application is compiled and the executable is installed.
\item[\fbox{\code{install $package$ [--$pre$]}}] Installs the newest version of
a package to the global package cache. \code{--$pre$} enables the installation
......@@ -540,18 +542,21 @@ to the global package cache. The ZIP file must contain at least the
package description file \code{package.json} and the directory \code{src}
containing the Curry source files.
\item[\fbox{\code{uninstall}}] Uninstall the executable installed
for this package.
\item[\fbox{\code{uninstall $package$ $version$}}] Uninstalls a specific version
of a package from the global package cache.
\item[\fbox{\code{checkout $package$ [--$pre$]}}]
Checks out the newest version of a package into a local directory
in order to try or test its operations.
in order to test its operations or install a binary of the package..
\code{--$pre$} enables the installation of pre-release versions.
\item[\fbox{\code{checkout $package$ $version$}}]
Checks out a specific version of a package
into the local directory \code{$package$-$version$}
in order to try or test its operations.
in order to test its operations or install a binary of the package..
\item[\fbox{\code{upgrade}}]
Upgrades all dependencies of the current package to
......
......@@ -6,7 +6,8 @@ module CPM.Main where
import CSV (showCSV)
import Directory ( doesFileExist, getAbsolutePath, doesDirectoryExist
, createDirectory, getDirectoryContents, renameFile )
, createDirectory, getDirectoryContents, renameFile
, removeFile )
import Distribution (installDir, stripCurrySuffix)
import Either
import FilePath ((</>), splitSearchPath, takeExtension)
......@@ -37,7 +38,7 @@ cpmBanner :: String
cpmBanner = unlines [bannerLine,bannerText,bannerLine]
where
bannerText =
"Curry Package Manager <curry-language.org/tools/cpm> (version of 28/02/2017)"
"Curry Package Manager <curry-language.org/tools/cpm> (version of 01/03/2017)"
bannerLine = take (length bannerText) (repeat '-')
main :: IO ()
......@@ -140,8 +141,8 @@ data InstallOptions = InstallOptions
, instPrerelease :: Bool }
data UninstallOptions = UninstallOptions
{ uninstPackage :: String
, uninstVersion :: Version }
{ uninstPackage :: Maybe String
, uninstVersion :: Maybe Version }
data InfoOptions = InfoOptions
{ infoPackage :: Maybe String
......@@ -192,7 +193,7 @@ installOpts s = case optCommand s of
uninstallOpts :: Options -> UninstallOptions
uninstallOpts s = case optCommand s of
Uninstall opts -> opts
_ -> UninstallOptions "" (0, 0, 0, Nothing)
_ -> UninstallOptions Nothing Nothing
infoOpts :: Options -> InfoOptions
infoOpts s = case optCommand s of
......@@ -300,13 +301,17 @@ optionParser = optParser
( short "p"
<> long "pre"
<> help "Try pre-release versions when searching for newest version.") )
<|> command "uninstall" (help "Uninstall package") Right
( arg (\s a -> Right $ a { optCommand = Uninstall (uninstallOpts a) { uninstPackage = s } })
<|> command "uninstall" (help "Uninstall package")
(\a -> Right $ a { optCommand = Uninstall (uninstallOpts a) })
( arg (\s a -> Right $ a { optCommand =
Uninstall (uninstallOpts a) { uninstPackage = Just s } })
( metavar "PACKAGE"
<> help "The package to be uninstalled")
<.> arg (\s a -> readVersion' s >.> \v -> a { optCommand = Uninstall (uninstallOpts a) { uninstVersion = v } })
<> help "The package to be uninstalled"
<> optional)
<.> arg (\s a -> readVersion' s >.> \v -> a { optCommand = Uninstall (uninstallOpts a) { uninstVersion = Just v } })
( metavar "VERSION"
<> help "The version to be uninstalled") )
<> help "The version to be uninstalled"
<> optional) )
<|> command "deps" (help "Calculate dependencies") (\a -> Right $ a { optCommand = Deps }) []
<|> command "new" (help "Create a new package") (\a -> Right $ a { optCommand = New }) []
<|> command "update" (help "Update the package index")
......@@ -517,7 +522,7 @@ installExecutable cfg repo gc p =
bindir = binInstallDir cfg
binexec = bindir </> name
in compiler CompilerOptions { comCommand = cmd } cfg repo gc |>
log Info ("Installing executable `" ++ name ++ "' into `" ++
log Info ("Installing executable '" ++ name ++ "' into '" ++
bindir ++ "'") |>
(system ("rm -f " ++ binexec) >> renameFile mainmod binexec >>
checkPath path bindir))
......@@ -526,12 +531,28 @@ installExecutable cfg repo gc p =
checkPath path bindir =
if bindir `elem` splitSearchPath path
then succeedIO ()
else log Info $ "It is recommended to add `" ++bindir++ "' to your path!"
else log Info $ "It is recommended to add '" ++bindir++ "' to your path!"
uninstall :: UninstallOptions -> Config -> Repository -> GlobalCache
-> IO (ErrorLogger ())
uninstall (UninstallOptions pkg ver) cfg repo gc =
uninstall (UninstallOptions (Just pkg) (Just ver)) cfg repo gc =
uninstallPackage cfg repo gc pkg ver
uninstall (UninstallOptions (Just _) Nothing) _ _ _ =
log Error "Please provide a package and version number!"
uninstall (UninstallOptions Nothing (Just _)) _ _ _ =
log Error "Please provide a package and version number!"
uninstall (UninstallOptions Nothing Nothing) cfg _ _ =
tryFindLocalPackageSpec "." |>= \specDir ->
loadPackageSpec specDir |>= \pkg ->
maybe (succeedIO ())
(\ (PackageExecutable name _) ->
let binexec = binInstallDir cfg </> name
in (doesFileExist binexec >>= \exbin ->
if exbin
then removeFile binexec >>
log Info ("Executable '" ++ binexec ++ "' removed")
else log Info $ "Executable '" ++ binexec ++ "' not installed"))
(executableSpec pkg)
tryFindVersion :: String -> Version -> Repository -> IO (ErrorLogger Package)
tryFindVersion pkg ver repo = case findVersion repo pkg ver of
......@@ -707,7 +728,9 @@ newPackage = do
inpName <- askMandatory "What is the name of the new package?"
exists <- doesDirectoryExist inpName
if exists
then putStrLn "There is already a directory with that name. I can't overwrite directories!" >> exitWith 1
then do putStrLn $ "There is already a directory with that name. " ++
"I can't overwrite directories!"
exitWith 1
else return ()
inpVersionS <- askDefault "What is the first version of the package?" "0.0.1"
inpVersion <- case readVersion inpVersionS of
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment