Lodestar
An integrated real-time control package in C++
BasicCLI.hpp
1 //
2 // Created by Hamza El-Kebir on 2/15/22.
3 //
4 
5 #ifndef LODESTAR_BASICCLI_HPP
6 #define LODESTAR_BASICCLI_HPP
7 
8 #include <CLI11/CLI11.hpp>
9 #include <Lodestar/blocks/aux/Executor.hpp>
10 #include <LodestarConfig.hpp>
11 
12 namespace ls {
13  namespace cli {
14  class BasicCLI {
15  public:
16  struct BasicCLIOptions {
17  bool graph = false;
18  bool dotFile = false;
19  bool version = false;
21  };
22 
23  static CLI::App &makeApp(CLI::App &app, BasicCLIOptions &opts, ls::blocks::aux::Executor &ex)
24  {
25  opts.ex = &ex;
26 
27  app.description("A Lodestar application.");
28  app.add_flag("-v,--version", opts.version, "Lodestar version");
29  app.add_flag("-g,--graph", opts.graph, "Display graph");
30  app.add_flag("-d,--dot-file", opts.dotFile, "Output graph as dot file");
31 
32  return app;
33  }
34 
35  static int
36  runApp(int argc, char **argv, CLI::App &app, BasicCLIOptions &opts)
37  {
38  CLI11_PARSE(app, argc, argv);
39 
40  if (opts.graph) {
41  if (opts.dotFile) {
42  ::std::stringstream ss;
43  opts.ex->makeDotFile(ss);
44  ::std::cout << ss.str() << ::std::endl;
45  } else {
46  ::std::cout << opts.ex->getAsciiGraph(true, true) << ::std::endl;
47  }
48  } else if (opts.version) {
49  ::std::cout << "Lodestar v" << LS_VERSION_MAJOR << "." << LS_VERSION_MAJOR << "."
50  << LS_VERSION_PATCH << ::std::endl;
51  }
52 
53  return 0;
54  }
55  };
56  }
57 }
58 
59 
60 #endif //LODESTAR_BASICCLI_HPP
ls::blocks::aux::Executor
Definition: Executor.hpp:23
ls
Main Lodestar code.
Definition: BilinearTransformation.hpp:12
ls::cli::BasicCLI::BasicCLIOptions
Definition: BasicCLI.hpp:16
ls::cli::BasicCLI
Definition: BasicCLI.hpp:14