MaCh3  2.8.0
Reference Guide
mach3.cpp
Go to the documentation of this file.
1 
10 #include "CLI/MaCh3Program.hpp"
11 
20 int main(int argc, char *argv[]) {
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 }
Module for MCMC diagnostic analysis.
Module for extracting penalty terms from systematic chains.
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
Core program class for the MaCh3 command-line interface.
Module for processing MCMC chains and producing diagnostic plots.
Module for performing diagnostic analysis on MCMC chains.
Module for extracting specific penalty terms from MCMC chains.
const MaCh3ArgumentParser & get_subcommand_used() const
Get the subcommand that was used in parsing.
Definition: m3argparse.hpp:40
Main program class that manages modules, plugins, and command-line parsing.
void add_core_module(IModule &module)
Add a core module to the program.
void completions(const std::string &prefix, const std::vector< std::string > &context) const
Generate completion suggestions given the current prefix and preceding words.
void install_completions() const
Install shell completion scripts for bash and zsh.
int Run()
Run the selected subcommand.
void load_dynamic_plugins()
Load dynamic plugins from the MACH3_PLUGINS environment variable.
Module for processing MCMC chains and producing various diagnostic plots.
int main(int argc, char *argv[])
Main entry point for the MaCh3 application.
Definition: mach3.cpp:20