Add preliminary arguments handling
This commit is contained in:
parent
b45c3ad8f1
commit
2bfc5a440d
38
src/Main.hs
38
src/Main.hs
@ -1,10 +1,14 @@
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
|
||||
import Types
|
||||
import Pretty
|
||||
import Parser
|
||||
|
||||
import Control.Monad (when)
|
||||
import Data.List (isInfixOf)
|
||||
import System.FilePath (takeBaseName)
|
||||
import System.Process (readProcess, callCommand)
|
||||
import System.Console.ArgParser
|
||||
|
||||
|
||||
-- Search functions --
|
||||
@ -51,10 +55,40 @@ sendClipboard text =
|
||||
callCommand $ "echo " ++ (show text) ++ " | pbcopy"
|
||||
|
||||
|
||||
-- CLI arguments --
|
||||
|
||||
data ProgArgs = ProgArgs
|
||||
{ searchTerm :: String
|
||||
, keychain :: FilePath
|
||||
, exactMatches :: String
|
||||
, resultsLimit :: Int
|
||||
, contentOnly :: Bool
|
||||
, noClipboard :: Bool
|
||||
} deriving (Show)
|
||||
|
||||
parser :: ParserSpec ProgArgs
|
||||
parser = ProgArgs
|
||||
`parsedBy` reqPos "term" `Descr` "Keychain search term"
|
||||
`andBy` optFlag "" "keychain" `Descr` "Use a specific keychain"
|
||||
`andBy` optFlag "" "exact" `Descr` "Only return exact matches"
|
||||
`andBy` optFlag 10 "limit" `Descr` "Set upper results limit"
|
||||
`andBy` boolFlag "content" `Descr` "Print only the items content"
|
||||
`andBy` boolFlag "clipboard" `Descr` "Disable clipboard paste"
|
||||
|
||||
interface :: IO (CmdLnInterface ProgArgs)
|
||||
interface =
|
||||
(`setAppDescr` "Quickly access the OSX keychain") <$>
|
||||
(`setAppEpilog` "TODO") <$>
|
||||
mkApp parser
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
main = interface >>= (`runApp` search)
|
||||
|
||||
|
||||
search :: ProgArgs -> IO ()
|
||||
search ProgArgs {..} = do
|
||||
res <- fuzzy "gog.com" <$> getKeychain
|
||||
sendClipboard (content (head res))
|
||||
pprint res
|
||||
when (not noClipboard) (sendClipboard (content $ head res))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user