twin/app/Main.hs
2023-07-30 22:54:04 +02:00

57 lines
1.3 KiB
Haskell

module Main where
import System.Directory
import System.Environment
import Options.Applicative
import Data.List
data Args = Args
{ title :: String
, directory :: FilePath
, fileHead :: FilePath
, verbose :: Bool
}
args :: Parser Args
args = Args
<$> strOption
( long "title"
<> short 't'
<> value "Title Left Blank"
<> help "Document title" )
<*> strOption
( long "directory"
<> short 'd'
<> value "./"
<> help "Directory to parse" )
<*> strOption
( long "header"
<> short 'H'
<> value ""
<> help "File with header text" )
<*> switch
( long "verbose"
<> short 'v'
<> help "Verbose mode")
--mapM_ putStrLn =<< getDirectoryContents =<< getEnv "FIETS"
main :: IO ()
main = parseArgs =<< execParser opts
where
opts = info ( args <**> helper)
( fullDesc
<> progDesc "Generate gemini page index"
<> header "fucking kill me")
parseArgs :: Args -> IO()
parseArgs (Args t d h False) = do
putStrLn $ "# " ++ t
putStrLn =<< readFile h
mkIndex =<< getDirectoryContents d
parseArgs _ = putStrLn "fiets"
mkIndex :: [String] -> IO ()
--mkIndex = mapM_ (putStrLn . ("=> " ++))
mkIndex = mapM_ (putStrLn . ("=> " ++)) . filter (isSuffixOf ".gmi")