packages feed

ogma-cli 1.7.0 → 1.8.0

raw patch · 8 files changed

+249/−15 lines, 8 filesdep +aesondep +microstachedep +textdep ~ogma-core

Dependencies added: aeson, microstache, text

Dependency ranges changed: ogma-core

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for ogma-cli +## [1.8.0] - 2025-07-13++* Version bump 1.8.0 (#275).+* Expose overview command (#272).+* Extend code commands to accept expressions to monitor as CLI arguments (#121).+ ## [1.7.0] - 2025-03-21  * Version bump 1.7.0 (#269).
ogma-cli.cabal view
@@ -32,7 +32,7 @@ build-type:          Simple  name:                ogma-cli-version:             1.7.0+version:             1.8.0 homepage:            https://github.com/nasa/ogma bug-reports:         https://github.com/nasa/ogma/issues license:             OtherLicense@@ -90,6 +90,7 @@                      >  -h,--help                Show this help text                      >                      >Available commands:+                     >  overview                 Generate an overview of the input specification(s)                      >  structs                  Generate Copilot structs from C structs                      >  handlers                 Generate message handlers from C structs                      >  cfs                      Generate a complete CFS/Copilot application@@ -142,6 +143,7 @@     CLI.CommandCStructs2MsgHandlers     CLI.CommandDiagram     CLI.CommandFPrimeApp+    CLI.CommandOverview     CLI.CommandROSApp     CLI.CommandStandalone     CLI.CommandTop@@ -149,8 +151,12 @@    build-depends:       base                 >= 4.11.0.0 && < 5+    , aeson                >= 2.0.0.0  && < 2.3     , optparse-applicative >= 0.14     && < 0.19-    , ogma-core            >= 1.7.0 && < 1.8+    , microstache          >= 1.0      && < 1.1+    , text                 >= 1.2.3.1  && < 2.2++    , ogma-core            >= 1.8.0 && < 1.9    hs-source-dirs:     src
src/CLI/CommandCFSApp.hs view
@@ -57,7 +57,8 @@  -- | Options needed to generate the cFS application. data CommandOpts = CommandOpts-  { cFSAppInputFile    :: Maybe String+  { cFSAppConditionExpr  :: Maybe String+  , cFSAppInputFile    :: Maybe String   , cFSAppTarget       :: String   , cFSAppTemplateDir  :: Maybe String   , cFSAppVarNames     :: Maybe String@@ -78,7 +79,8 @@ command c = Command.CFSApp.command options   where     options = Command.CFSApp.CommandOptions-                { Command.CFSApp.commandInputFile   = cFSAppInputFile c+                { Command.CFSApp.commandConditionExpr = cFSAppConditionExpr c+                , Command.CFSApp.commandInputFile   = cFSAppInputFile c                 , Command.CFSApp.commandTargetDir   = cFSAppTarget c                 , Command.CFSApp.commandTemplateDir = cFSAppTemplateDir c                 , Command.CFSApp.commandVariables   = cFSAppVarNames c@@ -102,6 +104,13 @@ commandOptsParser = CommandOpts   <$> optional         ( strOption+            (  long "condition-expr"+            <> metavar "EXPRESSION"+            <> help strCFSAppConditionExprArgDesc+            )+        )+  <*> optional+        ( strOption             (  long "input-file"             <> metavar "FILENAME"             <> help strCFSAppFileNameArgDesc@@ -181,6 +190,11 @@ strCFSAppTemplateDirArgDesc :: String strCFSAppTemplateDirArgDesc =   "Directory holding cFS application source template"++-- | Argument expression to CFS app generation command.+strCFSAppConditionExprArgDesc :: String+strCFSAppConditionExprArgDesc =+  "Expression used as guard or trigger condition"  -- | Argument input file to CFS app generation command strCFSAppFileNameArgDesc :: String
src/CLI/CommandFPrimeApp.hs view
@@ -57,7 +57,8 @@  -- | Options needed to generate the FPrime component. data CommandOpts = CommandOpts-  { fprimeAppInputFile    :: Maybe String+  { fprimeAppConditionExpr  :: Maybe String+  , fprimeAppInputFile    :: Maybe String   , fprimeAppTarget       :: String   , fprimeAppTemplateDir  :: Maybe String   , fprimeAppVariables    :: Maybe String@@ -79,7 +80,8 @@   where     options =       Command.FPrimeApp.CommandOptions-        { Command.FPrimeApp.commandInputFile   = fprimeAppInputFile c+        { Command.FPrimeApp.commandConditionExpr = fprimeAppConditionExpr c+        , Command.FPrimeApp.commandInputFile   = fprimeAppInputFile c         , Command.FPrimeApp.commandTargetDir   = fprimeAppTarget c         , Command.FPrimeApp.commandTemplateDir = fprimeAppTemplateDir c         , Command.FPrimeApp.commandVariables   = fprimeAppVariables c@@ -103,6 +105,13 @@ commandOptsParser = CommandOpts   <$> optional         ( strOption+            (  long "condition-expr"+            <> metavar "EXPRESSION"+            <> help strFPrimeAppConditionExprArgDesc+            )+        )+  <*> optional+        ( strOption             (  long "input-file"             <> metavar "FILENAME"             <> help strFPrimeAppFileNameArgDesc@@ -182,6 +191,10 @@ strFPrimeAppTemplateDirArgDesc :: String strFPrimeAppTemplateDirArgDesc =   "Directory holding F' component source template"++-- | Argument expression to FPrime app generation command.+strFPrimeAppConditionExprArgDesc :: String+strFPrimeAppConditionExprArgDesc = "Expression used as guard or trigger condition"  -- | Argument input file to FPrime component generation command strFPrimeAppFileNameArgDesc :: String
+ src/CLI/CommandOverview.hs view
@@ -0,0 +1,152 @@+{-# LANGUAGE OverloadedStrings #-}+-- Copyright 2020 United States Government as represented by the Administrator+-- of the National Aeronautics and Space Administration. All Rights Reserved.+--+-- Disclaimers+--+-- No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY+-- OF ANY KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT+-- LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO+-- SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A+-- PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT THE+-- SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF+-- PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE. THIS AGREEMENT DOES NOT, IN+-- ANY MANNER, CONSTITUTE AN ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR+-- RECIPIENT OF ANY RESULTS, RESULTING DESIGNS, HARDWARE, SOFTWARE PRODUCTS OR+-- ANY OTHER APPLICATIONS RESULTING FROM USE OF THE SUBJECT SOFTWARE. FURTHER,+-- GOVERNMENT AGENCY DISCLAIMS ALL WARRANTIES AND LIABILITIES REGARDING+-- THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES+-- IT "AS IS."+--+-- Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST+-- THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS+-- ANY PRIOR RECIPIENT. IF RECIPIENT'S USE OF THE SUBJECT SOFTWARE RESULTS IN+-- ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES OR LOSSES ARISING FROM SUCH USE,+-- INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING FROM, RECIPIENT'S+-- USE OF THE SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY AND HOLD HARMLESS THE+-- UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY+-- PRIOR RECIPIENT, TO THE EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY+-- FOR ANY SUCH MATTER SHALL BE THE IMMEDIATE, UNILATERAL TERMINATION OF THIS+-- AGREEMENT.+--+-- | CLI interface to the Overview subcommand.+module CLI.CommandOverview+    (+      -- * Direct command access+      command+    , CommandOpts+    , ErrorCode++      -- * CLI+    , commandDesc+    , commandOptsParser+    )+  where++-- External imports+import           Data.Aeson          (toJSON)+import qualified Data.Text.Lazy      as T+import qualified Data.Text.Lazy.IO   as T+import           Options.Applicative (Parser, help, long, metavar, optional,+                                      short, showDefault, strOption, value)+import           Text.Microstache++-- External imports: command results+import Command.Result ( Result(..) )++-- External imports: actions or commands supported+import           Command.Overview (ErrorCode)+import qualified Command.Overview++-- * Command++-- | Options to generate an overview from the input specification(s).+data CommandOpts = CommandOpts+  { overviewFileName    :: FilePath+  , overviewFormat      :: String+  , overviewPropFormat  :: String+  , overviewPropVia     :: Maybe String+  }++-- | Print an overview of the input specification(s).+command :: CommandOpts -> IO (Result ErrorCode)+command c = do+    (mOutput, result) <-+      Command.Overview.command (overviewFileName c) internalCommandOpts++    case (mOutput, outputString) of+      (Just output, Right template) ->+         T.putStr $ renderMustache template (toJSON output)+      _ -> putStrLn "Error"+    return result++  where+    internalCommandOpts :: Command.Overview.CommandOptions+    internalCommandOpts = Command.Overview.CommandOptions+      { Command.Overview.commandFormat      = overviewFormat c+      , Command.Overview.commandPropFormat  = overviewPropFormat c+      , Command.Overview.commandPropVia     = overviewPropVia c+      }++    outputString = compileMustacheText "output" $ T.unlines+      [ "The file has:"+      , " - {{commandExternalVariables}} external variables."+      , " - {{commandInternalVariables}} internal variables."+      , " - {{commandRequirements}} requirements."+      ]++-- * CLI++-- | Command description for CLI help.+commandDesc :: String+commandDesc = "Generate an overview of the input specification(s)"++-- | Subparser for the @overview@ command, used to generate an overview+-- of the input specifications.+commandOptsParser :: Parser CommandOpts+commandOptsParser = CommandOpts+  <$> strOption+        (  long "file-name"+        <> metavar "FILENAME"+        <> help strOverviewFilenameDesc+        )+  <*> strOption+        (  long "input-format"+        <> short 'f'+        <> metavar "FORMAT_NAME"+        <> help strOverviewFormatDesc+        <> showDefault+        <> value "fcs"+        )+  <*> strOption+        (  long "prop-format"+        <> short 'p'+        <> metavar "FORMAT_NAME"+        <> help strOverviewPropFormatDesc+        <> showDefault+        <> value "smv"+        )+  <*> optional+        ( strOption+            (  long "parse-prop-via"+            <> metavar "COMMAND"+            <> help strOverviewPropViaDesc+            )+        )++-- | Filename flag description.+strOverviewFilenameDesc :: String+strOverviewFilenameDesc = "File with properties or requirements"++-- | Format flag description.+strOverviewFormatDesc :: String+strOverviewFormatDesc = "Format of the input file"++-- | Property format flag description.+strOverviewPropFormatDesc :: String+strOverviewPropFormatDesc = "Format of temporal or boolean properties"++-- | External command to pre-process individual properties.+strOverviewPropViaDesc :: String+strOverviewPropViaDesc =+  "Command to pre-process individual properties"
src/CLI/CommandROSApp.hs view
@@ -57,7 +57,8 @@  -- | Options needed to generate the ROS application. data CommandOpts = CommandOpts-  { rosAppInputFile    :: Maybe String+  { rosAppConditionExpr  :: Maybe String+  , rosAppInputFile    :: Maybe String   , rosAppTarget       :: String   , rosAppTemplateDir  :: Maybe String   , rosAppVarNames     :: Maybe String@@ -78,7 +79,8 @@ command c = Command.ROSApp.command options   where     options = Command.ROSApp.CommandOptions-                { Command.ROSApp.commandInputFile   = rosAppInputFile c+                { Command.ROSApp.commandConditionExpr = rosAppConditionExpr c+                , Command.ROSApp.commandInputFile   = rosAppInputFile c                 , Command.ROSApp.commandTargetDir   = rosAppTarget c                 , Command.ROSApp.commandTemplateDir = rosAppTemplateDir c                 , Command.ROSApp.commandVariables   = rosAppVarNames c@@ -102,6 +104,13 @@ commandOptsParser = CommandOpts   <$> optional         ( strOption+            (  long "condition-expr"+            <> metavar "EXPRESSION"+            <> help strROSAppConditionExprArgDesc+            )+        )+  <*> optional+        ( strOption             (  long "input-file"             <> metavar "FILENAME"             <> help strROSAppFileNameArgDesc@@ -181,6 +190,10 @@ strROSAppTemplateDirArgDesc :: String strROSAppTemplateDirArgDesc =   "Directory holding ROS application source template"++-- | Argument expression to ROS app generation command.+strROSAppConditionExprArgDesc :: String+strROSAppConditionExprArgDesc = "Expression used as guard or trigger condition"  -- | Argument input file to ROS app generation command strROSAppFileNameArgDesc :: String
src/CLI/CommandStandalone.hs view
@@ -60,7 +60,8 @@ data CommandOpts = CommandOpts   { standaloneTargetDir    :: FilePath   , standaloneTemplateDir  :: Maybe FilePath-  , standaloneFileName     :: FilePath+  , standaloneConditionExpr  :: Maybe String+  , standaloneFileName     :: Maybe FilePath   , standaloneFormat       :: String   , standalonePropFormat   :: String   , standaloneTypes        :: [String]@@ -76,7 +77,8 @@   where     internalCommandOpts :: Command.Standalone.CommandOptions     internalCommandOpts = Command.Standalone.CommandOptions-      { Command.Standalone.commandInputFile   = standaloneFileName c+      { Command.Standalone.commandConditionExpr = standaloneConditionExpr c+      , Command.Standalone.commandInputFile   = standaloneFileName c       , Command.Standalone.commandTargetDir   = standaloneTargetDir c       , Command.Standalone.commandTemplateDir = standaloneTemplateDir c       , Command.Standalone.commandFormat      = standaloneFormat c@@ -121,11 +123,20 @@             <> help strStandaloneTemplateDirArgDesc             )         )-  <*> strOption-        (  long "file-name"-        <> metavar "FILENAME"-        <> help strStandaloneFilenameDesc+  <*> optional+        ( strOption+          (  long "condition-expr"+          <> metavar "FILENAME"+          <> help strStandaloneConditionExprDesc+          )         )+  <*> optional+        ( strOption+          (  long "file-name"+          <> metavar "FILENAME"+          <> help strStandaloneFilenameDesc+          )+        )   <*> strOption         (  long "input-format"         <> short 'f'@@ -178,6 +189,11 @@ -- | Template dir flag description. strStandaloneTemplateDirArgDesc :: String strStandaloneTemplateDirArgDesc = "Directory holding standalone source template"++-- | Condition flag description.+strStandaloneConditionExprDesc :: String+strStandaloneConditionExprDesc =+  "Condition upon which the monitor will fire or notify"  -- | Filename flag description. strStandaloneFilenameDesc :: String
src/CLI/CommandTop.hs view
@@ -91,6 +91,7 @@ import qualified CLI.CommandCStructs2MsgHandlers import qualified CLI.CommandDiagram import qualified CLI.CommandFPrimeApp+import qualified CLI.CommandOverview import qualified CLI.CommandROSApp import qualified CLI.CommandStandalone @@ -107,6 +108,7 @@   | CommandOptsCStructs2MsgHandlers      CLI.CommandCStructs2MsgHandlers.CommandOpts   | CommandOptsDiagram                   CLI.CommandDiagram.CommandOpts   | CommandOptsFPrimeApp                 CLI.CommandFPrimeApp.CommandOpts+  | CommandOptsOverview                  CLI.CommandOverview.CommandOpts   | CommandOptsROSApp                    CLI.CommandROSApp.CommandOpts   | CommandOptsStandalone                CLI.CommandStandalone.CommandOpts @@ -120,7 +122,8 @@ -- | Subparser for multiple subcommands. commandOptsParser :: Parser CommandOpts commandOptsParser = subparser-  (  subcommandCStructs+  (  subcommandOverview+  <> subcommandCStructs   <> subcommandMsgHandlers   <> subcommandCFSApp   <> subcommandFPrimeApp@@ -129,6 +132,15 @@   <> subcommandDiagram   ) +-- | Modifier for the overview subcommand, linking the subcommand options and+-- description to the command @overview@ at top level.+subcommandOverview :: Mod CommandFields CommandOpts+subcommandOverview =+  subcommand+    "overview"+    (CommandOptsOverview <$> CLI.CommandOverview.commandOptsParser)+    CLI.CommandOverview.commandDesc+ -- | Modifier for the CStruct to Copilot Struct generation subcommand, linking -- the subcommand options and description to the command @structs@ at top -- level.@@ -225,6 +237,8 @@   id <$> CLI.CommandCStructs2MsgHandlers.command c command (CommandOptsFPrimeApp c) =   id <$> CLI.CommandFPrimeApp.command c+command (CommandOptsOverview c) =+  id <$> CLI.CommandOverview.command c command (CommandOptsROSApp c) =   id <$> CLI.CommandROSApp.command c command (CommandOptsStandalone c) =