diff --git a/sonic-db-cli/sonic-db-cli.cpp b/sonic-db-cli/sonic-db-cli.cpp index 7060e489a..7d6b654c2 100755 --- a/sonic-db-cli/sonic-db-cli.cpp +++ b/sonic-db-cli/sonic-db-cli.cpp @@ -208,12 +208,12 @@ void parseCliArguments( Options &options) { // Parse argument with getopt https://man7.org/linux/man-pages/man3/getopt.3.html - const char* short_options = "hsnc"; + const char* short_options = "hsn:c:"; static struct option long_options[] = { - {"help", optional_argument, NULL, 'h' }, - {"unixsocket", optional_argument, NULL, 's' }, - {"namespace", optional_argument, NULL, 'n' }, - {"container_name", optional_argument, NULL, 'c' }, + {"help", no_argument, NULL, 'h' }, + {"unixsocket", no_argument, NULL, 's' }, + {"namespace", required_argument, NULL, 'n' }, + {"container_name", required_argument, NULL, 'c' }, // The last element of the array has to be filled with zeros. {0, 0, 0, 0 } }; @@ -235,10 +235,9 @@ void parseCliArguments( break; case 'n': - if (optind < argc) + if (optarg) { - options.m_namespace = argv[optind]; - optind++; + options.m_namespace = optarg; } else { @@ -247,10 +246,9 @@ void parseCliArguments( break; case 'c': - if (optind < argc) + if (optarg) { - options.m_container_name = argv[optind]; - optind++; + options.m_container_name = optarg; } else {