shared/shell: Fix not handling sort options
getopt_long index is only valid for long options.
diff --git a/src/shared/shell.c b/src/shared/shell.c
index 1fec58d..3aabda7 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -787,7 +787,7 @@
void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
{
- int c, index = 0;
+ int c, index = -1;
struct option options[256];
char optstr[256];
size_t offset;
@@ -817,6 +817,13 @@
data.timeout = atoi(optarg);
break;
default:
+ if (index < 0) {
+ for (index = 0; options[index].val; index++) {
+ if (c == options[index].val)
+ break;
+ }
+ }
+
if (c != opt->options[index - offset].val) {
usage(argc, argv, opt);
exit(EXIT_SUCCESS);