bin/*: correct error message for invalid long option specification

The commands under "bin/" output the error messages by themselves by
setting opterr to 0, and are compatible with getopt_long, but if
an invalid long option is specified, the option that causes the error
will not be displayed as shown below:

 lscp: invalid option --

Also lscp and lssu do not properly display error messages for options
that require an additional argument and it is not provided.

Fix these issues by not setting opterr to 0 and leaving error output
for argument options to getopt() or getopt_long()'s built-in features.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
This commit is contained in:
Ryusuke Konishi 2024-03-03 22:09:21 +09:00
parent 5e06a9697d
commit a34ee4f35f
6 changed files with 6 additions and 14 deletions

View File

@ -86,8 +86,6 @@ int main(int argc, char *argv[])
#endif /* _GNU_SOURCE */
sigset_t sigset, oldset;
opterr = 0;
last = strrchr(argv[0], '/');
progname = last ? last + 1 : argv[0];
@ -107,7 +105,7 @@ int main(int argc, char *argv[])
PACKAGE_VERSION);
exit(EXIT_SUCCESS);
default:
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
exit(EXIT_FAILURE);
}
}

View File

@ -264,8 +264,6 @@ int main(int argc, char *argv[])
int option_index;
#endif /* _GNU_SOURCE */
opterr = 0;
last = strrchr(argv[0], '/');
progname = last ? last + 1 : argv[0];
@ -285,7 +283,7 @@ int main(int argc, char *argv[])
PACKAGE_VERSION);
exit(EXIT_SUCCESS);
default:
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
exit(EXIT_FAILURE);
}
}

View File

@ -418,7 +418,6 @@ int main(int argc, char *argv[])
mode = NILFS_CHECKPOINT;
rvs = 0;
opterr = 0; /* prevent error message */
progname = strrchr(argv[0], '/');
if (progname == NULL)
progname = argv[0];
@ -463,7 +462,7 @@ int main(int argc, char *argv[])
PACKAGE_VERSION);
exit(EXIT_SUCCESS);
default:
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
exit(EXIT_FAILURE);
}
}

View File

@ -298,7 +298,6 @@ int main(int argc, char *argv[])
int option_index;
#endif /* _GNU_SOURCE */
opterr = 0;
progname = strrchr(argv[0], '/');
if (progname == NULL)
progname = argv[0];
@ -345,7 +344,7 @@ int main(int argc, char *argv[])
PACKAGE_VERSION);
exit(EXIT_SUCCESS);
default:
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
exit(EXIT_FAILURE);
}
}

View File

@ -81,7 +81,6 @@ int main(int argc, char *argv[])
ss = 0;
print = 0;
opterr = 0;
last = strrchr(argv[0], '/');
progname = last ? last + 1 : argv[0];
@ -107,7 +106,7 @@ int main(int argc, char *argv[])
PACKAGE_VERSION);
exit(EXIT_SUCCESS);
default:
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
exit(EXIT_FAILURE);
}
}

View File

@ -147,7 +147,6 @@ int main(int argc, char *argv[])
int option_index;
#endif /* _GNU_SOURCE */
opterr = 0;
last = strrchr(argv[0], '/');
progname = last ? last + 1 : argv[0];
@ -175,7 +174,7 @@ int main(int argc, char *argv[])
PACKAGE_VERSION);
exit(EXIT_SUCCESS);
default:
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
exit(EXIT_FAILURE);
}
}