{-# LANGUAGE OverloadedStrings #-}
module ShortcutLinks
(
Result(..),
Shortcut,
allShortcuts,
useShortcut,
useShortcutFrom,
)
where
import Data.Text (Text)
import qualified Data.Text as T
import ShortcutLinks.All
import ShortcutLinks.Utils (format)
useShortcut
:: Text
-> Maybe Text
-> Text
-> Result Text
useShortcut = useShortcutFrom allShortcuts
useShortcutFrom
:: [([Text], Shortcut)]
-> Text
-> Maybe Text
-> Text
-> Result Text
useShortcutFrom shortcuts name option link =
let givenShortcut (names,_) = name `elem` names
in case filter givenShortcut shortcuts of
[] -> fail (format "there's no shortcut named '{}'" name)
[sh] -> (snd sh) option link
_ -> fail (format "there's more than one shortcut named '{}'" name)