Commit ec6ae1ef authored by Michael Hanus 's avatar Michael Hanus

Command "checkout" added

parent 20d2bc5b
......@@ -431,7 +431,18 @@ the global package cache.
\item[\fbox{\code{uninstall $package$ $version$}}] Uninstalls a specific version
of a package from the global package cache.
\item[\fbox{\code{upgrade}}] Upgrades all dependencies of the current package to
\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.
\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.
\item[\fbox{\code{upgrade}}]
Upgrades all dependencies of the current package to
the newest compatible version.
\item[\fbox{\code{upgrade $package$}}] Upgrades a specific dependency of the
......
......@@ -18,7 +18,8 @@ import CPM.ErrorLogger
import CPM.FileUtil (fileInPath)
import CPM.Config (Config (packageInstallDir), readConfiguration)
import CPM.PackageCache.Global (GlobalCache, readInstalledPackagesFromDir
, installFromZip, uninstallPackage)
, installFromZip, checkoutPackage
, uninstallPackage)
import CPM.Package
import CPM.Resolution (showResult)
import CPM.Repository (Repository, readRepository, findVersion, listPackages
......@@ -68,8 +69,9 @@ runWithArgs opts = do
result <- case optCommand opts of
NoCommand -> failIO "NoCommand"
Deps -> deps config repo globalCache
PkgInfo o -> info o config repo globalCache
Install o -> install o config repo globalCache
PkgInfo o -> info o config repo globalCache
Checkout o -> checkout o config repo globalCache
Install o -> install o config repo globalCache
Compiler o -> compiler o config repo globalCache
Exec o -> exec o config repo globalCache
Diff o -> diff o config repo globalCache
......@@ -90,10 +92,11 @@ data Options = Options
data Command
= Deps
| NoCommand
| Install InstallOptions
| Checkout CheckoutOptions
| Install InstallOptions
| Uninstall UninstallOptions
| PkgInfo InfoOptions
| Compiler CompilerOptions
| PkgInfo InfoOptions
| Compiler CompilerOptions
| Update
| List ListOptions
| Search SearchOptions
......@@ -103,9 +106,14 @@ data Command
| Diff DiffOptions
| New
data CheckoutOptions = CheckoutOptions
{ coPackage :: String
, coVersion :: Maybe Version
, coPrerelease :: Bool }
data InstallOptions = InstallOptions
{ instTarget :: Maybe String
, instVersion :: Maybe Version
{ instTarget :: Maybe String
, instVersion :: Maybe Version
, instPrerelease :: Bool }
data UninstallOptions = UninstallOptions
......@@ -140,6 +148,11 @@ data DiffOptions = DiffOptions
, diffAPI :: Bool
, diffBehavior :: Bool }
checkoutOpts :: Options -> CheckoutOptions
checkoutOpts s = case optCommand s of
Checkout opts -> opts
_ -> CheckoutOptions "" Nothing False
installOpts :: Options -> InstallOptions
installOpts s = case optCommand s of
Install opts -> opts
......@@ -224,7 +237,20 @@ optionParser = optParser
<> metavar "LEVEL"
<> help "Log level for the application. Valid values are 'info' and 'debug'." )
<.> commands (metavar "COMMAND")
( command "install" (help "Install a package.") (\a -> Right $ a { optCommand = Install (installOpts a) })
( command "checkout" (help "Checkout a package.") Right --(\a -> Right $ a { optCommand = Checkout (checkoutOpts a) })
( arg (\s a -> Right $ a { optCommand = Checkout
(checkoutOpts a) { coPackage = s } })
( metavar "PACKAGE"
<> help "A package name or the path to a file" )
<.> arg (\s a -> readVersion' s >.> \v -> a { optCommand = Checkout (checkoutOpts a) { coVersion = Just v } })
( metavar "VERSION"
<> help "The package version"
<> optional )
<.> flag (\a -> Right $ a { optCommand = Checkout (checkoutOpts a) { coPrerelease = True } })
( short "p"
<> long "pre"
<> help "Try pre-release versions when searching for newest version.") )
<|> command "install" (help "Install a package.") (\a -> Right $ a { optCommand = Install (installOpts a) })
( arg (\s a -> Right $ a { optCommand = Install (installOpts a) { instTarget = Just s } })
( metavar "TARGET"
<> help "A package name or the path to a file"
......@@ -354,6 +380,21 @@ compiler o cfg repo gc = tryFindLocalPackageSpec "." |>=
unsetEnviron "CURRYPATH"
succeedIO ()
checkout :: CheckoutOptions -> Config -> Repository -> GlobalCache
-> IO (ErrorLogger ())
checkout (CheckoutOptions pkg Nothing pre) cfg repo gc =
case findLatestVersion repo pkg pre of
Nothing -> failIO $ "Package '" ++ pkg ++
"' not found in package repository."
Just p -> acquireAndInstallPackageWithDependencies cfg repo gc p >>
checkoutPackage cfg repo gc p
checkout (CheckoutOptions pkg (Just ver) _) cfg repo gc =
case findVersion repo pkg ver of
Nothing -> failIO $ "Package '" ++ pkg ++ "-" ++ showVersion ver ++
"' not found in package repository."
Just p -> acquireAndInstallPackageWithDependencies cfg repo gc p >>
checkoutPackage cfg repo gc p
install :: InstallOptions -> Config -> Repository -> GlobalCache
-> IO (ErrorLogger ())
install (InstallOptions Nothing Nothing _) cfg repo gc =
......
......@@ -18,6 +18,7 @@ module CPM.PackageCache.Global
, tryFindPackage
, missingPackages
, installFromZip
, checkoutPackage
, uninstallPackage
, emptyCache
) where
......@@ -223,6 +224,22 @@ installMissingDependencies cfg gc deps = if length missing > 0
missingPackages :: GlobalCache -> [Package] -> [Package]
missingPackages gc = filter (not . isPackageInstalled gc)
--- Checkout a package from the global package cache.
checkoutPackage :: Config -> Repository -> GlobalCache -> Package
-> IO (ErrorLogger ())
checkoutPackage cfg _ _ pkg = do
sexists <- doesDirectoryExist pkgDir
texists <- doesDirectoryExist pkgId
if texists
then log Error $ "Package '" ++ pkgId ++ "' already checked out."
else if sexists
then copyDirectory pkgDir pkgId >> log Info logMsg
else log Info $ "Package '" ++ pkgId ++ "' is not installed."
where
pkgDir = (packageInstallDir cfg) </> pkgId
pkgId = name pkg ++ "-" ++ showVersion (version pkg)
logMsg = "Package '" ++ pkgId ++ "' checked out into local directory."
--- Removes a package from the global package cache.
uninstallPackage :: Config -> Repository -> GlobalCache -> String -> Version
-> IO (ErrorLogger ())
......
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