2 Main file for Help shell level 3 function.
4 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. <BR>
5 Copyright (c) 2014, ARM Limited. All rights reserved. <BR>
6 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "UefiShellLevel3CommandsLib.h"
20 #include <Library/ShellLib.h>
21 #include <Library/HandleParsingLib.h>
23 #include <Protocol/EfiShellDynamicCommand.h>
26 Attempt to print help from a dynamically added command.
28 @param[in] CommandToGetHelpOn The unicode name of the command that help is
30 @param[in] SectionToGetHelpOn Pointer to the section specifier(s).
31 @param[in] PrintCommandText Print the command followed by the help content
34 @retval EFI_SUCCESS The help was displayed
35 @retval EFI_NOT_FOUND The command name could not be found
36 @retval EFI_DEVICE_ERROR The help data format was incorrect.
40 PrintDynamicCommandHelp(
41 IN CHAR16
*CommandToGetHelpOn
,
42 IN CHAR16
*SectionToGetHelpOn
,
43 IN BOOLEAN PrintCommandText
48 EFI_HANDLE
*CommandHandleList
;
49 EFI_HANDLE
*NextCommand
;
50 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*DynamicCommand
;
52 Status
= EFI_NOT_FOUND
;
54 CommandHandleList
= NULL
;
56 CommandHandleList
= GetHandleListByProtocol(&gEfiShellDynamicCommandProtocolGuid
);
58 if (CommandHandleList
== NULL
) {
60 // not found or out of resources
65 for (NextCommand
= CommandHandleList
; *NextCommand
!= NULL
; NextCommand
++) {
66 Status
= gBS
->HandleProtocol(
68 &gEfiShellDynamicCommandProtocolGuid
,
69 (VOID
**)&DynamicCommand
72 if (EFI_ERROR(Status
)) {
77 // Check execution break flag when printing multiple command help information.
79 if (ShellGetExecutionBreakFlag ()) {
83 if ((gUnicodeCollation
->MetaiMatch (gUnicodeCollation
, (CHAR16
*)DynamicCommand
->CommandName
, CommandToGetHelpOn
)) ||
84 (gEfiShellProtocol
->GetAlias (CommandToGetHelpOn
, NULL
) != NULL
&& (gUnicodeCollation
->MetaiMatch (gUnicodeCollation
, (CHAR16
*)DynamicCommand
->CommandName
, (CHAR16
*)(gEfiShellProtocol
->GetAlias(CommandToGetHelpOn
, NULL
)))))) {
85 // Print as Shell Help if in ManPage format.
86 Status
= ShellPrintHelp (DynamicCommand
->CommandName
, SectionToGetHelpOn
,
88 if (Status
== EFI_DEVICE_ERROR
) {
89 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HELP_INV
),
90 gShellLevel3HiiHandle
, DynamicCommand
->CommandName
);
91 } else if (EFI_ERROR(Status
)) {
92 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HELP_NF
),
93 gShellLevel3HiiHandle
, DynamicCommand
->CommandName
);
100 SHELL_FREE_NON_NULL(CommandHandleList
);
102 return (Found
? EFI_SUCCESS
: Status
);
106 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
107 {L
"-usage", TypeFlag
},
108 {L
"-section", TypeMaxValue
},
109 {L
"-verbose", TypeFlag
},
115 Function for 'help' command.
117 @param[in] ImageHandle Handle to the Image (NULL if Internal).
118 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
122 ShellCommandRunHelp (
123 IN EFI_HANDLE ImageHandle
,
124 IN EFI_SYSTEM_TABLE
*SystemTable
129 CHAR16
*ProblemParam
;
130 SHELL_STATUS ShellStatus
;
131 CONST COMMAND_LIST
*CommandList
;
132 CONST COMMAND_LIST
*Node
;
133 CHAR16
*CommandToGetHelpOn
;
134 CHAR16
*SectionToGetHelpOn
;
137 BOOLEAN PrintCommandText
;
139 PrintCommandText
= TRUE
;
141 ShellStatus
= SHELL_SUCCESS
;
142 CommandToGetHelpOn
= NULL
;
143 SectionToGetHelpOn
= NULL
;
147 // initialize the shell lib (we must be in non-auto-init...)
149 Status
= ShellInitialize();
150 ASSERT_EFI_ERROR(Status
);
152 Status
= CommandInit();
153 ASSERT_EFI_ERROR(Status
);
156 // parse the command line
158 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
159 if (EFI_ERROR(Status
)) {
160 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
161 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel3HiiHandle
, L
"help", ProblemParam
);
162 FreePool(ProblemParam
);
163 ShellStatus
= SHELL_INVALID_PARAMETER
;
169 // Check for conflicting parameters.
171 if (ShellCommandLineGetFlag(Package
, L
"-usage")
172 &&ShellCommandLineGetFlag(Package
, L
"-section")
173 &&(ShellCommandLineGetFlag(Package
, L
"-verbose") || ShellCommandLineGetFlag(Package
, L
"-v"))
175 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel3HiiHandle
, L
"help");
176 ShellStatus
= SHELL_INVALID_PARAMETER
;
177 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
178 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
, L
"help");
179 ShellStatus
= SHELL_INVALID_PARAMETER
;
182 // Get the command name we are getting help on
184 ASSERT(CommandToGetHelpOn
== NULL
);
185 StrnCatGrow(&CommandToGetHelpOn
, NULL
, ShellCommandLineGetRawValue(Package
, 1), 0);
186 if (CommandToGetHelpOn
== NULL
&& ShellCommandLineGetFlag(Package
, L
"-?")) {
188 // If we dont have a command and we got a simple -?
189 // we are looking for help on help command.
191 StrnCatGrow(&CommandToGetHelpOn
, NULL
, L
"help", 0);
194 if (CommandToGetHelpOn
== NULL
) {
195 StrnCatGrow(&CommandToGetHelpOn
, NULL
, L
"*", 0);
196 ASSERT(SectionToGetHelpOn
== NULL
);
197 StrnCatGrow(&SectionToGetHelpOn
, NULL
, L
"NAME", 0);
199 PrintCommandText
= FALSE
;
200 ASSERT(SectionToGetHelpOn
== NULL
);
202 // Get the section name for the given command name
204 if (ShellCommandLineGetFlag(Package
, L
"-section")) {
205 StrnCatGrow(&SectionToGetHelpOn
, NULL
, ShellCommandLineGetValue(Package
, L
"-section"), 0);
206 } else if (ShellCommandLineGetFlag(Package
, L
"-usage")) {
207 StrnCatGrow(&SectionToGetHelpOn
, NULL
, L
"NAME,SYNOPSIS", 0);
208 } else if (ShellCommandLineGetFlag(Package
, L
"-verbose") || ShellCommandLineGetFlag(Package
, L
"-v")) {
211 // The output of help <command> will display NAME, SYNOPSIS, OPTIONS, DESCRIPTION, and EXAMPLES sections.
213 StrnCatGrow (&SectionToGetHelpOn
, NULL
, L
"NAME,SYNOPSIS,OPTIONS,DESCRIPTION,EXAMPLES", 0);
217 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, CommandToGetHelpOn
, L
"special") == 0) {
219 // we need info on the special characters
221 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_SC_HEADER
), gShellLevel3HiiHandle
);
222 HiiString
= HiiGetString(gShellLevel3HiiHandle
, STRING_TOKEN(STR_HELP_SC_DATA
), NULL
);
223 ShellPrintEx(-1, -1, L
"%s", HiiString
);
227 CommandList
= ShellCommandGetCommandList(TRUE
);
228 ASSERT(CommandList
!= NULL
);
229 for ( Node
= (COMMAND_LIST
*)GetFirstNode(&CommandList
->Link
)
230 ; CommandList
!= NULL
&& !IsListEmpty(&CommandList
->Link
) && !IsNull(&CommandList
->Link
, &Node
->Link
)
231 ; Node
= (COMMAND_LIST
*)GetNextNode(&CommandList
->Link
, &Node
->Link
)
234 // Checking execution break flag when print multiple command help information.
236 if (ShellGetExecutionBreakFlag ()) {
239 if ((gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, Node
->CommandString
, CommandToGetHelpOn
)) ||
240 (gEfiShellProtocol
->GetAlias(CommandToGetHelpOn
, NULL
) != NULL
&& (gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, Node
->CommandString
, (CHAR16
*)(gEfiShellProtocol
->GetAlias(CommandToGetHelpOn
, NULL
)))))) {
242 // We have a command to look for help on.
244 Status
= ShellPrintHelp(Node
->CommandString
, SectionToGetHelpOn
, PrintCommandText
);
245 if (Status
== EFI_DEVICE_ERROR
) {
246 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_INV
), gShellLevel3HiiHandle
, Node
->CommandString
);
247 } else if (EFI_ERROR(Status
)) {
248 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_NF
), gShellLevel3HiiHandle
, Node
->CommandString
);
256 // now try to match against the dynamic command list and print help
258 Status
= PrintDynamicCommandHelp (CommandToGetHelpOn
, SectionToGetHelpOn
,
260 if (!EFI_ERROR(Status
)) {
265 // Search the .man file for Shell applications (Shell external commands).
268 Status
= ShellPrintHelp(CommandToGetHelpOn
, SectionToGetHelpOn
, FALSE
);
269 if (Status
== EFI_DEVICE_ERROR
) {
270 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_INV
), gShellLevel3HiiHandle
, CommandToGetHelpOn
);
271 } else if (EFI_ERROR(Status
)) {
272 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_NF
), gShellLevel3HiiHandle
, CommandToGetHelpOn
);
280 ShellStatus
= SHELL_NOT_FOUND
;
284 // free the command line package
286 ShellCommandLineFreeVarList (Package
);
290 if (CommandToGetHelpOn
!= NULL
&& StrCmp(CommandToGetHelpOn
, L
"*") == 0){
292 // If '*' then the command entered was 'Help' without qualifiers, This footer
293 // provides additional info on help switches
295 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_FOOTER
), gShellLevel3HiiHandle
);
297 if (CommandToGetHelpOn
!= NULL
) {
298 FreePool(CommandToGetHelpOn
);
300 if (SectionToGetHelpOn
!= NULL
) {
301 FreePool(SectionToGetHelpOn
);
304 return (ShellStatus
);