-- | Provides Optparse utils.
--
-- @since 0.1
module Effectful.Optparse.Utils
  ( OsPath,
    osPath,
    validOsPath,
  )
where

import FileSystem.OsPath (OsPath)
import FileSystem.OsPath qualified as OsPath
import Options.Applicative (ReadM)
import Options.Applicative qualified as OA

-- | 'OsPath' 'OA.Option' reader.
--
-- @since 0.1
osPath :: ReadM OsPath
osPath :: ReadM OsPath
osPath = ReadM FilePath
forall s. IsString s => ReadM s
OA.str ReadM FilePath -> (FilePath -> ReadM OsPath) -> ReadM OsPath
forall a b. ReadM a -> (a -> ReadM b) -> ReadM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= FilePath -> ReadM OsPath
forall (m :: * -> *).
(HasCallStack, MonadFail m) =>
FilePath -> m OsPath
OsPath.encodeFail

-- | 'OsPath' 'OA.Option' reader. This includes validation i.e. fails if the
-- path is considered invalid on the given platform.
--
-- @since 0.1
validOsPath :: ReadM OsPath
validOsPath :: ReadM OsPath
validOsPath = ReadM FilePath
forall s. IsString s => ReadM s
OA.str ReadM FilePath -> (FilePath -> ReadM OsPath) -> ReadM OsPath
forall a b. ReadM a -> (a -> ReadM b) -> ReadM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= FilePath -> ReadM OsPath
forall (m :: * -> *).
(HasCallStack, MonadFail m) =>
FilePath -> m OsPath
OsPath.encodeValidFail