mvsim-cli-node.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2020 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mvsim/Comms/Client.h>
11 
12 #include "mvsim-cli.h"
13 
14 static int printCommandsNode(bool showErrorMsg);
15 static int nodeList();
16 
17 static const std::map<std::string, cmd_t> cliNodeCommands = {
18  {"list", cmd_t(&nodeList)},
19 };
20 
22 {
23  const auto& lstCmds = argCmd.getValue();
24  if (argHelp.isSet()) return printCommandsNode(false);
25  if (lstCmds.size() != 2) return printCommandsNode(true);
26 
27  // Take second unlabeled argument:
28  const std::string subcommand = lstCmds.at(1);
29  auto itSubcmd = cliNodeCommands.find(subcommand);
30 
31  if (itSubcmd == cliNodeCommands.end()) return printCommandsNode(true);
32 
33  // Execute command:
34  return (itSubcmd->second)();
35 }
36 
37 int nodeList()
38 {
40 
41  client.setMinLoggingLevel(
42  mrpt::typemeta::TEnumType<mrpt::system::VerbosityLevel>::name2value(
43  argVerbosity.getValue()));
44 
45  std::cout << "# Connecting to server...\n";
46  client.connect();
47  std::cout << "# Connected.\n";
48  std::cout << "# Querying list of nodes to server...\n";
49  const auto lstNodes = client.requestListOfNodes();
50 
51  std::cout << "# Done. Found " << lstNodes.size() << " nodes:\n";
52 
53  for (const auto& n : lstNodes)
54  {
55  std::cout << "- name: \"" << n.name << "\"\n";
56  }
57 
58  return 0;
59 }
60 
61 int printCommandsNode(bool showErrorMsg)
62 {
63  if (showErrorMsg)
64  {
66  std::cerr << "Error: missing or unknown subcommand.\n";
68  }
69 
70  fprintf(
71  stderr,
72  R"XXX(Usage:
73 
74  mvsim node --help Show this help
75  mvsim node list List all nodes connected to the server.
76 
77 )XXX");
78 
79  return showErrorMsg ? 1 : 0;
80 }
int commandNode()
void BASE_IMPEXP setConsoleColor(TConsoleColor color, bool changeStdErr=false)
std::function< int(void)> cmd_t
Definition: mvsim-cli.h:23
TCLAP::SwitchArg argHelp("h","help","Shows more detailed help for command", cmd)
static int printCommandsNode(bool showErrorMsg)
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
std::vector< InfoPerNode > requestListOfNodes()
GLsizei n
TCLAP::ValueArg< std::string > argVerbosity("v","verbose","Verbosity level", false,"INFO","ERROR|WARN|INFO|DEBUG", cmd)
static const std::map< std::string, cmd_t > cliNodeCommands
bool isSet() const
TCLAP::UnlabeledMultiArg< std::string > argCmd("command","Command to run. Run 'mvsim help' to list commands.", false,"", cmd)
static int nodeList()


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51