From df083521484e2d16970312a1dc9a53f0747883eb Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 18 Aug 2014 12:29:21 +0200 Subject: [PATCH] Revise *controlpanel help output Make the output easier to read by wrapping mandatory argument names with angle brackets (just like in *status help), and make it possible to output help for given command(s). Furthermore, output only relevant variable lists and align casing & arguments in general help & command specific usage output. --- modules/controlpanel.cpp | 273 +++++++++++++++++++++------------------ src/Modules.cpp | 2 +- 2 files changed, 149 insertions(+), 126 deletions(-) diff --git a/modules/controlpanel.cpp b/modules/controlpanel.cpp index f084518b..de6e138a 100644 --- a/modules/controlpanel.cpp +++ b/modules/controlpanel.cpp @@ -40,100 +40,123 @@ static array_size_helper array_size(T (&)[N]) { class CAdminMod : public CModule { using CModule::PutModule; - void PrintHelp(const CString&) { - HandleHelpCommand(); + void PrintHelp(const CString& sLine) { + HandleHelpCommand(sLine); - PutModule("The following variables are available when using the Set/Get commands:"); - - CTable VarTable; - VarTable.AddColumn("Variable"); - VarTable.AddColumn("Type"); static const char* str = "String"; static const char* boolean = "Boolean (true/false)"; static const char* integer = "Integer"; static const char* doublenum = "Double"; - static const char* vars[][2] = { - {"Nick", str}, - {"Altnick", str}, - {"Ident", str}, - {"RealName", str}, - {"BindHost", str}, - {"MultiClients", boolean}, - {"DenyLoadMod", boolean}, - {"DenySetBindHost", boolean}, - {"DefaultChanModes", str}, - {"QuitMsg", str}, - {"BufferCount", integer}, - {"AutoClearChanBuffer", boolean}, - {"AutoClearQueryBuffer",boolean}, - {"Password", str}, - {"JoinTries", integer}, - {"MaxJoins", integer}, - {"MaxNetworks", integer}, - {"MaxQueryBuffers", integer}, - {"Timezone", str}, - {"Admin", boolean}, - {"AppendTimestamp", boolean}, - {"PrependTimestamp", boolean}, - {"TimestampFormat", str}, - {"DCCBindHost", str}, - {"StatusPrefix", str}, + + const CString sCmdFilter = sLine.Token(1, false); + const CString::size_type iCmdLength = sCmdFilter.size(); + + const CString sVarFilter = sLine.Token(2, true); + const CString::size_type iVarLength = sVarFilter.size(); + + if (sCmdFilter.empty() || sCmdFilter.Equals("Set", false, iCmdLength) || sCmdFilter.Equals("Get", false, iCmdLength)) { + CTable VarTable; + VarTable.AddColumn("Variable"); + VarTable.AddColumn("Type"); + static const char* vars[][2] = { + {"Nick", str}, + {"Altnick", str}, + {"Ident", str}, + {"RealName", str}, + {"BindHost", str}, + {"MultiClients", boolean}, + {"DenyLoadMod", boolean}, + {"DenySetBindHost", boolean}, + {"DefaultChanModes", str}, + {"QuitMsg", str}, + {"BufferCount", integer}, + {"AutoClearChanBuffer", boolean}, + {"AutoClearQueryBuffer",boolean}, + {"Password", str}, + {"JoinTries", integer}, + {"MaxJoins", integer}, + {"MaxNetworks", integer}, + {"MaxQueryBuffers", integer}, + {"Timezone", str}, + {"Admin", boolean}, + {"AppendTimestamp", boolean}, + {"PrependTimestamp", boolean}, + {"TimestampFormat", str}, + {"DCCBindHost", str}, + {"StatusPrefix", str}, #ifdef HAVE_ICU - {"ClientEncoding", str}, + {"ClientEncoding", str}, #endif - }; - for (unsigned int i = 0; i != ARRAY_SIZE(vars); ++i) { - VarTable.AddRow(); - VarTable.SetCell("Variable", vars[i][0]); - VarTable.SetCell("Type", vars[i][1]); + }; + for (unsigned int i = 0; i != ARRAY_SIZE(vars); ++i) { + if (sVarFilter.empty() || sVarFilter.Equals(vars[i][0], false, iVarLength)) { + VarTable.AddRow(); + VarTable.SetCell("Variable", vars[i][0]); + VarTable.SetCell("Type", vars[i][1]); + } + } + if (!VarTable.empty()) { + PutModule("The following variables are available when using the Set/Get commands:"); + PutModule(VarTable); + } } - PutModule(VarTable); - PutModule("The following variables are available when using the SetNetwork/GetNetwork commands:"); - - CTable NVarTable; - NVarTable.AddColumn("Variable"); - NVarTable.AddColumn("Type"); - static const char* nvars[][2] = { - {"Nick", str}, - {"Altnick", str}, - {"Ident", str}, - {"RealName", str}, - {"BindHost", str}, - {"FloodRate", doublenum}, - {"FloodBurst", integer}, + if (sCmdFilter.empty() || sCmdFilter.Equals("SetNetwork", false, iCmdLength) || sCmdFilter.Equals("GetNetwork", false, iCmdLength)) { + CTable NVarTable; + NVarTable.AddColumn("Variable"); + NVarTable.AddColumn("Type"); + static const char* nvars[][2] = { + {"Nick", str}, + {"Altnick", str}, + {"Ident", str}, + {"RealName", str}, + {"BindHost", str}, + {"FloodRate", doublenum}, + {"FloodBurst", integer}, #ifdef HAVE_ICU - {"Encoding", str}, + {"Encoding", str}, #endif - }; - for (unsigned int i = 0; i != ARRAY_SIZE(nvars); ++i) { - NVarTable.AddRow(); - NVarTable.SetCell("Variable", nvars[i][0]); - NVarTable.SetCell("Type", nvars[i][1]); + }; + for (unsigned int i = 0; i != ARRAY_SIZE(nvars); ++i) { + if (sVarFilter.empty() || sVarFilter.Equals(nvars[i][0], false, iVarLength)) { + NVarTable.AddRow(); + NVarTable.SetCell("Variable", nvars[i][0]); + NVarTable.SetCell("Type", nvars[i][1]); + } + } + if (!NVarTable.empty()) { + PutModule("The following variables are available when using the SetNetwork/GetNetwork commands:"); + PutModule(NVarTable); + } } - PutModule(NVarTable); - - PutModule("The following variables are available when using the SetChan/GetChan commands:"); - CTable CVarTable; - CVarTable.AddColumn("Variable"); - CVarTable.AddColumn("Type"); - static const char* cvars[][2] = { - {"DefModes", str}, - {"Key", str}, - {"Buffer", integer}, - {"InConfig", boolean}, - {"AutoClearChanBuffer", boolean}, - {"Detached", boolean} - }; - for (unsigned int i = 0; i != ARRAY_SIZE(cvars); ++i) { - CVarTable.AddRow(); - CVarTable.SetCell("Variable", cvars[i][0]); - CVarTable.SetCell("Type", cvars[i][1]); + if (sCmdFilter.empty() || sCmdFilter.Equals("SetChan", false, iCmdLength) || sCmdFilter.Equals("GetChan", false, iCmdLength)) { + CTable CVarTable; + CVarTable.AddColumn("Variable"); + CVarTable.AddColumn("Type"); + static const char* cvars[][2] = { + {"DefModes", str}, + {"Key", str}, + {"Buffer", integer}, + {"InConfig", boolean}, + {"AutoClearChanBuffer", boolean}, + {"Detached", boolean} + }; + for (unsigned int i = 0; i != ARRAY_SIZE(cvars); ++i) { + if (sVarFilter.empty() || sVarFilter.Equals(cvars[i][0], false, iVarLength)) { + CVarTable.AddRow(); + CVarTable.SetCell("Variable", cvars[i][0]); + CVarTable.SetCell("Type", cvars[i][1]); + } + } + if (!CVarTable.empty()) { + PutModule("The following variables are available when using the SetChan/GetChan commands:"); + PutModule(CVarTable); + } } - PutModule(CVarTable); - PutModule("You can use $me as the user name for modifying your own user."); + if (sCmdFilter.empty()) + PutModule("You can use $me as the user name for modifying your own user."); } CUser* GetUser(const CString& sUsername) { @@ -157,7 +180,7 @@ class CAdminMod : public CModule { CUser* pUser; if (sVar.empty()) { - PutModule("Usage: get [username]"); + PutModule("Usage: Get [username]"); return; } @@ -234,7 +257,7 @@ class CAdminMod : public CModule { CString sValue = sLine.Token(3, true); if (sValue.empty()) { - PutModule("Usage: set "); + PutModule("Usage: Set "); return; } @@ -574,7 +597,7 @@ class CAdminMod : public CModule { const CString sChan = sLine.Token(3); if (sChan.empty()) { - PutModule("Usage: addchan "); + PutModule("Usage: AddChan "); return; } @@ -606,7 +629,7 @@ class CAdminMod : public CModule { const CString sChan = sLine.Token(3); if (sChan.empty()) { - PutModule("Usage: delchan "); + PutModule("Usage: DelChan "); return; } @@ -644,7 +667,7 @@ class CAdminMod : public CModule { CString sChan = sLine.Token(4, true); if (sChan.empty()) { - PutModule("Usage: getchan "); + PutModule("Usage: GetChan "); return; } @@ -690,7 +713,7 @@ class CAdminMod : public CModule { CString sValue = sLine.Token(5, true); if (sValue.empty()) { - PutModule("Usage: setchan "); + PutModule("Usage: SetChan "); return; } @@ -791,7 +814,7 @@ class CAdminMod : public CModule { sUsername = sLine.Token(1), sPassword = sLine.Token(2); if (sPassword.empty()) { - PutModule("Usage: adduser "); + PutModule("Usage: AddUser "); return; } @@ -823,7 +846,7 @@ class CAdminMod : public CModule { const CString sUsername = sLine.Token(1, true); if (sUsername.empty()) { - PutModule("Usage: deluser "); + PutModule("Usage: DelUser "); return; } @@ -860,7 +883,7 @@ class CAdminMod : public CModule { sNewUsername = sLine.Token(2, true); if (sOldUsername.empty() || sNewUsername.empty()) { - PutModule("Usage: cloneuser "); + PutModule("Usage: CloneUser "); return; } @@ -905,7 +928,7 @@ class CAdminMod : public CModule { } if (sNetwork.empty()) { - PutModule("Usage: " + sLine.Token(0) + " [user] network"); + PutModule("Usage: AddNetwork [user] network"); return; } @@ -942,7 +965,7 @@ class CAdminMod : public CModule { } if (sNetwork.empty()) { - PutModule("Usage: " + sLine.Token(0) + " [user] network"); + PutModule("Usage: DelNetwork [user] network"); return; } @@ -1010,7 +1033,7 @@ class CAdminMod : public CModule { CString sServer = sLine.Token(3, true); if (sServer.empty()) { - PutModule("Usage: addserver "); + PutModule("Usage: AddServer "); return; } @@ -1201,7 +1224,7 @@ class CAdminMod : public CModule { CString sArgs = sLine.Token(3, true); if (sModName.empty()) { - PutModule("Usage: loadmodule []"); + PutModule("Usage: LoadModule [args]"); return; } @@ -1219,7 +1242,7 @@ class CAdminMod : public CModule { CString sArgs = sLine.Token(4, true); if (sModName.empty()) { - PutModule("Usage: loadnetmodule []"); + PutModule("Usage: LoadNetModule [args]"); return; } @@ -1260,7 +1283,7 @@ class CAdminMod : public CModule { CString sModName = sLine.Token(2); if (sModName.empty()) { - PutModule("Usage: unloadmodule "); + PutModule("Usage: UnloadModule "); return; } @@ -1277,7 +1300,7 @@ class CAdminMod : public CModule { CString sModName = sLine.Token(3); if (sModName.empty()) { - PutModule("Usage: unloadnetmodule "); + PutModule("Usage: UnloadNetModule "); return; } @@ -1317,7 +1340,7 @@ class CAdminMod : public CModule { CString sUsername = sLine.Token(1); if (sUsername.empty()) { - PutModule("Usage: listmods "); + PutModule("Usage: ListMods "); return; } @@ -1333,7 +1356,7 @@ class CAdminMod : public CModule { CString sNetwork = sLine.Token(2); if (sNetwork.empty()) { - PutModule("Usage: listnetmods "); + PutModule("Usage: ListNetMods "); return; } @@ -1353,63 +1376,63 @@ class CAdminMod : public CModule { public: MODCONSTRUCTOR(CAdminMod) { AddCommand("Help", static_cast(&CAdminMod::PrintHelp), - "", "Generates this output"); + "[command] [variable]", "Prints help for matching commands and variables"); AddCommand("Get", static_cast(&CAdminMod::Get), - "variable [username]", "Prints the variable's value for the given or current user"); + " [username]", "Prints the variable's value for the given or current user"); AddCommand("Set", static_cast(&CAdminMod::Set), - "variable username value", "Sets the variable's value for the given user (use $me for the current user)"); + " ", "Sets the variable's value for the given user (use $me for the current user)"); AddCommand("GetNetwork", static_cast(&CAdminMod::GetNetwork), - "variable [username network]", "Prints the variable's value for the given network"); + " [username] [network]", "Prints the variable's value for the given network"); AddCommand("SetNetwork", static_cast(&CAdminMod::SetNetwork), - "variable username network value", "Sets the variable's value for the given network"); + " ", "Sets the variable's value for the given network"); AddCommand("GetChan", static_cast(&CAdminMod::GetChan), - "variable [username] network chan", "Prints the variable's value for the given channel"); + " [username] ", "Prints the variable's value for the given channel"); AddCommand("SetChan", static_cast(&CAdminMod::SetChan), - "variable username network chan value", "Sets the variable's value for the given channel"); + " ", "Sets the variable's value for the given channel"); AddCommand("AddChan", static_cast(&CAdminMod::AddChan), - "username network chan", "Adds a new channel"); + " ", "Adds a new channel"); AddCommand("DelChan", static_cast(&CAdminMod::DelChan), - "username network chan", "Deletes a channel"); + " ", "Deletes a channel"); AddCommand("ListUsers", static_cast(&CAdminMod::ListUsers), - "", "Lists users"); + "", "Lists users"); AddCommand("AddUser", static_cast(&CAdminMod::AddUser), - "username password", "Adds a new user"); + " ", "Adds a new user"); AddCommand("DelUser", static_cast(&CAdminMod::DelUser), - "username", "Deletes a user"); + "", "Deletes a user"); AddCommand("CloneUser", static_cast(&CAdminMod::CloneUser), - "oldusername newusername", "Clones a user"); + " ", "Clones a user"); AddCommand("AddServer", static_cast(&CAdminMod::AddServer), - "username network server", "Adds a new IRC server for the given or current user"); + " ", "Adds a new IRC server for the given or current user"); AddCommand("Reconnect", static_cast(&CAdminMod::ReconnectUser), - "username network", "Cycles the user's IRC server connection"); + " ", "Cycles the user's IRC server connection"); AddCommand("Disconnect", static_cast(&CAdminMod::DisconnectUser), - "username network", "Disconnects the user from their IRC server"); + " ", "Disconnects the user from their IRC server"); AddCommand("LoadModule", static_cast(&CAdminMod::LoadModuleForUser), - "username modulename [args]", "Loads a Module for a user"); + " [args]", "Loads a Module for a user"); AddCommand("UnLoadModule", static_cast(&CAdminMod::UnLoadModuleForUser), - "username modulename", "Removes a Module of a user"); + " ", "Removes a Module of a user"); AddCommand("ListMods", static_cast(&CAdminMod::ListModulesForUser), - "username", "Get the list of modules for a user"); + "", "Get the list of modules for a user"); AddCommand("LoadNetModule",static_cast(&CAdminMod::LoadModuleForNetwork), - "username network modulename [args]", "Loads a Module for a network"); + " [args]", "Loads a Module for a network"); AddCommand("UnLoadNetModule",static_cast(&CAdminMod::UnLoadModuleForNetwork), - "username network modulename", "Removes a Module of a network"); + " ", "Removes a Module of a network"); AddCommand("ListNetMods", static_cast(&CAdminMod::ListModulesForNetwork), - "username network", "Get the list of modules for a network"); + " ", "Get the list of modules for a network"); AddCommand("ListCTCPs", static_cast(&CAdminMod::ListCTCP), - "username", "List the configured CTCP replies"); + "", "List the configured CTCP replies"); AddCommand("AddCTCP", static_cast(&CAdminMod::AddCTCP), - "username ctcp [reply]", "Configure a new CTCP reply"); + " [reply]", "Configure a new CTCP reply"); AddCommand("DelCTCP", static_cast(&CAdminMod::DelCTCP), - "username ctcp", "Remove a CTCP reply"); + " ", "Remove a CTCP reply"); // Network commands AddCommand("AddNetwork", static_cast(&CAdminMod::AddNetwork), - "[username] network", "Add a network for a user"); + "[username] ", "Add a network for a user"); AddCommand("DelNetwork", static_cast(&CAdminMod::DelNetwork), - "[username] network", "Delete a network for a user"); + "[username] ", "Delete a network for a user"); AddCommand("ListNetworks", static_cast(&CAdminMod::ListNetworks), - "[username]", "List all networks for a user"); + "[username]", "List all networks for a user"); } virtual ~CAdminMod() {} diff --git a/src/Modules.cpp b/src/Modules.cpp index 90e92473..fe8d1f36 100644 --- a/src/Modules.cpp +++ b/src/Modules.cpp @@ -554,7 +554,7 @@ bool CModule::HandleCommand(const CString& sLine) { } void CModule::HandleHelpCommand(const CString& sLine) { - CString sFilter = sLine.Token(1, true); + CString sFilter = sLine.Token(1); CString::size_type iFilterLength = sFilter.size(); CTable Table; map::const_iterator it;