shrun-0.9: A utility program for running shell commands concurrently.
Safe HaskellNone
LanguageGHC2021

Shrun.Configuration.Legend

Description

Provides types for the legend functionality.

Synopsis

Parsing

linesToMap :: List KeyVal -> Either DuplicateKeyError LegendMap Source #

Attempts to parse the given [KeyVal] into LegendMap. Duplicate keys are not allowed.

type LegendMap = HashMap Text (NESeq Text) Source #

Alias for our legend map.

Translation

translateCommands :: LegendMap -> NESeq Text -> Either CyclicKeyError (NESeq CommandP1) Source #

Returns a list of Text commands, potentially transforming a given string via the LegendMap legend.

Given a command string s, we first check if s exists as a key in legend. If it does not, we return s. If there is a key matching s, i.e.,

legend = fromList [...,(s, v),...]

where \(v = v_1,,\ldots,,v_n\), then we recursively search on each \(v_i\). We stop and return \(v_i\) when it does not exist as a key in the map.

Examples

Expand
>>> :set -XOverloadedLists
>>> :{
  let m = Map.fromList
        [ ("cmd1", "one" :<|| []),
          ("cmd2", "two" :<|| []),
          ("all", "cmd1" :<|| ["cmd2","other"])
        ]
      cmds = translateCommands m ("all" :<|| ["blah"])
  in (fmap . fmap) (view #command) cmds
:}
Right (fromList ("one" :| ["two","other","blah"]))

Note: If -- when looking up a line -- we detect a cycle, then a CyclicKeyError will be returned.

>>> :{
  let m = Map.fromList
        [ ("a", "b" :<|| []),
          ("b", "c" :<|| []),
          ("c", "a" :<|| [])
        ]
  in translateCommands m ("a" :<|| [])
:}
Left (MkCyclicKeyError "a -> b -> c -> a")