Skip to content

Commit

Permalink
Just rely on JSON for Interpreter codec
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed Oct 18, 2024
1 parent 0c6d7b9 commit 8a24b1b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Restyler/Config/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ module Restyler.Config.Interpreter
, readInterpreter
) where

import Restyler.Prelude hiding ((.=))
import Restyler.Prelude

import Autodocodec
import Data.Aeson (FromJSON, ToJSON)
import Autodocodec (HasCodec (..), codecViaAeson)
import Data.Aeson
import Data.Text qualified as T
import Restyler.ReadP
import System.FilePath (takeFileName)
Expand All @@ -26,16 +26,16 @@ data Interpreter
| Ruby
| Other Text
deriving stock (Eq, Show)
deriving (FromJSON, ToJSON) via (Autodocodec Interpreter)

instance FromJSON Interpreter where
parseJSON = withText "Interpreter" $ pure . interpreterFromText

instance ToJSON Interpreter where
-- N.B. this may not always work, but it works for now
toJSON = toJSON . T.toLower . show

instance HasCodec Interpreter where
codec =
stringConstCodec
$ (Sh, "sh")
:| [ (Bash, "bash")
, (Python, "python")
, (Ruby, "ruby")
]
codec = codecViaAeson "Interpreter" -- TODO

readInterpreter :: Text -> Maybe Interpreter
readInterpreter contents = do
Expand Down

0 comments on commit 8a24b1b

Please sign in to comment.