Draft documentation and option parsing for a "--monitor" option to run a command and monitor its input and output (#67).

This commit is contained in:
Andrew Wood
2026-03-11 23:37:09 +00:00
parent a33ee8ef26
commit 5f1893f094
5 changed files with 46 additions and 2 deletions
+17 -1
View File
@@ -680,6 +680,7 @@ opts_t opts_parse(unsigned int argc, char **argv)
{ "watchfd", 1, NULL, (int) 'd' },
{ "output", 1, NULL, (int) 'o' },
{ "average-rate-window", 1, NULL, (int) 'm' },
{ "monitor", 0, NULL, (int) 'M' },
#ifdef ENABLE_DEBUGGING
{ "debug", 1, NULL, (int) '!' },
#endif /* ENABLE_DEBUGGING */
@@ -688,7 +689,7 @@ opts_t opts_parse(unsigned int argc, char **argv)
/*@+nullassign@ */
int option_index = 0;
#endif /* HAVE_GETOPT_LONG */
char *short_options = "hVpteIrab8kTA:fvnqcWD:s:gl0i:w:H:N:u:F:x:L:B:CEZ:SYKOXU:R:Q:P:d:m:o:"
char *short_options = "hVpteIrab8kTA:fvnqcWD:s:gl0i:w:H:N:u:F:x:L:B:CEZ:SYKOXU:R:Q:P:d:m:o:M"
#ifdef ENABLE_DEBUGGING
"!:"
#endif
@@ -1102,6 +1103,9 @@ opts_t opts_parse(unsigned int argc, char **argv)
case 'm':
opts->average_rate_window = pv_getnum_count(optarg, opts->decimal_units);
break;
case 'M':
opts->action = PV_ACTION_MONITOR;
break;
#ifdef ENABLE_DEBUGGING
case '!':
debugging_output_destination(optarg);
@@ -1250,6 +1254,18 @@ opts_t opts_parse(unsigned int argc, char **argv)
/*@+mustfreefresh@ */
}
/*
* At least one non-option argument is required with -M.
*/
if ((PV_ACTION_MONITOR == opts->action) && (optind >= (int) argc)) {
/*@-mustfreefresh@ *//* see above */
fprintf(stderr, "%s: -M: %s\n", opts->program_name,
_("a command to run must be specified"));
opts_free(opts);
return NULL;
/*@+mustfreefresh@ */
}
/*
* Store remaining command-line arguments.
*/