-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up command handling in hdp.c/h #433
Conversation
derobins
commented
Sep 13, 2023
- Move list of commands inside hdp.c
- Remove HDP_MASTER scheme
- Tie command string & enum value together in a struct to keep in sync
- Minor tidying
* Move list of commands inside hdp.c * Remove HDP_MASTER scheme * Tie command string & enum value together in a struct to keep in sync * Minor tidying
#ifdef HDP_MASTER | ||
= {"help", "list", "dumpsds", "dumprig", "dumpvg", "dumpvd", "dumpgr"} | ||
#endif /* HDP_MASTER */ | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved into hdp.c since it's not used anywhere else
typedef struct command_t { | ||
const command_value_t value; | ||
const char *name; | ||
} command_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tying the enum value and string together into a struct ensures they will never be out of sync
Also return EXIT_FAILURE/SUCCESS instead of 1 and 0
if (cmd == BAD_COMMAND) { | ||
printf("Invalid command: %s\n", argv[curr_arg]); | ||
exit(EXIT_FAILURE); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before we printed the value of cmd (in code below), which would just be the sentinel NONE value, which is unhelpful.
break; | ||
} /* end switch */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Printing the enum value was unhelpful. Printing the string is better, which we do above.
Test failures are due to GitHub flakiness and aren't real |