aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Sucan <jan@jansucan.com>2024-03-24 15:05:53 +0100
committerJán Sučan <jan@jansucan.com>2024-03-24 15:14:13 +0100
commite54d3a1e4e7491c41610a6bac3789a10e8cdf7c6 (patch)
tree09c0e52981ca6626cc0059184f18ca2b79c2b737
parentd4a2243237fb591cce2e18cb98934dea8465efb4 (diff)
Remove the -h option
This simplifies parsing of the options. Help message is printed on wrong arguments. Keep only the help operation.
-rw-r--r--src/options.cpp16
-rw-r--r--tests/008-help_option.sh2
2 files changed, 3 insertions, 15 deletions
diff --git a/src/options.cpp b/src/options.cpp
index 51a9260..ecb1026 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -43,7 +43,6 @@
#define OPTIONS_DEFAULT_BUFFER_SIZE (4 * 1024 * 1024)
struct common_options {
- bool help;
uint32_t sector_size;
uint32_t buffer_size;
};
@@ -149,7 +148,6 @@ options_parse_operation(const char *const op_name, options_t *const opts)
static void
options_init_common(struct common_options *const opts)
{
- opts->help = false;
opts->sector_size = OPTIONS_DEFAULT_SECTOR_SIZE;
opts->buffer_size = OPTIONS_DEFAULT_BUFFER_SIZE;
}
@@ -162,16 +160,12 @@ options_parse_common(int *const argc, char ***const argv,
char *arg_sector_size = NULL;
char *arg_buffer_size = NULL;
- while ((ch = getopt(*argc, *argv, ":b:hs:")) != -1) {
+ while ((ch = getopt(*argc, *argv, ":b:s:")) != -1) {
switch (ch) {
case 'b':
arg_buffer_size = optarg;
break;
- case 'h':
- opts->help = true;
- break;
-
case 's':
arg_sector_size = optarg;
break;
@@ -223,9 +217,7 @@ options_parse_backup(int *const argc, char ***const argv, options_t *const opts)
return false;
}
- if (common_opts.help) {
- opts->operation_id = OPERATION_ID_HELP;
- } else if (*argc < 3) {
+ if (*argc < 3) {
print_error("missing arguments");
return false;
} else if (*argc > 3) {
@@ -252,9 +244,7 @@ options_parse_restore(int *const argc, char ***const argv,
return false;
}
- if (common_opts.help) {
- opts->operation_id = OPERATION_ID_HELP;
- } else if (*argc < 2) {
+ if (*argc < 2) {
print_error("missing arguments");
return false;
} else if (*argc > 2) {
diff --git a/tests/008-help_option.sh b/tests/008-help_option.sh
index 494aeac..75d9d4e 100644
--- a/tests/008-help_option.sh
+++ b/tests/008-help_option.sh
@@ -5,7 +5,5 @@ source ./assert.sh
PROGRAM_EXEC="$1"
assert "Usage" "" 0 $PROGRAM_EXEC help
-assert "Usage" "" 0 $PROGRAM_EXEC backup -h
-assert "Usage" "" 0 $PROGRAM_EXEC restore -h
exit 0