Skip to content

Commit 43e3258

Browse files
author
Avi SZYCHTER
committed
Improved CLI for can-parse
1 parent 90a03fb commit 43e3258

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

utils/can-parse/can-parse.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ enum CanParseAction {
1919
};
2020

2121
static std::string CHECKFRAME_ACTION = "checkframe";
22-
23-
void showUsage(char* program_name) {
24-
std::cerr << "Usage: " << program_name << " [ACTION] <path/to/file>" << std::endl;
25-
std::cerr << "Possible actions: " << std::endl;
26-
std::cerr << "\t" << CHECKFRAME_ACTION << "\tCheck different properties of the CAN database" << std::endl;
27-
std::cerr << "Currently supported formats: DBC" << std::endl;
22+
static std::string PRINTFRAME_ACTION = "printframe";
23+
24+
void showUsage(std::ostream& ostrm, char* program_name) {
25+
ostrm << "Usage: " << program_name << " [ACTION] <path/to/file>" << std::endl;
26+
ostrm << "When no action is specified, defaults to " << PRINTFRAME_ACTION << std::endl;
27+
ostrm << "Possible actions: " << std::endl;
28+
ostrm << "\t" << PRINTFRAME_ACTION << "\tPrint the content of the CAN database" << std::endl;
29+
ostrm << "\t" << CHECKFRAME_ACTION << "\tCheck different properties of the CAN database" << std::endl;
30+
ostrm << "Currently supported formats: DBC" << std::endl;
2831
}
2932

3033

@@ -41,12 +44,15 @@ std::tuple<CanParseAction, std::string> extractAction(int argc, char** argv) {
4144
size_t i = 0;
4245
for(const std::string& arg : args) {
4346
// First argument, we check for potential actions
44-
std::cout << "Arg: " << arg << std::endl;
4547
if(i++ == 0) {
4648
if(arg == CHECKFRAME_ACTION) {
4749
action = CheckAll;
4850
continue;
4951
}
52+
else if(arg == PRINTFRAME_ACTION) {
53+
action = PrintAll;
54+
continue;
55+
}
5056
}
5157

5258
// Check for options
@@ -76,12 +82,12 @@ int main(int argc, char** argv) {
7682
}
7783
catch(const CanParseException& e) {
7884
std::cerr << "Invalid use of the program: " << e.what() << std::endl;
79-
showUsage(argv[0]);
85+
showUsage(std::cerr, argv[0]);
8086
return 1;
8187
}
8288

8389
if(action == Help) {
84-
showUsage(argv[0]);
90+
showUsage(std::cout, argv[0]);
8591
return 0;
8692
}
8793

@@ -105,6 +111,10 @@ int main(int argc, char** argv) {
105111
check_all_frames(db);
106112
break;
107113

114+
case Help:
115+
// Already handled before.
116+
break;
117+
108118
default:
109119
std::cerr << "Acton not implemented yet." << std::endl;
110120
return 3;

0 commit comments

Comments
 (0)