{-# LANGUAGE LambdaCase                 #-}
{-# LANGUAGE MultiWayIf                 #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE TupleSections              #-}

module HS.Cmd.Use where

import           HS.Cfg.CfgFile
import           HS.Types


-- | command driver to configure installation manager priorities
cmdUse :: Cfg -> [Manager] -> IO ()
cmdUse :: Cfg -> [Manager] -> IO ()
cmdUse Cfg{Map Compiler Installation
CompilerVersion
InstallMode
Managers
_cfg_installations :: Cfg -> Map Compiler Installation
_cfg_compiler :: Cfg -> CompilerVersion
_cfg_mode :: Cfg -> InstallMode
_cfg_managers :: Cfg -> Managers
_cfg_installations :: Map Compiler Installation
_cfg_compiler :: CompilerVersion
_cfg_mode :: InstallMode
_cfg_managers :: Managers
..} [Manager]
ms = case [Manager]
ms of
  [] -> Builder -> IO ()
forall b. FromBuilder b => Builder -> b
fmtLn (Builder -> IO ()) -> Builder -> IO ()
forall a b. (a -> b) -> a -> b
$ Managers -> Builder
forall p. Buildable p => p -> Builder
build Managers
_cfg_managers
  [Manager]
_  -> CfgFile -> Managers -> IO ()
forall a. Buildable a => CfgFile -> a -> IO ()
save CfgFile
CF_managers (Managers -> IO ()) -> Managers -> IO ()
forall a b. (a -> b) -> a -> b
$ [Manager] -> Managers
Managers [Manager]
ms

-- | command driver to configure default @InstallMode@
cmdUseIM :: Cfg -> Maybe InstallMode -> IO ()
cmdUseIM :: Cfg -> Maybe InstallMode -> IO ()
cmdUseIM Cfg{Map Compiler Installation
CompilerVersion
InstallMode
Managers
_cfg_installations :: Map Compiler Installation
_cfg_compiler :: CompilerVersion
_cfg_mode :: InstallMode
_cfg_managers :: Managers
_cfg_installations :: Cfg -> Map Compiler Installation
_cfg_compiler :: Cfg -> CompilerVersion
_cfg_mode :: Cfg -> InstallMode
_cfg_managers :: Cfg -> Managers
..} Maybe InstallMode
mb = case Maybe InstallMode
mb of
  Maybe InstallMode
Nothing -> Builder -> IO ()
forall b. FromBuilder b => Builder -> b
fmtLn (Builder -> IO ()) -> Builder -> IO ()
forall a b. (a -> b) -> a -> b
$ InstallMode -> Builder
forall p. Buildable p => p -> Builder
build InstallMode
_cfg_mode
  Just InstallMode
im -> CfgFile -> InstallMode -> IO ()
forall a. Buildable a => CfgFile -> a -> IO ()
save CfgFile
CF_mode InstallMode
im

-- | command driver to configure default toolchain
cmdUseCp :: Cfg -> Maybe CompilerVersion -> IO ()
cmdUseCp :: Cfg -> Maybe CompilerVersion -> IO ()
cmdUseCp Cfg{Map Compiler Installation
CompilerVersion
InstallMode
Managers
_cfg_installations :: Map Compiler Installation
_cfg_compiler :: CompilerVersion
_cfg_mode :: InstallMode
_cfg_managers :: Managers
_cfg_installations :: Cfg -> Map Compiler Installation
_cfg_compiler :: Cfg -> CompilerVersion
_cfg_mode :: Cfg -> InstallMode
_cfg_managers :: Cfg -> Managers
..} Maybe CompilerVersion
mb = case Maybe CompilerVersion
mb of
  Maybe CompilerVersion
Nothing -> Builder -> IO ()
forall b. FromBuilder b => Builder -> b
fmtLn (Builder -> IO ()) -> Builder -> IO ()
forall a b. (a -> b) -> a -> b
$ CompilerVersion -> Builder
forall p. Buildable p => p -> Builder
build CompilerVersion
_cfg_compiler
  Just CompilerVersion
cp -> CfgFile -> CompilerVersion -> IO ()
forall a. Buildable a => CfgFile -> a -> IO ()
save CfgFile
CF_compiler CompilerVersion
cp