[cli] ini: --dry-run option to output toml to stdout

parent 59c23118
Pipeline #6755 failed with stages
in 33 minutes and 1 second
......@@ -36,7 +36,7 @@ import Toml qualified
iniCLI :: IniArgs -> IO ()
iniCLI iniArgs = do
iniCLI iniArgs@(IniArgs { dry_run }) = do
let iniPath = fromMaybe "gargantext.ini" $ ini_path iniArgs
let tomlPath = fromMaybe "gargantext-settings.toml" $ toml_path iniArgs
putStrLn $ "Reading configuration from file " <> iniPath <> "..."
......@@ -45,8 +45,11 @@ iniCLI iniArgs = do
iniNLP <- IniNLP.readConfig iniPath
connInfo <- Ini.readDBConfig iniPath
let c = convertConfigs ini iniMail iniNLP connInfo
T.writeFile tomlPath (show (Toml.encode c) :: Text)
putStrLn $ "Converted configuration into TOML and wrote it to file " <> tomlPath
if dry_run then
putStrLn (show (Toml.encode c) :: Text)
else do
T.writeFile tomlPath (show (Toml.encode c) :: Text)
putStrLn $ "Converted configuration into TOML and wrote it to file " <> tomlPath
iniCmd :: HasCallStack => Mod CommandFields CLI
iniCmd = command "ini" (info (helper <*> fmap CLISub iniParser)
......@@ -55,7 +58,8 @@ iniCmd = command "ini" (info (helper <*> fmap CLISub iniParser)
iniParser :: Parser CLICmd
iniParser = fmap CCMD_ini $ IniArgs <$>
(optional . strOption $ long "ini-path" <> help "Path to the input ini file" ) <*>
(optional . strOption $ long "toml-path" <> help "Path to the output .toml file")
(optional . strOption $ long "toml-path" <> help "Path to the output .toml file") <*>
(flag False True (long "dry-run" <> help "If set, will only output generated .toml file to stdout"))
convertConfigs :: Ini.GargConfig -> IniMail.MailConfig -> IniNLP.NLPConfig -> PGS.ConnectInfo -> Config.GargConfig
convertConfigs ini@(Ini.GargConfig { .. }) iniMail nlpConfig connInfo =
......
......@@ -48,6 +48,7 @@ data ImportArgs = ImportArgs
data IniArgs = IniArgs
{ ini_path :: !(Maybe FilePath)
, toml_path :: !(Maybe FilePath)
, dry_run :: !Bool
} deriving (Show, Eq)
data InitArgs = InitArgs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment