From 01bf79c915a53c6587ef3cad0f641f0b5f81af7b Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Feb 2015 13:39:15 +0100 Subject: much --query= --- env.nix | 1 + much.cabal | 1 + test5.hs | 31 ++++++++++++++++++++++++------- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/env.nix b/env.nix index 9a38cfe..86f17cc 100644 --- a/env.nix +++ b/env.nix @@ -20,6 +20,7 @@ let aeson cabal-install case-insensitive + docopt email-header friendly-time mime diff --git a/much.cabal b/much.cabal index 2be4209..32e0ab9 100644 --- a/much.cabal +++ b/much.cabal @@ -15,6 +15,7 @@ executable much , containers >=0.5 && <0.6 , deepseq >=1.3 && <1.4 , directory >=1.2 && <1.3 + , docopt >=0.6 && <0.7 , friendly-time >=0.3 && <0.4 , process >=1.2 && <1.3 , rosezipper >=0.2 && <0.3 diff --git a/test5.hs b/test5.hs index 3075b0a..76e8ec6 100644 --- a/test5.hs +++ b/test5.hs @@ -2,7 +2,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -module Main (main) where +module Main (main, mainWithArgs) where import qualified Data.ByteString.Lazy as LBS import qualified Data.Text as T @@ -25,6 +25,7 @@ import Event import RenderTreeView (renderTreeView) import Scanner (scan) import System.Directory +import System.Console.Docopt (getArgWithDefault, optionsWithUsage, shortOption) import System.Environment import System.Exit import System.IO @@ -54,11 +55,8 @@ data State = State , decrst :: [Int] } - -initState :: IO State -initState = do - let query = "tag:inbox AND NOT tag:killed" - +initState :: String -> IO State +initState query = do r_ <- either error id <$> Notmuch.search query return State @@ -84,7 +82,26 @@ initState = do main :: IO () main = - bracket initState cleanup startup + getArgs >>= mainWithArgs + + +mainWithArgs :: [String] -> IO () +mainWithArgs args = do + args' <- optionsWithUsage usage args + let query = getArgWithDefault args' defaultSearch (shortOption 'q') + bracket (initState query) cleanup startup + where + usage = unlines + [ "Command-line MUA using notmuch." + , "" + , "Usage:" + , " much [-q ]" + , "" + , "Options:" + , " -q , --query=" + , " Open specific search, defaults to " ++ (show defaultSearch) + ] + defaultSearch = "tag:inbox AND NOT tag:killed" cleanup :: State -> IO () -- cgit v1.2.3