From 879cd577f7f69d2b74602953f5c4db74e1cf1d5b Mon Sep 17 00:00:00 2001 From: Ivan Perez Date: Wed, 11 Dec 2024 11:47:00 +0000 Subject: [PATCH] ogma-cli: Add CLI argument to standalone command to set target directory. 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), or not using ogma altogether for that reason. A prior commit introduced, in the standalone command, support for custom templates. Unlike the prior implementation of the standalone command, which printed the output to standard output, the new interface puts the result in a file (or several files) included with the template. To implement this new functionality, we have added an argument to specify a target directory for the generated standalone application, where the files will be copied to. This commit exposes that new parameter to set the target directory to the user in the CLI. --- ogma-cli/src/CLI/CommandStandalone.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ogma-cli/src/CLI/CommandStandalone.hs b/ogma-cli/src/CLI/CommandStandalone.hs index b4cd7377..7cafc443 100644 --- a/ogma-cli/src/CLI/CommandStandalone.hs +++ b/ogma-cli/src/CLI/CommandStandalone.hs @@ -58,7 +58,8 @@ import qualified Command.Standalone -- | Options to generate Copilot from specification. data CommandOpts = CommandOpts - { standaloneFileName :: FilePath + { standaloneTargetDir :: FilePath + , standaloneFileName :: FilePath , standaloneFormat :: String , standalonePropFormat :: String , standaloneTypes :: [String] @@ -71,7 +72,8 @@ command c = standalone (standaloneFileName c) internalCommandOpts where internalCommandOpts :: Command.Standalone.StandaloneOptions internalCommandOpts = Command.Standalone.StandaloneOptions - { Command.Standalone.standaloneFormat = standaloneFormat c + { Command.Standalone.standaloneTargetDir = standaloneTargetDir c + , Command.Standalone.standaloneFormat = standaloneFormat c , Command.Standalone.standalonePropFormat = standalonePropFormat c , Command.Standalone.standaloneTypeMapping = types , Command.Standalone.standaloneFilename = standaloneTarget c @@ -98,6 +100,13 @@ commandDesc = commandOptsParser :: Parser CommandOpts commandOptsParser = CommandOpts <$> strOption + ( long "target-dir" + <> metavar "DIR" + <> showDefault + <> value "copilot" + <> help strStandaloneTargetDirDesc + ) + <*> strOption ( long "file-name" <> metavar "FILENAME" <> help strStandaloneFilenameDesc @@ -133,6 +142,10 @@ commandOptsParser = CommandOpts <> value "monitor" ) +-- | Target dir flag description. +strStandaloneTargetDirDesc :: String +strStandaloneTargetDirDesc = "Target directory" + -- | Filename flag description. strStandaloneFilenameDesc :: String strStandaloneFilenameDesc = "File with properties or requirements"