Merge of Fredrik Hultin command_line
[people/xl0/gpxe.git] / src / commandline / commands / help.c
1 #include "command.h"
2 #include "console.h"
3 #include <string.h>
4 #include <gpxe/tables.h>
5
6 static struct command cmd_start[0] __table_start ( commands );
7 static struct command cmd_end[0] __table_end ( commands );
8
9 void help_req(){}
10
11 static int cmd_help_exec ( int argc, char **argv ) {
12
13         struct command *ccmd;
14         int unknown = 1;
15         if(argc == 1){
16                 printf("Built in commands:\n\n\texit, quit\t\tExit the command line and boot\n\nCompiled in commands:\n\n");
17
18                 for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) {
19                         printf ("\t%s\t\t%s\n", ccmd->name, ccmd->desc );
20                 }
21         }else{
22                 if(!strcmp(argv[1], "exit") || !strcmp(argv[1], "quit")){
23                         printf("exit, quit - The quit command\n\nUsage:\nquit or exit\n\n\tExample:\n\t\texit\n");
24                 }else{
25                         for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) {
26                                 if(!strcmp(ccmd->name, argv[1])){
27                                         unknown = 0;
28                                         printf ("\t%s - %s\n\nUsage:\n%s\n", ccmd->name, ccmd->desc, ccmd->usage );
29                                         break;
30                                 }
31                         }
32                         if(unknown){
33                                 printf("\"%s\" isn't compiled in (does it exist?).\n", argv[1]);
34                         }
35                 }
36                 
37         }
38         return 0;
39 }
40
41 struct command help_command __command = {
42         .name = "help",
43         .usage = "help <command>\n\n\tExample:\n\t\thelp help\n",
44         .desc = "The help command",
45         .exec = cmd_help_exec,
46 };
47
48