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

parent 59c23118
...@@ -36,7 +36,7 @@ import Toml qualified ...@@ -36,7 +36,7 @@ import Toml qualified
iniCLI :: IniArgs -> IO () iniCLI :: IniArgs -> IO ()
iniCLI iniArgs = do iniCLI iniArgs@(IniArgs { dry_run }) = do
let iniPath = fromMaybe "gargantext.ini" $ ini_path iniArgs let iniPath = fromMaybe "gargantext.ini" $ ini_path iniArgs
let tomlPath = fromMaybe "gargantext-settings.toml" $ toml_path iniArgs let tomlPath = fromMaybe "gargantext-settings.toml" $ toml_path iniArgs
putStrLn $ "Reading configuration from file " <> iniPath <> "..." putStrLn $ "Reading configuration from file " <> iniPath <> "..."
...@@ -45,6 +45,9 @@ iniCLI iniArgs = do ...@@ -45,6 +45,9 @@ iniCLI iniArgs = do
iniNLP <- IniNLP.readConfig iniPath iniNLP <- IniNLP.readConfig iniPath
connInfo <- Ini.readDBConfig iniPath connInfo <- Ini.readDBConfig iniPath
let c = convertConfigs ini iniMail iniNLP connInfo let c = convertConfigs ini iniMail iniNLP connInfo
if dry_run then
putStrLn (show (Toml.encode c) :: Text)
else do
T.writeFile tomlPath (show (Toml.encode c) :: Text) T.writeFile tomlPath (show (Toml.encode c) :: Text)
putStrLn $ "Converted configuration into TOML and wrote it to file " <> tomlPath putStrLn $ "Converted configuration into TOML and wrote it to file " <> tomlPath
...@@ -55,7 +58,8 @@ iniCmd = command "ini" (info (helper <*> fmap CLISub iniParser) ...@@ -55,7 +58,8 @@ iniCmd = command "ini" (info (helper <*> fmap CLISub iniParser)
iniParser :: Parser CLICmd iniParser :: Parser CLICmd
iniParser = fmap CCMD_ini $ IniArgs <$> iniParser = fmap CCMD_ini $ IniArgs <$>
(optional . strOption $ long "ini-path" <> help "Path to the input ini file" ) <*> (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.GargConfig -> IniMail.MailConfig -> IniNLP.NLPConfig -> PGS.ConnectInfo -> Config.GargConfig
convertConfigs ini@(Ini.GargConfig { .. }) iniMail nlpConfig connInfo = convertConfigs ini@(Ini.GargConfig { .. }) iniMail nlpConfig connInfo =
......
...@@ -48,6 +48,7 @@ data ImportArgs = ImportArgs ...@@ -48,6 +48,7 @@ data ImportArgs = ImportArgs
data IniArgs = IniArgs data IniArgs = IniArgs
{ ini_path :: !(Maybe FilePath) { ini_path :: !(Maybe FilePath)
, toml_path :: !(Maybe FilePath) , toml_path :: !(Maybe FilePath)
, dry_run :: !Bool
} deriving (Show, Eq) } deriving (Show, Eq)
data InitArgs = InitArgs 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