]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Updates the logic to allow help to ouput help information from a dynamic shell command
authorJaben Carsey <jaben.carsey@intel.com>
Tue, 5 Aug 2014 20:56:07 +0000 (20:56 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 5 Aug 2014 20:56:07 +0000 (20:56 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Lee Rosenbaum <lee.g.rosenbaum@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15756 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c
ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf

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
index 7316750fd84d6328d57f6045cc85804de8a01f22..79a4060833da71798d6b5011da2e4dac2ccf7631 100644 (file)
@@ -3,7 +3,7 @@
 # Note that the interactive versions of the time, date, and timezone functions are handled in the level 2 library.\r
 #\r
 # Copyright (c) 2013, Hewlett-Packard Development Company, L.P.\r
-# Copyright (c) 2009-2011, Intel Corporation. All rights reserved. <BR>\r
+# Copyright (c) 2009-2014, Intel Corporation. All rights reserved. <BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -59,6 +59,7 @@
   PcdLib\r
   HiiLib\r
   FileHandleLib\r
+  HandleParsingLib\r
 \r
 [Guids]\r
   gEfiFileInfoGuid\r
@@ -69,3 +70,5 @@
   gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize\r
   gEfiShellPkgTokenSpaceGuid.PcdShellSupplier\r
 \r
+[Protocols]\r
+  gEfiShellDynamicCommandProtocolGuid                     # SOMETIMES_CONSUMED\r