1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org>
2
3 #include "help.h"
4
5 #include "estringlist.h"
6
7 #include <stdio.h>
8
9
10 /*! \class Help help.h
11 This class handles the "aox help" command.
12 */
13
Help(EStringList * args)14 Help::Help( EStringList * args )
15 : AoxCommand( args )
16 {
17 execute();
18 }
19
20
21 static AoxFactory<Help>
22 f( "help", "", "Offer help on commands and more",
23 " Synopsis: aox help ...\n\n"
24 " Displays a brief help text on any aox command.\n"
25 " Examples: aox help, aox help show, aox help show counts,\n"
26 " aox help allcommands.\n"
27 " More verbose help is available in the aox manpage and at aox.org/aox/,\n"
28 " e.g. aox.org/aox/showcounts for aox show counts." );
29
30
execute()31 void Help::execute()
32 {
33 EString a = next().lower();
34
35 EString b;
36 if ( AoxCommandMap::needsNoun( a ) )
37 b = next().lower();
38
39 EString about = AoxCommandMap::aboutCommand( a, b );
40 if ( !about.isEmpty() ) {
41 printf( "aox %s %s -- %s\n%s",
42 a.cstr(), b.cstr(), AoxCommandMap::inBrief( a, b ).cstr(),
43 about.cstr() );
44 }
45 else if ( AoxCommandMap::validVerbs()->contains( a ) ) {
46 printf( "aox %s: Valid arguments:\n", a.cstr() );
47 EStringList::Iterator i( AoxCommandMap::validNouns( a ) );
48 while ( i ) {
49 printf( " %s -- %s\n",
50 i->cstr(), AoxCommandMap::inBrief( a, *i ).cstr() );
51 ++i;
52 }
53 }
54 else if ( a == "commands" || a.isEmpty() ) {
55 printf(
56 "aox: Command summary:\n"
57 " Server management:\n"
58 " start\n"
59 " stop\n"
60 " restart\n"
61 " show status\n"
62 "\n"
63 " Configuration:\n"
64 " check config\n"
65 " show build\n"
66 " show configuration\n"
67 " tune database\n"
68 "\n"
69 " Administration:\n"
70 " list <users|mailboxes|aliases|rights>\n"
71 " add <user|mailbox|alias>\n"
72 " delete <user|mailbox|alias>\n"
73 " change <username|password|address>\n"
74 " setacl\n"
75 "\n"
76 " Other:\n"
77 " show queue\n"
78 " undelete\n"
79 " vacuum\n"
80 " ...\n"
81 "\n"
82 " Use \"aox help <command name>\" for more specific help,\n"
83 " \"aox help allcommands\" for a complete list of commands or\n"
84 " e.g. \"aox help show\" for a list of arguments to show.\n"
85 );
86 }
87 else if ( a == "allcommands" ) {
88 printf( "aox: Valid commands:\n" );
89 EStringList::Iterator v( AoxCommandMap::validVerbs() );
90 while ( v ) {
91 EStringList::Iterator n( AoxCommandMap::validNouns( *v ) );
92 while ( n ) {
93 printf( " %s %s -- %s\n",
94 v->cstr(), n->cstr(),
95 AoxCommandMap::inBrief( *v, *n ).cstr() );
96 ++n;
97 }
98 ++v;
99 }
100 }
101 else if ( a == "aliases" ) {
102 printf( "aox: Valid Aliases:\n %s\n",
103 AoxCommandMap::aliases()->join( "\n " ).cstr() );
104 }
105 else {
106 printf( "aox %s: Invalid command.\n Valid commands:\n%s\n",
107 a.cstr(),
108 AoxCommandMap::validVerbs()->join( ", " )
109 .wrapped( 70, " ", " ", false ).cstr() );
110 }
111
112 finish();
113 }
114