diff --git a/.gitignore b/.gitignore index 1e89810048..00819589e2 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ testing/src/project_version.h .__tmp.log .check_syntax.tmp .check_syntax2.tmp +*.venv +__pycache__ +.DS_Store \ No newline at end of file diff --git a/core/command.h b/core/command.h index 8941cdf24d..621df57acd 100644 --- a/core/command.h +++ b/core/command.h @@ -23,6 +23,7 @@ #include "app.h" #include "exec_version.h" +#include "mrtrix.h" #ifdef MRTRIX_PROJECT namespace MR { namespace App { @@ -92,6 +93,18 @@ int main(int cmdline_argc, char **cmdline_argv) { ::MR::GUI::App app(cmdline_argc, cmdline_argv); #endif ::MR::App::parse(); + + // ENVVAR name: MRTRIX_CLI_PARSE_ONLY + // ENVVAR Set the command to parse the provided inputs and then quit + // ENVVAR if it is set. This can be used in the CI of wrapping code, + // ENVVAR such as the automatically generated Pydra interfaces. + // ENVVAR Note that it will have no effect for R interfaces + char *parse_only = std::getenv("MRTRIX_CLI_PARSE_ONLY"); + if (parse_only && ::MR::to(parse_only)) { + CONSOLE("Quitting after parsing command-line arguments successfully due to environment variable " + "'MRTRIX_CLI_PARSE_ONLY'"); + return 0; + } run(); } catch (::MR::Exception &E) { E.display(); diff --git a/core/exception.h b/core/exception.h index 34445faf52..39a27ebadc 100644 --- a/core/exception.h +++ b/core/exception.h @@ -65,19 +65,19 @@ extern void (*report_to_user_func)(const std::string &msg, int type); #define CONSOLE(msg) \ if (MR::App::log_level >= 1) \ - report_to_user_func(msg, -1) + ::MR::report_to_user_func(msg, -1) #define FAIL(msg) \ if (MR::App::log_level >= 0) \ - report_to_user_func(msg, 0) + ::MR::report_to_user_func(msg, 0) #define WARN(msg) \ if (MR::App::log_level >= 1) \ - report_to_user_func(msg, 1) + ::MR::report_to_user_func(msg, 1) #define INFO(msg) \ if (MR::App::log_level >= 2) \ - report_to_user_func(msg, 2) + ::MR::report_to_user_func(msg, 2) #define DEBUG(msg) \ if (MR::App::log_level >= 3) \ - report_to_user_func(msg, 3) + ::MR::report_to_user_func(msg, 3) class Exception { public: diff --git a/docs/reference/environment_variables.rst b/docs/reference/environment_variables.rst index 29f968b6af..e98197a68c 100644 --- a/docs/reference/environment_variables.rst +++ b/docs/reference/environment_variables.rst @@ -24,6 +24,13 @@ List of MRtrix3 environment variables when reading DICOM data, match the StudyName entry against the string provided +.. envvar:: MRTRIX_CLI_PARSE_ONLY + + Set the command to parse the provided inputs and then quit + if it is set. This can be used in the CI of wrapping code, + such as the automatically generated Pydra interfaces. + Note that it will have no effect for R interfaces + .. envvar:: MRTRIX_CONFIGFILE This can be used to set the location of the system-wide diff --git a/lib/mrtrix3/app.py b/lib/mrtrix3/app.py index 5792207121..c80a413ad5 100644 --- a/lib/mrtrix3/app.py +++ b/lib/mrtrix3/app.py @@ -192,6 +192,21 @@ def _execute(module): #pylint: disable=unused-variable CMDLINE.print_citation_warning() return_code = 0 + + cli_parse_only = os.getenv('MRTRIX_CLI_PARSE_ONLY') + if cli_parse_only: + try: + if cli_parse_only.lower() in ['yes', 'true'] or int(cli_parse_only): + console( + 'Quitting after parsing command-line arguments successfully due to ' + 'environment variable "MRTRIX_CLI_PARSE_ONLY"' + ) + sys.exit(return_code) + except ValueError: + warn('Potentially corrupt environment variable "MRTRIX_CLI_PARSE_ONLY" ' + '= "' + cli_parse_only + '"; ignoring') + sys.exit(return_code) + try: module.execute() except (run.MRtrixCmdError, run.MRtrixFnError) as exception: