mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-27 17:58:47 +00:00
28 lines
1.2 KiB
Haskell
28 lines
1.2 KiB
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
module Main where
|
|
|
|
import BadgeService.Admin (runAdminCmd)
|
|
import BadgeService.Options (BadgeServiceOpts (..), CliCommand (..), getBadgeServiceCommand)
|
|
import BadgeService.Service
|
|
import Simplex.Chat.Terminal (terminalChatConfig)
|
|
import System.Directory (getAppUserDataDirectory)
|
|
|
|
-- | 'getBadgeServiceCommand' decides, from the same combined parser that generates --help,
|
|
-- whether this is the operator @codes@ subcommand or a plain service run (the default with
|
|
-- no arguments -- 'BadgeService.Options.badgeServiceCommand' wraps the @codes@ subparser in
|
|
-- 'optional' so this never becomes mandatory). The @codes@ branch runs and exits without ever
|
|
-- starting the bot; the plain-run branch falls through to 'welcomeGetOpts', unchanged, which
|
|
-- re-parses the same arguments to print the startup banner before starting the service.
|
|
main :: IO ()
|
|
main = do
|
|
appDir <- getAppUserDataDirectory "simplex"
|
|
getBadgeServiceCommand appDir "simplex_badge_service" >>= \case
|
|
RunAdmin adminOpts -> runAdminCmd adminOpts
|
|
RunService _ -> do
|
|
opts@BadgeServiceOpts {runCLI} <- welcomeGetOpts
|
|
if runCLI
|
|
then badgeServiceCLI opts
|
|
else badgeService opts terminalChatConfig
|