{-# OPTIONS_GHC -Wno-orphans #-}

-- | This module contains an instance for labels,
-- that causes labels to be interpreted as
-- strings, with @_@ replaced with @-@.
--
-- It is useful for shells, since it's
-- easier to type arguments with labels.
--
-- NB: @_@ is replaced with @-@.
module Procex.Shell.Labels where

import Data.Functor
import Data.Proxy (Proxy (..))
import GHC.OverloadedLabels (IsLabel (..))
import GHC.TypeLits (KnownSymbol, symbolVal)

instance (a ~ String, KnownSymbol l) => IsLabel l a where
  fromLabel :: a
fromLabel =
    Proxy l -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (Proxy l
forall k (t :: k). Proxy t
Proxy :: Proxy l) String -> (Char -> Char) -> String
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
      Char
'_' -> Char
'-'
      Char
x -> Char
x