Commit f406450a authored by Grégoire Locqueville's avatar Grégoire Locqueville

Improve conversion script interface

`gargantext-cli ini` now takes two optional arguments:
- `--ini-path somefile.ini`: will read the configuration from `somefile.ini`.
  Defaults to `gargantext.ini`
- `--toml-path somefile.toml`: will write the configuration converted to TOML
  into `somefile.toml` (warning: it will erase the former file if there is already one!)
  Defaults to `gargantext-settings.toml`

Since it writes to a file, the command no longer outputs the configuration
to standard output.
parent 5c443218
Pipeline #6669 passed with stages
in 92 minutes and 36 seconds
...@@ -192,7 +192,7 @@ $ cp gargantext-settings.toml_toModify gargantext-settings.toml ...@@ -192,7 +192,7 @@ $ cp gargantext-settings.toml_toModify gargantext-settings.toml
**NOTE** If you had the `gargantext.ini` file before, you can automatically generate toml with: **NOTE** If you had the `gargantext.ini` file before, you can automatically generate toml with:
```shell ```shell
cabal v2-run gargantext-cli -- ini --ini-path ./gargantext.ini > gargantext-settings.toml cabal run gargantext-cli -- ini --ini-path gargantext.ini --toml-path gargantext-settings.toml
``` ```
> `.gitignore` excludes this file, so you don't need to worry about > `.gitignore` excludes this file, so you don't need to worry about
......
...@@ -20,6 +20,7 @@ module CLI.Ini where ...@@ -20,6 +20,7 @@ module CLI.Ini where
import CLI.Types import CLI.Types
import Data.Text qualified as T import Data.Text qualified as T
import Data.Text.IO qualified as T (writeFile)
import Database.PostgreSQL.Simple qualified as PGS import Database.PostgreSQL.Simple qualified as PGS
import Gargantext.Core.Config qualified as Config import Gargantext.Core.Config qualified as Config
import Gargantext.Core.Config.Ini.Ini qualified as Ini import Gargantext.Core.Config.Ini.Ini qualified as Ini
...@@ -33,24 +34,26 @@ import Toml qualified ...@@ -33,24 +34,26 @@ import Toml qualified
iniCLI :: IniArgs -> IO () iniCLI :: IniArgs -> IO ()
iniCLI (IniArgs iniPath) = do iniCLI iniArgs = do
-- putStrLn $ "ini path: " <> iniPath let iniPath = fromMaybe "gargantext.ini" $ ini_path iniArgs
let tomlPath = fromMaybe "gargantext-settings.toml" $ toml_path iniArgs
putStrLn $ "Reading configuration from file " <> iniPath <> "..."
ini <- Ini.readConfig iniPath ini <- Ini.readConfig iniPath
iniMail <- IniMail.readConfig iniPath iniMail <- IniMail.readConfig iniPath
iniNLP <- IniNLP.readConfig iniPath iniNLP <- IniNLP.readConfig iniPath
-- putStrLn (show ini :: Text)
connInfo <- Ini.readDBConfig iniPath connInfo <- Ini.readDBConfig iniPath
let c = convertConfigs ini iniMail iniNLP connInfo let c = convertConfigs ini iniMail iniNLP connInfo
-- putStrLn (show c :: Text) T.writeFile tomlPath (show (Toml.encode c) :: Text)
putStrLn (show (Toml.encode c) :: Text) putStrLn $ "Converted configuration into TOML and wrote it to file " <> tomlPath
iniCmd :: HasCallStack => Mod CommandFields CLI iniCmd :: HasCallStack => Mod CommandFields CLI
iniCmd = command "ini" (info (helper <*> fmap CLISub ini_p) (progDesc "Parse .ini file and output a corresponding .toml file.")) iniCmd = command "ini" (info (helper <*> fmap CLISub iniParser)
(progDesc "Parse .ini file and output a corresponding .toml file."))
ini_p :: Parser CLICmd iniParser :: Parser CLICmd
ini_p = fmap CCMD_ini $ IniArgs iniParser = fmap CCMD_ini $ IniArgs <$>
<$> strOption ( long "ini-path" (optional . strOption $ long "ini-path" <> help "Path to the input ini file" ) <*>
<> help "Path to ini file" ) (optional . strOption $ long "toml-path" <> help "Path to the output .toml file")
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 =
......
...@@ -46,7 +46,8 @@ data ImportArgs = ImportArgs ...@@ -46,7 +46,8 @@ data ImportArgs = ImportArgs
} deriving (Show, Eq) } deriving (Show, Eq)
data IniArgs = IniArgs data IniArgs = IniArgs
{ ini_path :: !FilePath { ini_path :: !(Maybe FilePath)
, toml_path :: !(Maybe FilePath)
} 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