Skip to content

Commit

Permalink
Add id completion
Browse files Browse the repository at this point in the history
  • Loading branch information
willbasky authored and cblp committed Sep 2, 2018
1 parent 7cfa787 commit dfb0af6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
26 changes: 16 additions & 10 deletions ff-core/lib/FF/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import Control.Applicative (optional, (<|>))
import Data.Semigroup ((<>))
import Data.Text (Text)
import Data.Time (Day)
import Options.Applicative (auto, command, execParser, flag',
fullDesc, help, helper, info, long,
metavar, option, progDesc, short,
strArgument, strOption, subparser, switch,
(<**>))

import FF.Storage (DocId (DocId))
import Options.Applicative (auto, command, completer, execParser,
flag', fullDesc, help, helper, info,
listIOCompleter, long, metavar, option,
progDesc, short, strArgument, strOption,
subparser, switch, (<**>))

import FF.Storage (DocId (DocId), Storage, listDocuments, rawDocId,
runStorage)
import qualified FF.Storage as Storage
import FF.Types (Limit, NoteId)

data Cmd
Expand Down Expand Up @@ -87,8 +89,8 @@ data Search = Search
, searchLimit :: Maybe Limit
}

parseOptions :: IO Options
parseOptions = execParser $ i parser "A note taker and task tracker"
parseOptions :: Storage.Handle -> IO Options
parseOptions h = execParser $ i parser "A note taker and task tracker"
where
parser = Options <$> brief <*>
(version <|> subparser commands <|> (CmdAction <$> cmdAgenda))
Expand Down Expand Up @@ -161,7 +163,8 @@ parseOptions = execParser $ i parser "A note taker and task tracker"
<*> optional start
<*> optional maybeEnd
search = Search <$> strArgument (metavar "TEXT") <*> optional limit
noteid = DocId <$> strArgument (metavar "ID" <> help "note id")
noteid = DocId <$> strArgument
(metavar "ID" <> help "note id" <> completer completeNoteIds)
text = strArgument $ metavar "TEXT" <> help "note text"
end = dateOption $ long "end" <> short 'e' <> help "end date"
limit = option auto $ long "limit" <> short 'l' <> help "Number of issues"
Expand Down Expand Up @@ -196,3 +199,6 @@ parseOptions = execParser $ i parser "A note taker and task tracker"
(long "version" <> short 'V' <> help "Current ff-note version")

i prsr desc = info (prsr <**> helper) $ fullDesc <> progDesc desc

completeNoteIds = listIOCompleter $
map rawDocId <$> runStorage h (listDocuments :: Storage [NoteId])
13 changes: 6 additions & 7 deletions ff/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ import Paths_ff (version)
main :: IO ()
main = do
cfg@Config { ui } <- loadConfig
Options {..} <- parseOptions
hClock <- newTVarIO =<< getRealLocalTime
hDataDir <- getDataDir cfg
let h = Storage.Handle{..}
Options {..} <- parseOptions h
case optionCmd of
CmdConfig param -> runCmdConfig cfg param
CmdAction action -> do
hClock <- newTVarIO =<< getRealLocalTime
hDataDir <- getDataDir cfg
let h = Storage.Handle{..}
runStorage h $ runCmdAction h ui action optionBrief
CmdVersion -> runCmdVersion
CmdAction action -> runStorage h $ runCmdAction h ui action optionBrief
CmdVersion -> runCmdVersion

getDataDir :: Config -> IO FilePath
getDataDir cfg = do
Expand Down

0 comments on commit dfb0af6

Please sign in to comment.