MaCh3  2.8.0
Reference Guide
Functions
mach3.cpp File Reference

Main entry point for the MaCh3 command-line interface. More...

#include "CLI/Modules/ProcessMCMCModule.hpp"
#include "CLI/Modules/DiagMCMCModule.hpp"
#include "CLI/Modules/GetPenaltyTermModule.hpp"
#include "CLI/MaCh3Program.hpp"
Include dependency graph for mach3.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 Main entry point for the MaCh3 application. More...
 

Detailed Description

Main entry point for the MaCh3 command-line interface.

This file contains the main function that initializes the MaCh3 program, registers core modules, loads dynamic plugins, and processes command-line arguments.

Definition in file mach3.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main entry point for the MaCh3 application.

Initializes the MaCh3 program with core modules and dynamic plugins, parses command-line arguments, and executes the selected subcommand.

Parameters
argcNumber of command-line arguments
argvArray of command-line argument strings
Returns
Exit code (0 on success, non-zero on error)

Definition at line 20 of file mach3.cpp.

20  {
21  M3::MaCh3Program program("mach3");
22 
23  // Hidden completion option — accepts prefix + preceding words as context
24  program.add_argument("--complete")
25  .hidden()
26  .nargs(argparse::nargs_pattern::any);
27 
28  // Hidden installer option
29  program.add_argument("--install-completions")
30  .help("")
31  .flag();
32 
34  M3::DiagMCMCModule diag;
36 
37  program.add_core_module(proc);
38  program.add_core_module(diag);
39  program.add_core_module(penterm);
40  program.load_dynamic_plugins();
41 
42  // Pre-scan for --complete before argparse processes the full command line,
43  // so incomplete commands (missing required args) still produce completions.
44  for (int i = 1; i < argc; i++) {
45  if (std::string_view(argv[i]) == "--complete") {
46  std::string prefix = (i + 1 < argc) ? argv[i + 1] : "";
47  std::vector<std::string> context;
48  for (int j = i + 2; j < argc; j++) {
49  context.emplace_back(argv[j]);
50  }
51  program.completions(prefix, context);
52  return 0;
53  }
54  }
55 
56  try {
57  program.parse_args(argc, argv);
58  }
59  catch (const std::exception& err) {
60 
61  std::cerr << err.what() << std::endl;
62  std::cerr << program.get_subcommand_used();
63  MACH3LOG_ERROR(err.what());
64  return 1;
65  }
66  catch(...){
67  MACH3LOG_ERROR("Unknown parsing error.");
68  return 1;
69  }
70 
71  // no subcommand args
72  if (!program.get_subcommand_used()){
73  std::cerr << program.get_subcommand_used();
74  return 2;
75  }
76 
77 
78  if (program.get<bool>("--install-completions")) {
79  program.install_completions();
80  return 0;
81  }
82 
83  try{
84  program.Run();
85  }
86  catch(...){
87  return 3;
88  }
89 
90  return 0;
91 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
Module for performing diagnostic analysis on MCMC chains.
Module for extracting specific penalty terms from MCMC chains.
Main program class that manages modules, plugins, and command-line parsing.
Module for processing MCMC chains and producing various diagnostic plots.