LCOV - code coverage report
Current view: top level - OdbDesignLib/App - OdbDesignArgs.cpp (source / functions) Coverage Total Hit
Test: OdbDesign Test Coverage Lines: 24.6 % 57 14
Test Date: 2026-11-19 04:56:22 Functions: 21.4 % 14 3
Legend: Lines: hit not hit

            Line data    Source code
       1              : #include "OdbDesignArgs.h"
       2              : #include <iostream>
       3              : #include <sstream>
       4              : 
       5              : namespace Odb::Lib::App
       6              : {
       7            7 :         OdbDesignArgs::OdbDesignArgs(int argc, char* argv[])
       8            7 :                 : CommandLineArgs(argc, argv)
       9              :         {
      10            7 :         }
      11              : 
      12            0 :         int OdbDesignArgs::port() const
      13              :         {
      14            0 :                 return intArg("port", DEFAULT_PORT);
      15              :         }
      16              : 
      17            0 :         std::string OdbDesignArgs::bindAddress() const
      18              :         {
      19            0 :                 return stringArg("bind", DEFAULT_BIND_ADDRESS);
      20              :         }
      21              : 
      22            0 :         int OdbDesignArgs::grpcPort() const
      23              :         {
      24            0 :                 return intArg("grpc-port", DEFAULT_GRPC_PORT);
      25              :         }
      26              : 
      27            0 :         std::string OdbDesignArgs::designsDir() const
      28              :         {
      29            0 :                 return stringArg("designs-dir", DEFAULT_DESIGNS_DIR);
      30              :         }
      31              : 
      32            0 :         std::string OdbDesignArgs::templatesDir() const
      33              :         {
      34            0 :                 return stringArg("templates-dir", DEFAULT_TEMPLATES_DIR);
      35              :         }
      36              : 
      37            0 :         bool OdbDesignArgs::help() const
      38              :         {
      39            0 :                 return boolArg("help", DEFAULT_HELP);
      40              :         }
      41              : 
      42            0 :         bool OdbDesignArgs::httpTrace() const
      43              :         {
      44            0 :                 return boolArg("http-trace", DEFAULT_HTTP_TRACE);
      45              :         }
      46              : 
      47            0 :         std::string OdbDesignArgs::loadDesign() const
      48              :         {
      49            0 :                 return stringArg("load-design", DEFAULT_LOAD_DESIGN);
      50              :         }
      51              : 
      52            0 :         bool OdbDesignArgs::loadAll() const
      53              :         {
      54            0 :                 return boolArg("load-all", DEFAULT_LOAD_ALL);
      55              :         }
      56              : 
      57            0 :         bool OdbDesignArgs::disableAuthentication() const
      58              :         {
      59            0 :                 return boolArg("disable-authentication", DEFAULT_DISABLE_AUTH);
      60              :         }
      61              : 
      62            3 :         int OdbDesignArgs::cacheMaxMb() const
      63              :         {
      64              :                 // intArg -> std::stoi throws when CommandLineArgs stored the literal
      65              :                 // boolean `true` (missing value, or a value starting with '-' or '/');
      66              :                 // this runs unconditionally at the top of OdbAppBase::Run(), so a
      67              :                 // malformed --cache-max-mb must not std::terminate the process — fall
      68              :                 // back to the default with a warning. Negative values clamp to 0
      69              :                 // (eviction disabled), matching setCacheMaxBytes semantics.
      70              :                 try
      71              :                 {
      72            6 :                         const int mb = intArg("cache-max-mb", DEFAULT_CACHE_MAX_MB);
      73            3 :                         return mb < 0 ? 0 : mb;
      74              :                 }
      75            0 :                 catch (const std::exception&)
      76              :                 {
      77            0 :                         std::cerr << "WARNING: invalid --cache-max-mb value; using default "
      78            0 :                                 << DEFAULT_CACHE_MAX_MB << std::endl;
      79            0 :                         return DEFAULT_CACHE_MAX_MB;
      80            0 :                 }
      81              :         }
      82              : 
      83            4 :         int OdbDesignArgs::maxBackgroundLoads() const
      84              :         {
      85              :                 // Same stoi-hardening as cacheMaxMb(): a malformed --max-background-loads
      86              :                 // must not std::terminate the process — fall back to the default with a
      87              :                 // warning. Negative values clamp to 0 (unbounded), matching
      88              :                 // DesignCache::setMaxBackgroundLoads semantics.
      89              :                 try
      90              :                 {
      91            9 :                         const int loads = intArg("max-background-loads", DEFAULT_MAX_BACKGROUND_LOADS);
      92            3 :                         return loads < 0 ? 0 : loads;
      93              :                 }
      94            1 :                 catch (const std::exception&)
      95              :                 {
      96            1 :                         std::cerr << "WARNING: invalid --max-background-loads value; using default "
      97            1 :                                 << DEFAULT_MAX_BACKGROUND_LOADS << std::endl;
      98            1 :                         return DEFAULT_MAX_BACKGROUND_LOADS;
      99            1 :                 }
     100              :         }
     101              : 
     102            0 :         std::string OdbDesignArgs::getUsageString() const
     103              :         {
     104            0 :                 std::stringstream ss;
     105            0 :                 ss << "Usage: " << executableName() << " [options]\n";
     106            0 :                 ss << "Options:\n";
     107            0 :                 ss << "  --bind <ip|host>        Bind address for REST server (default: " << DEFAULT_BIND_ADDRESS << ")\n";
     108            0 :                 ss << "  --port <port>            Port to listen on (default: " << DEFAULT_PORT << ")\n";
     109            0 :                 ss << "  --grpc-port <port>       gRPC port to listen on (default: " << DEFAULT_GRPC_PORT << ")\n";
     110            0 :                 ss << "  --designs-dir <dir>      Directory containing design files (default: " << DEFAULT_DESIGNS_DIR << ")\n";
     111            0 :                 ss << "  --templates-dir <dir>    Directory containing template files (default: " << DEFAULT_TEMPLATES_DIR << ")\n";
     112            0 :                 ss << "  --http-trace             Enable per-request HTTP tracing (default: " << (DEFAULT_HTTP_TRACE ? "true" : "false") << ")\n";
     113            0 :                 ss << "  --load-design <design>   Design to load on startup (default: " << DEFAULT_LOAD_DESIGN << ")\n";
     114            0 :                 ss << "  --load-all               Load all designs on startup (default: " << (DEFAULT_LOAD_ALL ? "true" : "false") << ")\n";
     115            0 :                 ss << "  --disable-authentication Disable authentication (default: " << (DEFAULT_DISABLE_AUTH ? "true" : "false") << ")\n";
     116            0 :                 ss << "  --cache-max-mb <MB>      Max design cache size in MB before LRU eviction, 0 disables (default: " << DEFAULT_CACHE_MAX_MB << ")\n";
     117            0 :                 ss << "  --max-background-loads <N>  Max concurrent background design loads, 0 = unbounded (default: " << DEFAULT_MAX_BACKGROUND_LOADS << ")\n";
     118            0 :                 ss << "  --help                   Print this help message\n";
     119            0 :                 return ss.str();                
     120            0 :         }       
     121              : }
        

Generated by: LCOV version 2.0-1