Skip to content

Commit

Permalink
ogma-cli: Make ROS backend receive options as record. Refs nasa#204.
Browse files Browse the repository at this point in the history
The ROS backend has a large amount of input options, making it
cumbersome to pass them around.

A prior commit has modified the backend in ogma-core to packs those
options in a record, making the signature of the top-level function
simpler and more uniform.

This commit adapts the CLI to provide the arguments in a record as
required by the updated backend.
  • Loading branch information
ivanperez-keera committed Jan 20, 2025
1 parent 5ac8d9c commit 49d6189
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions ogma-cli/src/CLI/CommandROSApp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ import Options.Applicative ( Parser, help, long, metavar, optional, showDefault,
import Command.Result ( Result )

-- External imports: actions or commands supported
import Command.ROSApp ( ErrorCode, rosApp )
import Command.ROSApp (ErrorCode, rosApp)
import qualified Command.ROSApp

-- * Command

-- | Options needed to generate the ROS application.
data CommandOpts = CommandOpts
{ rosAppTarget :: String
{ rosAppInputFile :: Maybe String
, rosAppTarget :: String
, rosAppTemplateDir :: Maybe String
, rosAppInputFile :: Maybe String
, rosAppVarNames :: Maybe String
, rosAppVarDB :: Maybe String
, rosAppHandlers :: Maybe String
Expand All @@ -68,16 +69,17 @@ data CommandOpts = CommandOpts
-- that subscribe to obtain necessary data from topics and call Copilot when
-- new data arrives.
--
-- This is just an uncurried version of "Command.ROSApp".
-- This is just a wrapper around "Command.ROSApp".
command :: CommandOpts -> IO (Result ErrorCode)
command c =
rosApp
(rosAppTarget c)
(rosAppTemplateDir c)
(rosAppInputFile c)
(rosAppVarNames c)
(rosAppVarDB c)
(rosAppHandlers c)
command c = rosApp (rosAppInputFile c) options
where
options = Command.ROSApp.ROSAppOptions
{ Command.ROSApp.rosAppTargetDir = rosAppTarget c
, Command.ROSApp.rosAppTemplateDir = rosAppTemplateDir c
, Command.ROSApp.rosAppVariables = rosAppVarNames c
, Command.ROSApp.rosAppVariableDB = rosAppVarDB c
, Command.ROSApp.rosAppHandlers = rosAppHandlers c
}

-- * CLI

Expand All @@ -89,7 +91,14 @@ commandDesc = "Generate a ROS 2 monitoring package"
-- application connected to Copilot monitors.
commandOptsParser :: Parser CommandOpts
commandOptsParser = CommandOpts
<$> strOption
<$> optional
( strOption
( long "input-file"
<> metavar "FILENAME"
<> help strROSAppFileNameArgDesc
)
)
<*> strOption
( long "app-target-dir"
<> metavar "DIR"
<> showDefault
Expand All @@ -103,13 +112,6 @@ commandOptsParser = CommandOpts
<> help strROSAppTemplateDirArgDesc
)
)
<*> optional
( strOption
( long "input-file"
<> metavar "FILENAME"
<> help strROSAppFileNameArgDesc
)
)
<*> optional
( strOption
( long "variable-file"
Expand Down

0 comments on commit 49d6189

Please sign in to comment.