Add some more command line options
This commit is contained in:
parent
7dd2a0bdad
commit
5e1555511d
1 changed files with 43 additions and 14 deletions
57
app/Main.hs
57
app/Main.hs
|
|
@ -12,15 +12,35 @@ import qualified Options.Applicative as O
|
||||||
import qualified TaskMachine.UI as TM
|
import qualified TaskMachine.UI as TM
|
||||||
|
|
||||||
data Options = Options
|
data Options = Options
|
||||||
{ oThemePaths :: [FilePath]
|
{ oConfigFile :: FilePath
|
||||||
, oExportDefaultTheme :: [String]
|
, oTaskDB :: FilePath
|
||||||
|
, oThemePaths :: [FilePath]
|
||||||
|
, oExportDefaultTheme :: [FilePath]
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
argParser :: O.Parser Options
|
argParser :: O.Parser Options
|
||||||
argParser = pure Options
|
argParser = pure Options
|
||||||
|
<*> configFile
|
||||||
|
<*> taskDB
|
||||||
<*> many themePaths
|
<*> many themePaths
|
||||||
<*> many exportDefaultTheme
|
<*> many exportDefaultTheme
|
||||||
where
|
where
|
||||||
|
configFile = O.strOption $ mconcat
|
||||||
|
[ O.short 'c'
|
||||||
|
, O.long "config"
|
||||||
|
, O.help "Specify the config file to be loaded."
|
||||||
|
, O.value "tasks.config"
|
||||||
|
, O.showDefault
|
||||||
|
, O.metavar "CONFIGFILE"
|
||||||
|
]
|
||||||
|
taskDB = O.strOption $ mconcat
|
||||||
|
[ O.short 'd'
|
||||||
|
, O.long "task-db"
|
||||||
|
, O.help "Specify the database file where the tasks are saved."
|
||||||
|
, O.value "tasks.db"
|
||||||
|
, O.showDefault
|
||||||
|
, O.metavar "TASKDB"
|
||||||
|
]
|
||||||
themePaths = O.strOption $ mconcat
|
themePaths = O.strOption $ mconcat
|
||||||
[ O.short 't'
|
[ O.short 't'
|
||||||
, O.long "theme"
|
, O.long "theme"
|
||||||
|
|
@ -37,39 +57,48 @@ argParser = pure Options
|
||||||
]
|
]
|
||||||
|
|
||||||
argParserInfo :: O.ParserInfo Options
|
argParserInfo :: O.ParserInfo Options
|
||||||
argParserInfo = O.info (O.helper <*> argParser) mempty
|
argParserInfo = O.info (O.helper <*> argParser) $ mconcat
|
||||||
|
[ O.fullDesc
|
||||||
|
]
|
||||||
|
|
||||||
-- Log an action (prefixes "-> ")
|
-- Log an action (prefixes "-> ")
|
||||||
action :: String -> IO ()
|
action :: String -> IO ()
|
||||||
action = putStrLn . ("-> " ++)
|
action = putStrLn . ("-> " ++)
|
||||||
|
|
||||||
-- Could probably implement using EitherT, but too lazy :)
|
-- Could probably implement using EitherT, but too lazy :)
|
||||||
loadThemes :: B.Theme -> [FilePath] -> IO (Either String B.Theme)
|
loadThemes :: B.Theme -> [FilePath] -> IO B.Theme
|
||||||
loadThemes theme [] = return $ Right theme
|
loadThemes theme [] = return theme
|
||||||
loadThemes theme (path:paths) = do
|
loadThemes theme (path:paths) = do
|
||||||
action $ "Loading theme " ++ show path ++ "."
|
action $ "Loading theme " ++ show path ++ "."
|
||||||
eModifiedTheme <- B.loadCustomizations path theme
|
eModifiedTheme <- B.loadCustomizations path theme
|
||||||
case eModifiedTheme of
|
case eModifiedTheme of
|
||||||
Left e -> return $ Left e
|
Left errMsg -> die errMsg
|
||||||
Right t -> loadThemes t paths
|
Right modifiedTheme -> loadThemes modifiedTheme paths
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
options <- O.execParser argParserInfo
|
options <- O.execParser argParserInfo
|
||||||
|
|
||||||
-- Good ol' debug print
|
-- Good ol' debug print
|
||||||
if False then putStrLn "- The Options -" >> (putStrLn $ show options) else return ()
|
when True $ do
|
||||||
|
putStrLn "- The Options -"
|
||||||
|
print options
|
||||||
|
putStrLn "- The End -"
|
||||||
|
putStrLn ""
|
||||||
|
|
||||||
-- Exporting default theme
|
-- Export default theme
|
||||||
forM_ (oExportDefaultTheme options) $ \path -> do
|
forM_ (oExportDefaultTheme options) $ \path -> do
|
||||||
action $ "Exporting default theme to " ++ show path ++ "."
|
action $ "Exporting default theme to " ++ show path ++ "."
|
||||||
B.saveTheme path TM.defaultTheme
|
B.saveTheme path TM.defaultTheme
|
||||||
|
|
||||||
-- Loading themes and running the program
|
-- Load config
|
||||||
eTheme <- loadThemes TM.defaultTheme $ oThemePaths options
|
-- TODO: Some config data type that contains the themes etc.
|
||||||
case eTheme of
|
|
||||||
Left errMsg -> die errMsg
|
-- Load themes and connect to db
|
||||||
Right theme -> error "Implement actual program logic" theme
|
theme <- loadThemes TM.defaultTheme $ oThemePaths options
|
||||||
|
|
||||||
|
-- Running the program
|
||||||
|
error "Implement actual program logic" theme
|
||||||
|
|
||||||
--import qualified Database.SQLite.Simple as DB
|
--import qualified Database.SQLite.Simple as DB
|
||||||
--import qualified TaskMachine.Database as TMD
|
--import qualified TaskMachine.Database as TMD
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue