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

import FileSystem.OsPath (OsPath)
import FileSystem.OsPath qualified as OsPath
import FileSystem.OsString (OsString)
import FileSystem.OsString qualified as OsString
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 String
forall s. IsString s => ReadM s
OA.str ReadM String -> (String -> 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
>>= String -> ReadM OsPath
forall (m :: * -> *).
(HasCallStack, MonadFail m) =>
String -> 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 String
forall s. IsString s => ReadM s
OA.str ReadM String -> (String -> 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
>>= String -> ReadM OsPath
forall (m :: * -> *).
(HasCallStack, MonadFail m) =>
String -> m OsPath
OsPath.encodeValidFail

-- | 'OsString' 'OA.Option' reader.
--
-- @since 0.1
osString :: ReadM OsString
osString :: ReadM OsPath
osString = ReadM String
forall s. IsString s => ReadM s
OA.str ReadM String -> (String -> 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
>>= String -> ReadM OsPath
forall (m :: * -> *).
(HasCallStack, MonadFail m) =>
String -> m OsPath
OsString.encodeFail