@@ -229,25 +229,37 @@ class AppWrapper : public CMOOSApp {
229229 // Clean shutdown
230230 }
231231
232- // Standard MOOS pattern: Run with mission file (reads server/port/name from file)
233- bool Run (const std::string & sMissionFile ) {
234- SetMissionFile (sMissionFile );
235- return BASE::Run ();
236- }
237-
238- // Alternative: Run with explicit parameters (for when mission file is not used)
239- bool Run (const std::string & sServer , int Port, const std::string & sMyName ) {
240- SetAppName (sMyName );
241- SetServer (sServer , Port);
242- return BASE::Run ();
243- }
244-
245- // Run with explicit parameters and mission file
246- bool Run (const std::string & sServer , int Port, const std::string & sMyName , const std::string & sMissionFile ) {
247- SetAppName (sMyName );
248- SetServer (sServer , Port);
249- SetMissionFile (sMissionFile );
250- return BASE::Run ();
232+ // Python-friendly wrapper that creates command-line arguments for CMOOSApp::Run()
233+ // Standard MOOS pattern: Run(app_name, mission_file, [additional args])
234+ bool Run (const std::string & sAppName , const std::string & sMissionFile = " " ,
235+ const std::string & sServerHost = " " , int nServerPort = 0 ) {
236+
237+ // Build argc/argv from parameters
238+ std::vector<std::string> args;
239+ args.push_back (sAppName ); // argv[0] is typically the program name
240+
241+ if (!sMissionFile .empty ()) {
242+ args.push_back (sMissionFile );
243+ }
244+
245+ if (!sServerHost .empty ()) {
246+ args.push_back (" --moos_host=" + sServerHost );
247+ }
248+
249+ if (nServerPort > 0 ) {
250+ args.push_back (" --moos_port=" + std::to_string (nServerPort));
251+ }
252+
253+ // Convert to argc/argv format
254+ int argc = static_cast <int >(args.size ());
255+ std::vector<char *> argv;
256+ for (auto & arg : args) {
257+ argv.push_back (const_cast <char *>(arg.c_str ()));
258+ }
259+ argv.push_back (nullptr ); // NULL terminator
260+
261+ // Call the real CMOOSApp::Run(app_name, argc, argv)
262+ return BASE::Run (sAppName , argc, argv.data ());
251263 }
252264
253265 // we can support vectors of objects by not lists so
@@ -759,19 +771,17 @@ PYBIND11_MODULE(pymoos, m) {
759771 py::class_<MOOS::AppWrapper, CMOOSApp>(m, " app" )
760772 .def (py::init<>())
761773
762- .def (" run" , static_cast <bool (MOOS::AppWrapper::*)(const std::string&)>(&MOOS::AppWrapper::Run),
763- " Run the MOOS application with mission file. "
764- " Server, port, and app name are read from the mission file." ,
765- py::arg (" mission_file" ))
766-
767- .def (" run" , static_cast <bool (MOOS::AppWrapper::*)(const std::string&, int , const std::string&)>(&MOOS::AppWrapper::Run),
768- " Run the MOOS application with explicit server, port, and name. "
769- " Use this when not using a mission file." ,
770- py::arg (" server" ), py::arg (" port" ), py::arg (" name" ))
771-
772- .def (" run" , static_cast <bool (MOOS::AppWrapper::*)(const std::string&, int , const std::string&, const std::string&)>(&MOOS::AppWrapper::Run),
773- " Run the MOOS application with both explicit parameters and mission file." ,
774- py::arg (" server" ), py::arg (" port" ), py::arg (" name" ), py::arg (" mission_file" ))
774+ .def (" run" , &MOOS::AppWrapper::Run,
775+ " Run the MOOS application. Uses standard MOOS Run(app_name, argc, argv) pattern.\n "
776+ " Parameters:\n "
777+ " app_name: Name of the application\n "
778+ " mission_file: Optional path to .moos mission file (reads ServerHost, ServerPort, etc.)\n "
779+ " server_host: Optional server hostname (overrides mission file)\n "
780+ " server_port: Optional server port (overrides mission file)" ,
781+ py::arg (" app_name" ),
782+ py::arg (" mission_file" ) = " " ,
783+ py::arg (" server_host" ) = " " ,
784+ py::arg (" server_port" ) = 0 )
775785
776786 .def (" fetch" , &MOOS::AppWrapper::FetchMailAsVector,
777787 " Fetch incoming mail as a vector." )
0 commit comments