mvsim-cli-node.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2023 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 const std::map<std::string, cmd_t> cliNodeCommands = {
18  {"list", cmd_t(&nodeList)},
19 };
20 
22 {
23  const auto& lstCmds = cli->argCmd.getValue();
24  if (cli->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  cli->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()
std::function< int(void)> cmd_t
Definition: mvsim-cli.h:74
static int printCommandsNode(bool showErrorMsg)
std::vector< InfoPerNode > requestListOfNodes()
void setConsoleErrorColor()
const std::map< std::string, cmd_t > cliNodeCommands
static int nodeList()
std::unique_ptr< cli_flags > cli
void setConsoleNormalColor()


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21