Skip to content

Commit

Permalink
Command line arguments to set paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
LogashenkoDL committed Sep 25, 2020
1 parent c4a70a0 commit d5b3801
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 3 deletions.
11 changes: 10 additions & 1 deletion ugbase/bridge/misc_bridges/util_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,18 @@ void RegisterBridge_Util(Registry& reg, string parentGroup)
reg.add_function("ug_get_current_path", &GetCurrentPath, grp,
"pathName", "", "Returns the current path");

reg.add_function("ug_set_root_path", &SetRootPath, grp,
reg.add_function("ug_set_root_path", static_cast<void(*)(const std::string&)>(&SetRootPath), grp,
"", "pathName", "Sets the paths relative to passed root path");

reg.add_function("ug_set_script_path", static_cast<void(*)(const std::string&)>(&SetScriptPath), grp,
"", "pathName", "Sets the script path");

reg.add_function("ug_set_apps_path", static_cast<void(*)(const std::string&)>(&SetAppsPath), grp,
"", "pathName", "Sets the script path");

reg.add_function("ug_set_plugin_path", static_cast<void(*)(const std::string&)>(&SetPluginPath), grp,
"", "pathName", "Sets the plugin path");

reg.add_function("ExecuteSystemCommand", &ExecuteSystemCommand, grp,
"success", "command", "Executes a command in the system shell");

Expand Down
63 changes: 63 additions & 0 deletions ugbase/ug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,69 @@ void SetRootPath(const std::string& strRoot)
PathProvider::set_path(APPS_PATH, strRoot + pathSep + "apps");
}

/**
* init app, script and data paths for a given root path
*/
void SetRootPath(const char* c_strRoot)
{
std::string strRoot(c_strRoot);
SetRootPath(strRoot);
}

/**
* init script path
*/
void SetScriptPath(const std::string& strScript)
{
PROFILE_FUNC();
PathProvider::set_path(SCRIPT_PATH, strScript);
}

/**
* init script path
*/
void SetScriptPath(const char* c_strScript)
{
std::string strScript(c_strScript);
SetScriptPath(strScript);
}

/**
* init apps path
*/
void SetAppsPath(const std::string& strApps)
{
PROFILE_FUNC();
PathProvider::set_path(APPS_PATH, strApps);
}

/**
* init apps path
*/
void SetAppsPath(const char* c_strApps)
{
std::string strApps(c_strApps);
SetAppsPath(strApps);
}

/**
* init plugin path
*/
void SetPluginPath(const std::string& strPlugin)
{
PROFILE_FUNC();
PathProvider::set_path(PLUGIN_PATH, strPlugin);
}

/**
* init plugin path
*/
void SetPluginPath(const char* c_strPlugin)
{
std::string strPlugin(c_strPlugin);
SetPluginPath(strPlugin);
}

////////////////////////////////////////////////////////////////////////
/// initializes ug
/** This method should be called at the beginning of main(...).
Expand Down
13 changes: 13 additions & 0 deletions ugbase/ug.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ UG_API bool InitPaths(const char* argv0);
* - PLUGIN_PATH
*/
UG_API void SetRootPath(const std::string& strRoot);
UG_API void SetRootPath(const char* c_strRoot);

/// Initializes the SCRIPT_PATH of ug::PathProvider.
UG_API void SetScriptPath(const std::string& strScript);
UG_API void SetScriptPath(const char* c_strScript);

/// Initializes the APPS_PATH of ug::PathProvider.
UG_API void SetAppsPath(const std::string& strApps);
UG_API void SetAppsPath(const char* c_strApps);

/// Initializes the PLUGIN_PATH of ug::PathProvider.
UG_API void SetPluginPath(const std::string& strPlugin);
UG_API void SetPluginPath(const char* c_strPlugin);

/// finalizes ug
/** If ug has been compiled for parallel use (UG_PARALLEL is defined)
Expand Down
20 changes: 18 additions & 2 deletions ugbase/ug_shell/ugshell_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,28 @@ int ugshell_main(int argc, char* argv[])
if(FindParam("-profile", argc, argv))
UGOutputProfileStatsOnExit(true);

const bool quiet = FindParam("-quiet", argc, argv);
const bool quiet = FindParam("-quiet", argc, argv);

const bool help = FindParam("-help", argc, argv);
const bool help = FindParam("-help", argc, argv);

const bool interactiveShellRequested = FindParam("-noquit", argc, argv);
bool defaultInteractiveShell = true; // may be changed later

const char* rootPath = NULL;
if(ParamToString(&rootPath, "-rootpath", argc, argv))
SetRootPath(rootPath);

const char* scriptPath = NULL;
if(ParamToString(&scriptPath, "-scriptpath", argc, argv))
SetScriptPath(scriptPath);

const char* appsPath = NULL;
if(ParamToString(&appsPath, "-appspath", argc, argv))
SetAppsPath(appsPath);

const char* pluginPath = NULL;
if(ParamToString(&pluginPath, "-pluginpath", argc, argv))
SetPluginPath(pluginPath);

#ifdef UG_PARALLEL
const bool parallelEnvironment = (pcl::NumProcs() > 1);
Expand Down

0 comments on commit d5b3801

Please sign in to comment.