module Docs.CLI.Directory where
import System.Directory (createDirectoryIfMissing, getXdgDirectory, XdgDirectory(..))
import System.FilePath
newtype AppCache = AppCache FilePath
mkAppCacheDir :: Maybe FilePath
-> IO AppCache
mkAppCacheDir :: Maybe FilePath -> IO AppCache
mkAppCacheDir Maybe FilePath
mpath = do
FilePath
dir <- (FilePath -> FilePath -> FilePath
</> FilePath
"html_cache") forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Maybe FilePath
mpath of
Just FilePath
path -> forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
path
Maybe FilePath
Nothing -> XdgDirectory -> FilePath -> IO FilePath
getXdgDirectory XdgDirectory
XdgCache FilePath
"haskell-docs-cli"
Bool -> FilePath -> IO ()
createDirectoryIfMissing Bool
True FilePath
dir
return $ FilePath -> AppCache
AppCache FilePath
dir
getAppHistoryFile :: IO FilePath
getAppHistoryFile :: IO FilePath
getAppHistoryFile = do
FilePath
dir <- XdgDirectory -> FilePath -> IO FilePath
getXdgDirectory XdgDirectory
XdgData FilePath
"haskell-docs-cli"
Bool -> FilePath -> IO ()
createDirectoryIfMissing Bool
True FilePath
dir
return (FilePath
dir FilePath -> FilePath -> FilePath
</> FilePath
"haskell-docs-cli.history")