cli.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
4 
5 int main(int argc, char** argv)
6 {
7  const auto usage = std::string("Usage: ") + argv[0] + " show|md5|fields|field-types|file|md5-text package/MessageType";
8 
9  if (argc <= 2)
10  {
11  std::cerr << usage << std::endl;
12  return 1;
13  }
14 
15  std::string action{argv[1]};
16 
17  if (action != "show" && action != "md5" && action != "fields" && action != "field-types" && action != "file" && action != "md5-text")
18  {
19  std::cerr << usage << std::endl;
20  return 2;
21  }
22 
23  std::string type{argv[2]};
24 
25  std::string result;
26 
27  if (action == "show")
28  {
29  result = ros::message::getFullDef(type);
30  if (result.empty())
31  {
32  std::cerr << "Definition for message type [" << type << "] could not be found!" << std::endl;
33  return 3;
34  }
35  }
36  else if (action == "md5")
37  {
38  result = ros::message::getMD5Sum(type);
39  if (result.empty())
40  {
41  std::cerr << "MD5 sum for message type [" << type << "] could not be found!" << std::endl;
42  return 4;
43  }
44  }
45  else if (action == "fields")
46  {
47  const auto fields = ros::message::getFieldNames(type);
48  if (fields.empty())
49  {
50  std::cerr << "Field names for message type [" << type << "] could not be found!" << std::endl;
51  return 5;
52  }
53  for (const auto& field : fields)
54  result += field + "\n";
55  }
56  else if (action == "field-types")
57  {
58  const auto fields = ros::message::getFieldTypes(type);
59  if (fields.empty())
60  {
61  std::cerr << "Field types for message type [" << type << "] could not be found!" << std::endl;
62  return 5;
63  }
64  for (const auto& field : fields)
65  result += field + "\n";
66  }
67  else if (action == "file")
68  {
69  result = ros::message::getMsgFile(type);
70  if (result.empty())
71  {
72  std::cerr << "Message proto file for message type [" << type << "] could not be found!" << std::endl;
73  return 6;
74  }
75  }
76  else if (action == "md5-text")
77  {
78  result = ros::message::getMD5Text(type);
79  if (result.empty())
80  {
81  std::cerr << "MD5 sum source text for message type [" << type << "] could not be found!" << std::endl;
82  return 7;
83  }
84  }
85 
86  std::cout << result; // intentionally no \n
87  return 0;
88 }
ros::message::getMD5Text
std::string getMD5Text(const std::string &messageType)
Return the exact text from which the MD5 sum of the message is computed.
Definition: rosmsg_cpp.cpp:256
ros::message::getFieldNames
std::vector< std::string > getFieldNames(const std::string &messageType)
Return the names of fields of the message type (non-recursive).
Definition: rosmsg_cpp.cpp:172
ros::message::getFieldTypes
std::vector< std::string > getFieldTypes(const std::string &messageType)
Return the types of fields of the message type (non-recursive).
Definition: rosmsg_cpp.cpp:188
ros::message::getFullDef
std::string getFullDef(const std::string &messageType)
Return the full recursive definition of the message type - the same as genpy generates.
Definition: rosmsg_cpp.cpp:146
main
int main(int argc, char **argv)
Definition: cli.cpp:5
rosmsg_cpp.h
ros::message::getMsgFile
std::string getMsgFile(const std::string &messageType)
Get the path to the .msg file corresponding to the given message type.
Definition: rosmsg_cpp.cpp:204
ros::message::getMD5Sum
std::string getMD5Sum(const std::string &messageType)
Return the MD5 sum of the message type - the same as genpy generates.
Definition: rosmsg_cpp.cpp:154


rosmsg_cpp
Author(s): Martin Pecka
autogenerated on Mon Apr 17 2023 02:30:24