46 lines
1.4 KiB
Haskell
46 lines
1.4 KiB
Haskell
{-# LANGUAGE TupleSections #-}
|
|
module Main where
|
|
|
|
import Options.Applicative
|
|
|
|
import Control.Monad.Buuka
|
|
(BuukaM, runBuukaM)
|
|
|
|
import Data.Environment
|
|
|
|
import UnliftIO.Directory
|
|
(XdgDirectory(XdgData), getXdgDirectory)
|
|
|
|
import Data.Foldable
|
|
(asum)
|
|
|
|
import System.Environment
|
|
(lookupEnv)
|
|
|
|
import qualified Operations
|
|
|
|
import Data.Query
|
|
(Field(..))
|
|
|
|
commands :: Parser (BuukaM ())
|
|
commands = subparser
|
|
( command "insert" (info (insertOpts Operations.insert <**> helper) (progDesc "Insert a new bookmark"))
|
|
<> command "list" (info (pure Operations.list <**> helper) (progDesc "List all the bookmarks"))
|
|
<> command "query" (info (queryOpts Operations.query <**> helper) (progDesc "Query the bookmarks"))
|
|
)
|
|
where
|
|
insertOpts f =
|
|
f <$> strOption (long "url" <> short 'u' <> metavar "URL")
|
|
<*> optional (strOption (long "title"))
|
|
queryOpts f =
|
|
uncurry f <$> asum [tagged Title "title", tagged Url "url"]
|
|
tagged t x = (t, ) <$> strOption (long x <> metavar "REGEX")
|
|
|
|
main :: IO ()
|
|
main = do
|
|
env <- Environment <$> (lookupEnv "BUUKA_HOME" >>= maybe defaultHome pure)
|
|
execParser (info (commands <**> helper) (fullDesc <> progDesc description)) >>= runBuukaM env
|
|
where
|
|
defaultHome = getXdgDirectory XdgData "buuka"
|
|
description = "Bookmarks manager. Stores the bookmarks in a yaml file under your xdg directory or in a folder specified by the BUUKA_HOME environment variable"
|