Skip to content

Commit d598dea

Browse files
authored
[syncd] Refactor syncd request shutdown command line parser (#944)
1 parent 26b2237 commit d598dea

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

syncd/RequestShutdownCommandLineOptionsParser.cpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ std::shared_ptr<RequestShutdownCommandLineOptions> RequestShutdownCommandLineOpt
2424
{ "warm", no_argument, 0, 'w' },
2525
{ "fast", no_argument, 0, 'f' },
2626
{ "pre", no_argument, 0, 'p' }, // Requesting pre shutdown
27+
{ "help", no_argument, 0, 'h' },
2728

2829
{ "globalContext", required_argument, 0, 'g' },
2930
{ "contextContig", required_argument, 0, 'x' },
31+
{ 0, 0, 0, 0 }
3032
};
3133

3234
bool optionSpecified = false;
@@ -35,7 +37,7 @@ std::shared_ptr<RequestShutdownCommandLineOptions> RequestShutdownCommandLineOpt
3537
{
3638
int option_index = 0;
3739

38-
int c = getopt_long(argc, argv, "cwfpg:x:", long_options, &option_index);
40+
int c = getopt_long(argc, argv, "cwfpg:x:h", long_options, &option_index);
3941

4042
if (c == -1)
4143
break;
@@ -68,7 +70,11 @@ std::shared_ptr<RequestShutdownCommandLineOptions> RequestShutdownCommandLineOpt
6870

6971
case 'x':
7072
options->m_contextConfig = std::string(optarg);
71-
break;
73+
break
74+
;
75+
case 'h':
76+
printUsage();
77+
exit(EXIT_FAILURE);
7278

7379
default:
7480
SWSS_LOG_ERROR("getopt failure");
@@ -92,19 +98,24 @@ void RequestShutdownCommandLineOptionsParser::printUsage()
9298
{
9399
SWSS_LOG_ENTER();
94100

95-
std::cout << "Usage: syncd_request_shutdown [-w] [--warm] [-p] [--pre] [-c] [--cold] [-f] [--fast] [-g idx] [-x contextConfig]" << std::endl;
101+
std::cout << "Usage: syncd_request_shutdown [-w] [--warm] [-p] [--pre] [-c] [--cold] [-f] [--fast] [-g idx] [-x contextConfig] [-h] [--help]" << std::endl;
96102

97103
std::cerr << std::endl;
98104

99105
std::cerr << "Shutdown option must be specified" << std::endl;
100106
std::cerr << "---------------------------------" << std::endl;
101-
std::cerr << " --warm -w for warm restart" << std::endl;
102-
std::cerr << " --pre -p for warm pre-shutdown" << std::endl;
103-
std::cerr << " --cold -c for cold restart" << std::endl;
104-
std::cerr << " --fast -f for fast restart" << std::endl;
105-
std::cerr << std::endl;
106-
std::cout << " --globalContext -g" << std::endl;
107-
std::cout << " Global context index to load from context config file" << std::endl;
108-
std::cout << " --contextConfig -x" << std::endl;
109-
std::cout << " Context configuration file" << std::endl;
107+
std::cerr << " -w --warm" << std::endl;
108+
std::cerr << " For warm restart" << std::endl;
109+
std::cerr << " -p --pre" << std::endl;
110+
std::cerr << " For warm pre-shutdown" << std::endl;
111+
std::cerr << " -c --cold" << std::endl;
112+
std::cerr << " For cold restart" << std::endl;
113+
std::cerr << " -f --fast" << std::endl;
114+
std::cerr << " For fast restart" << std::endl;
115+
std::cout << " -g --globalContext " << std::endl;
116+
std::cout << " Global context index to load from context config file" << std::endl;
117+
std::cout << " -x --contextConfig" << std::endl;
118+
std::cout << " Context configuration file" << std::endl;
119+
std::cout << " -h --help" << std::endl;
120+
std::cout << " Print usege" << std::endl;
110121
}

0 commit comments

Comments
 (0)