]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c
Updates the logic to allow help to ouput help information from a dynamic shell command
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Help.c
index cd03ff7f07f2cae6fda7186fb6f3b7c52421ddd5..a5dfade8f11826b4afa21004c9b60cec4d583c57 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for Help shell level 3 function.\r
 \r
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 #include "UefiShellLevel3CommandsLib.h"\r
 \r
 #include <Library/ShellLib.h>\r
+#include <Library/HandleParsingLib.h>\r
+\r
+#include <Protocol/EfiShellDynamicCommand.h>\r
+\r
+/**\r
+  Attempt to print help from a dynamically added command.\r
+\r
+  @param[in]  CommandToGetHelpOn  The unicode name of the command that help is requested on.\r
+\r
+  @retval EFI_SUCCESS             The help was displayed\r
+  @retval FI_NOT_FOUND            The command name could not be found\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+PrintDynamicCommandHelp(\r
+  IN  CHAR16 *CommandToGetHelpOn\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  BOOLEAN                             Found = FALSE;\r
+  EFI_HANDLE                          *CommandHandleList = NULL;\r
+  EFI_HANDLE                          *NextCommand;\r
+  EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *DynamicCommand;\r
+  CHAR16                              *OutText = NULL;\r
+\r
+  CommandHandleList = GetHandleListByProtocol(&gEfiShellDynamicCommandProtocolGuid);\r
+\r
+  if (CommandHandleList == NULL) {\r
+    //\r
+    // not found or out of resources\r
+    //\r
+    return FALSE;\r
+  }\r
+\r
+  for (NextCommand = CommandHandleList; *NextCommand != NULL; NextCommand++) {\r
+    Status = gBS->HandleProtocol(\r
+      *NextCommand,\r
+      &gEfiShellDynamicCommandProtocolGuid,\r
+      (VOID **)&DynamicCommand\r
+      );\r
+\r
+    if (EFI_ERROR(Status)) {\r
+      continue;\r
+    }\r
+\r
+    if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, (CHAR16 *)DynamicCommand->CommandName, CommandToGetHelpOn)) ||\r
+      (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, (CHAR16 *)DynamicCommand->CommandName, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {\r
+      //\r
+      // TODO: how to get proper language?\r
+      //\r
+      OutText = DynamicCommand->GetHelp(DynamicCommand, "en");\r
+\r
+      if (OutText == NULL) {\r
+        continue;\r
+      }\r
+\r
+      //\r
+      // Trim extra characters from the end the the string before printing\r
+      //\r
+      while (StrLen(OutText) > 0 \r
+        && (OutText[StrLen(OutText) - 1] == L'\r' || OutText[StrLen(OutText) - 1] == L'\n' || OutText[StrLen(OutText) - 1] == L' ')) {\r
+        OutText[StrLen(OutText) - 1] = CHAR_NULL;\r
+      }\r
+\r
+      //\r
+      // Make sure we have something to print still.\r
+      //\r
+      if (StrLen(OutText) == 0) {\r
+        FreePool(OutText);\r
+        OutText = NULL;\r
+        continue;\r
+      }\r
+\r
+      //\r
+      // Print and move on.\r
+      //\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_HELP_COMMAND), gShellLevel3HiiHandle, DynamicCommand->CommandName, OutText);\r
+      FreePool(OutText);\r
+      OutText = NULL;\r
+      Found = TRUE;\r
+      break;\r
+    }\r
+\r
+  }\r
+\r
+  FreePool(CommandHandleList);\r
+\r
+  return Found ? EFI_SUCCESS : EFI_NOT_FOUND;\r
+}\r
 \r
 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
   {L"-usage", TypeFlag},\r
@@ -168,15 +258,24 @@ ShellCommandRunHelp (
         // Search the .man file for Shell applications (Shell external commands).\r
         //\r
         if (!Found) {\r
-            Status = ShellPrintHelp(CommandToGetHelpOn, SectionToGetHelpOn, FALSE);\r
-            if (Status == EFI_DEVICE_ERROR) {\r
-               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, CommandToGetHelpOn);\r
-            } else if (EFI_ERROR(Status)) {\r
-               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);\r
-            } else {\r
-              Found = TRUE;\r
-            }\r
+          Status = ShellPrintHelp(CommandToGetHelpOn, SectionToGetHelpOn, FALSE);\r
+          if (Status == EFI_DEVICE_ERROR) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, CommandToGetHelpOn);\r
+          } else if (EFI_ERROR(Status)) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);\r
+          } else {\r
+            Found = TRUE;\r
+          }\r
+        }\r
+\r
+        //\r
+        // now try to match against the dynamic command list and print help\r
+        //\r
+        Status = PrintDynamicCommandHelp(CommandToGetHelpOn);\r
+        if (Status == EFI_SUCCESS) {\r
+          Found = TRUE;\r
         }\r
+        \r
       }\r
 \r
       if (!Found) {\r
@@ -206,4 +305,3 @@ ShellCommandRunHelp (
 \r
   return (ShellStatus);\r
 }\r
-\r