Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Jan 9, 2025
1 parent 64a2500 commit b649bb7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
28 changes: 11 additions & 17 deletions app/Commands/Dev/Nockma/Encode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,29 @@ runCommand opts = runSimpleErrorIO $ do
EncodeBytes ->
case opts ^. nockmaEncodeApply of
Nothing -> renderStdOutRaw (jamToByteString from)
Just Cue -> case from of
Nockma.TermAtom a -> renderStdOutRaw (naturalToByteString (a ^. Nockma.atom))
Nockma.TermCell {} -> throw @SimpleError "Cannot cue a cell"
Just Cue -> termToByteString from >>= renderStdOutRaw
EncodeBase64 ->
case opts ^. nockmaEncodeApply of
Nothing -> renderStdOut (encodeJam64 from)
Just Cue -> case from of
Nockma.TermAtom a ->
renderStdOut
Just Cue ->
termToByteString from
>>= renderStdOut
. decodeUtf8
. Base64.encode
. naturalToByteString
$ a ^. Nockma.atom
Nockma.TermCell {} -> throw @SimpleError "Cannot cue a cell"
EncodeText ->
case opts ^. nockmaEncodeApply of
Nothing -> renderStdOut (Nockma.ppSerialize from)
Just Cue -> case from of
Nockma.TermAtom a ->
(decodeCue . naturalToByteString $ a ^. Nockma.atom) >>= renderStdOut . Nockma.ppSerialize
Nockma.TermCell {} -> throw @SimpleError "Cannot cue a cell"
Just Cue -> termToByteString from >>= decodeCue >>= renderStdOut . Nockma.ppSerialize
EncodeDebug ->
case opts ^. nockmaEncodeApply of
Nothing -> renderStdOut (Nockma.ppPrint from)
Just Cue -> case from of
Nockma.TermAtom a ->
(decodeCue . naturalToByteString $ a ^. Nockma.atom) >>= renderStdOut . Nockma.ppPrint
Nockma.TermCell {} -> throw @SimpleError "Cannot cue a cell"
Just Cue -> termToByteString from >>= decodeCue >>= renderStdOut . Nockma.ppPrint
where
termToByteString :: (Members '[Error SimpleError] r') => Term Natural -> Sem r' ByteString
termToByteString = \case
Nockma.TermCell {} -> throw @SimpleError "Cannot cue a cell"
Nockma.TermAtom a -> return (naturalToByteString (a ^. Nockma.atom))

fromTextEncoding :: (Members '[App, EmbedIO] r') => Sem r' (Term Natural)
fromTextEncoding = do
bs <- getContents
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Nockma/Encode/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ parseNockmaEncodeOptions = do
optCue <-
switch
( long "cue"
<> help "Apply cue if the original encoding wasn't jammed"
<> help "Apply cue"
)
_nockmaEncodeTo <-
option
Expand Down

0 comments on commit b649bb7

Please sign in to comment.