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
**NOTE** If you had the `gargantext.ini` file before, you can automatically generate toml with:
```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
......
......@@ -20,6 +20,7 @@ module CLI.Ini where
import CLI.Types
import Data.Text qualified as T
import Data.Text.IO qualified as T (writeFile)
import Database.PostgreSQL.Simple qualified as PGS
import Gargantext.Core.Config qualified as Config
import Gargantext.Core.Config.Ini.Ini qualified as Ini
......@@ -33,24 +34,26 @@ import Toml qualified
iniCLI :: IniArgs -> IO ()
iniCLI (IniArgs iniPath) = do
-- putStrLn $ "ini path: " <> iniPath
iniCLI iniArgs = do
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
iniMail <- IniMail.readConfig iniPath
iniNLP <- IniNLP.readConfig iniPath
-- putStrLn (show ini :: Text)
connInfo <- Ini.readDBConfig iniPath
let c = convertConfigs ini iniMail iniNLP connInfo
-- putStrLn (show c :: Text)
putStrLn (show (Toml.encode c) :: Text)
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 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
ini_p = fmap CCMD_ini $ IniArgs
<$> strOption ( long "ini-path"
<> help "Path to ini file" )
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")
convertConfigs :: Ini.GargConfig -> IniMail.MailConfig -> IniNLP.NLPConfig -> PGS.ConnectInfo -> Config.GargConfig
convertConfigs ini@(Ini.GargConfig { .. }) iniMail nlpConfig connInfo =
......
......@@ -46,7 +46,8 @@ data ImportArgs = ImportArgs
} deriving (Show, Eq)
data IniArgs = IniArgs
{ ini_path :: !FilePath
{ ini_path :: !(Maybe FilePath)
, toml_path :: !(Maybe FilePath)
} 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