]> granicus.if.org Git - icinga2/commitdiff
CLI: Hide "Command options" if command is null
authorMhd Sulhan <ms@kilabit.info>
Thu, 22 Oct 2015 15:49:42 +0000 (22:49 +0700)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 26 Oct 2015 07:05:09 +0000 (08:05 +0100)
Before this commit, if icinga2 command executed without any argument,
the program will print empty "Command options".

While at it, clean the whitespaces.

fixes #10439

Signed-off-by: Gunnar Beutner <gunnar@beutner.name>
lib/cli/clicommand.cpp

index 30d52aa285866812b2f50b616774146b23d1dd44..723f1ae46ecd9ed92f758ae39797c5aed39cfe94 100644 (file)
@@ -48,7 +48,7 @@ std::vector<String> icinga::GetBashCompletionSuggestions(const String& type, con
                result.push_back(wline);
        }
        fclose(fp);
-       
+
        /* Append a slash if there's only one suggestion and it's a directory */
        if ((type == "file" || type == "directory") && result.size() == 1) {
                String path = result[0];
@@ -200,12 +200,11 @@ bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& vi
 found_command:
        lock.unlock();
 
-       po::options_description vdesc("Command options");
-
-       if (command)
+       if (command) {
+               po::options_description vdesc("Command options");
                command->InitParameters(vdesc, hiddenDesc);
-
-       visibleDesc.add(vdesc);
+               visibleDesc.add(vdesc);
+       }
 
        if (autocomplete)
                return true;
@@ -323,7 +322,7 @@ void CLICommand::ShowCommands(int argc, char **argv, po::options_description *vi
                } else if (autoindex - 1 >= 0 && argv[autoindex - 1][0] == '-' && argv[autoindex - 1][1] != '-') {
                        aname = argv[autoindex - 1];
                        pword = aword;
-                       
+
                        if (pword == "=")
                                pword = "";
                } else if (aword.GetLength() > 1 && aword[0] == '-' && aword[1] != '-') {
@@ -349,7 +348,7 @@ void CLICommand::ShowCommands(int argc, char **argv, po::options_description *vi
                BOOST_FOREACH(const String& suggestion, command->GetArgumentSuggestions(odesc->long_name(), pword)) {
                        std::cout << prefix << suggestion << "\n";
                }
-               
+
                return;
 
 complete_option: