mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-24 10:55:33 +00:00
83 lines
2.4 KiB
Haskell
83 lines
2.4 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Simplex.Chat.Options
|
|
( ChatOpts (..),
|
|
getChatOpts,
|
|
defaultSMPServers,
|
|
)
|
|
where
|
|
|
|
import qualified Data.Attoparsec.ByteString.Char8 as A
|
|
import qualified Data.ByteString.Char8 as B
|
|
import Data.List.NonEmpty (NonEmpty)
|
|
import qualified Data.List.NonEmpty as L
|
|
import Options.Applicative
|
|
import Simplex.Chat.Controller (updateStr, versionStr)
|
|
import Simplex.Messaging.Agent.Protocol (SMPServer (..))
|
|
import Simplex.Messaging.Encoding.String
|
|
import Simplex.Messaging.Parsers (parseAll)
|
|
import System.FilePath (combine)
|
|
|
|
data ChatOpts = ChatOpts
|
|
{ dbFilePrefix :: String,
|
|
smpServers :: NonEmpty SMPServer,
|
|
logConnections :: Bool,
|
|
logAgent :: Bool
|
|
}
|
|
|
|
defaultSMPServers :: NonEmpty SMPServer
|
|
defaultSMPServers =
|
|
L.fromList
|
|
[ "smp://0YuTwO05YJWS8rkjn9eLJDjQhFKvIYd8d4xG8X1blIU=@smp8.simplex.im",
|
|
"smp://SkIkI6EPd2D63F4xFKfHk7I1UGZVNn6k1QWZ5rcyr6w=@smp9.simplex.im",
|
|
"smp://6iIcWT_dF2zN_w5xzZEY7HI2Prbh3ldP07YTyDexPjE=@smp10.simplex.im"
|
|
]
|
|
|
|
chatOpts :: FilePath -> Parser ChatOpts
|
|
chatOpts appDir =
|
|
ChatOpts
|
|
<$> strOption
|
|
( long "database"
|
|
<> short 'd'
|
|
<> metavar "DB_FILE"
|
|
<> help "Path prefix to chat and agent database files"
|
|
<> value defaultDbFilePath
|
|
<> showDefault
|
|
)
|
|
<*> option
|
|
parseSMPServer
|
|
( long "server"
|
|
<> short 's'
|
|
<> metavar "SERVER"
|
|
<> help
|
|
"Comma separated list of SMP server(s) to use"
|
|
<> value defaultSMPServers
|
|
)
|
|
<*> switch
|
|
( long "connections"
|
|
<> short 'c'
|
|
<> help "Log every contact and group connection on start"
|
|
)
|
|
<*> switch
|
|
( long "log-agent"
|
|
<> short 'l'
|
|
<> help "Enable logs from SMP agent"
|
|
)
|
|
where
|
|
defaultDbFilePath = combine appDir "simplex_v1"
|
|
|
|
parseSMPServer :: ReadM (NonEmpty SMPServer)
|
|
parseSMPServer = eitherReader $ parseAll servers . B.pack
|
|
where
|
|
servers = L.fromList <$> strP `A.sepBy1` A.char ','
|
|
|
|
getChatOpts :: FilePath -> IO ChatOpts
|
|
getChatOpts appDir =
|
|
execParser $
|
|
info
|
|
(helper <*> versionOption <*> chatOpts appDir)
|
|
(header versionStr <> fullDesc <> progDesc "Start chat with DB_FILE file and use SERVER as SMP server")
|
|
where
|
|
versionOption = infoOption versionAndUpdate (long "version" <> short 'v' <> help "Show version")
|
|
versionAndUpdate = versionStr <> "\n" <> updateStr
|