From 253efc45bfbfc537c6c318e11c4b656185ec7d23 Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Tue, 24 Dec 2024 01:14:59 +0000 Subject: [PATCH] ogma-cli: Provide CLI argument to set auxiliary template source directory in standalone command. Refs #189. The standalone backend uses a fixed template to generate the Copilot monitor. That template does not fit all use cases, so we are finding users heavily modifying the output (which is hard to keep up with when there are changes), and or not using ogma altogether for that reason. A recent commit introduced into ogma-core the ability to use a custom template and expand variables using mustache. This commit exposes that new parameter to the user in the CLI. --- ogma-cli/src/CLI/CommandStandalone.hs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/ogma-cli/src/CLI/CommandStandalone.hs b/ogma-cli/src/CLI/CommandStandalone.hs index 7cafc443..108e4a61 100644 --- a/ogma-cli/src/CLI/CommandStandalone.hs +++ b/ogma-cli/src/CLI/CommandStandalone.hs @@ -43,7 +43,7 @@ module CLI.CommandStandalone where -- External imports -import Options.Applicative (Parser, help, long, metavar, many, short, +import Options.Applicative (Parser, help, long, many, metavar, optional, short, showDefault, strOption, switch, value) -- External imports: command results @@ -58,12 +58,13 @@ import qualified Command.Standalone -- | Options to generate Copilot from specification. data CommandOpts = CommandOpts - { standaloneTargetDir :: FilePath - , standaloneFileName :: FilePath - , standaloneFormat :: String - , standalonePropFormat :: String - , standaloneTypes :: [String] - , standaloneTarget :: String + { standaloneTargetDir :: FilePath + , standaloneTemplateDir :: Maybe FilePath + , standaloneFileName :: FilePath + , standaloneFormat :: String + , standalonePropFormat :: String + , standaloneTypes :: [String] + , standaloneTarget :: String } -- | Transform an input specification into a Copilot specification. @@ -73,6 +74,7 @@ command c = standalone (standaloneFileName c) internalCommandOpts internalCommandOpts :: Command.Standalone.StandaloneOptions internalCommandOpts = Command.Standalone.StandaloneOptions { Command.Standalone.standaloneTargetDir = standaloneTargetDir c + , Command.Standalone.standaloneTemplateDir = standaloneTemplateDir c , Command.Standalone.standaloneFormat = standaloneFormat c , Command.Standalone.standalonePropFormat = standalonePropFormat c , Command.Standalone.standaloneTypeMapping = types @@ -106,6 +108,13 @@ commandOptsParser = CommandOpts <> value "copilot" <> help strStandaloneTargetDirDesc ) + <*> optional + ( strOption + ( long "template-dir" + <> metavar "DIR" + <> help strStandaloneTemplateDirArgDesc + ) + ) <*> strOption ( long "file-name" <> metavar "FILENAME" @@ -146,6 +155,10 @@ commandOptsParser = CommandOpts strStandaloneTargetDirDesc :: String strStandaloneTargetDirDesc = "Target directory" +-- | Template dir flag description. +strStandaloneTemplateDirArgDesc :: String +strStandaloneTemplateDirArgDesc = "Directory holding standalone source template" + -- | Filename flag description. strStandaloneFilenameDesc :: String strStandaloneFilenameDesc = "File with properties or requirements"