From aec99ea213b42130997eba8838878de6f773b6a7 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 18 Aug 2014 13:54:47 +0200 Subject: [PATCH] Revise *status help output Make it possible to output help for given command(s) and align casing & arguments in general help & command specific usage output. --- include/znc/Client.h | 2 +- src/ClientCommand.cpp | 330 ++++++++++-------------------------------- 2 files changed, 79 insertions(+), 253 deletions(-) diff --git a/include/znc/Client.h b/include/znc/Client.h index 413e107b..b7aed570 100644 --- a/include/znc/Client.h +++ b/include/znc/Client.h @@ -133,7 +133,7 @@ public: virtual void ReadLine(const CString& sData); bool SendMotd(); - void HelpUser(); + void HelpUser(const CString& sFilter = ""); void AuthUser(); virtual void Connected(); virtual void Timeout(); diff --git a/src/ClientCommand.cpp b/src/ClientCommand.cpp index 3ee1e865..13fb46b9 100644 --- a/src/ClientCommand.cpp +++ b/src/ClientCommand.cpp @@ -42,7 +42,7 @@ void CClient::UserCommand(CString& sLine) { const CString sCommand = sLine.Token(0); if (sCommand.Equals("HELP")) { - HelpUser(); + HelpUser(sLine.Token(1)); } else if (sCommand.Equals("LISTNICKS")) { if (!m_pNetwork) { PutStatus("You must be connected with a network to use this command"); @@ -257,7 +257,7 @@ void CClient::UserCommand(CString& sLine) { CString sMessage = sLine.Token(1, true); if (sMessage.empty()) { - PutStatus("Usage: SetMOTD "); + PutStatus("Usage: SetMOTD "); } else { CZNC::Get().SetMotd(sMessage); PutStatus("MOTD set to [" + sMessage + "]"); @@ -266,7 +266,7 @@ void CClient::UserCommand(CString& sLine) { CString sMessage = sLine.Token(1, true); if (sMessage.empty()) { - PutStatus("Usage: AddMOTD "); + PutStatus("Usage: AddMOTD "); } else { CZNC::Get().AddMotd(sMessage); PutStatus("Added [" + sMessage + "] to MOTD"); @@ -587,7 +587,7 @@ void CClient::UserCommand(CString& sLine) { CString sNewNetwork = sLine.Token(4); if (sOldUser.empty() || sOldNetwork.empty() || sNewUser.empty()) { - PutStatus("Usage: MoveNetwork old-user old-network new-user [new-network]"); + PutStatus("Usage: MoveNetwork [new network]"); return; } if (sNewNetwork.empty()) { @@ -1553,284 +1553,110 @@ void CClient::UserPortCommand(CString& sLine) { } } -void CClient::HelpUser() { +static void AddCommandHelp(CTable& Table, const CString& sCmd, const CString& sArgs, const CString& sDesc, const CString& sFilter = "") +{ + const CString::size_type iFilterLength = sFilter.size(); + if (sFilter.empty() || sCmd.Equals(sFilter, false, iFilterLength)) { + Table.AddRow(); + Table.SetCell("Command", sCmd); + Table.SetCell("Arguments", sArgs); + Table.SetCell("Description", sDesc); + } +} + +void CClient::HelpUser(const CString& sFilter) { CTable Table; Table.AddColumn("Command"); Table.AddColumn("Arguments"); Table.AddColumn("Description"); - PutStatus("In the following list all occurrences of <#chan> support wildcards (* and ?)"); - PutStatus("(Except ListNicks)"); + if (sFilter.empty()) { + PutStatus("In the following list all occurrences of <#chan> support wildcards (* and ?)"); + PutStatus("(Except ListNicks)"); + } - Table.AddRow(); - Table.SetCell("Command", "Version"); - Table.SetCell("Description", "Print which version of ZNC this is"); - - Table.AddRow(); - Table.SetCell("Command", "ListMods"); - Table.SetCell("Description", "List all loaded modules"); - - Table.AddRow(); - Table.SetCell("Command", "ListAvailMods"); - Table.SetCell("Description", "List all available modules"); + AddCommandHelp(Table, "Version", "", "Print which version of ZNC this is", sFilter); + AddCommandHelp(Table, "ListMods", "", "List all loaded modules", sFilter); + AddCommandHelp(Table, "ListAvailMods", "", "List all available modules", sFilter); if (!m_pUser->IsAdmin()) { // If they are an admin we will add this command below with an argument - Table.AddRow(); - Table.SetCell("Command", "ListChans"); - Table.SetCell("Description", "List all channels"); + AddCommandHelp(Table, "ListChans", "", "List all channels", sFilter); } - - Table.AddRow(); - Table.SetCell("Command", "ListNicks"); - Table.SetCell("Arguments", "<#chan>"); - Table.SetCell("Description", "List all nicks on a channel"); - + AddCommandHelp(Table, "ListNicks", "<#chan>", "List all nicks on a channel", sFilter); if (!m_pUser->IsAdmin()) { - Table.AddRow(); - Table.SetCell("Command", "ListClients"); - Table.SetCell("Description", "List all clients connected to your ZNC user"); + AddCommandHelp(Table, "ListClients", "", "List all clients connected to your ZNC user", sFilter); } + AddCommandHelp(Table, "ListServers", "", "List all servers of current IRC network", sFilter); - Table.AddRow(); - Table.SetCell("Command", "ListServers"); - Table.SetCell("Description", "List all servers of current IRC network"); + AddCommandHelp(Table, "AddNetwork", "", "Add a network to your user", sFilter); + AddCommandHelp(Table, "DelNetwork", "", "Delete a network from your user", sFilter); + AddCommandHelp(Table, "ListNetworks", "", "List all networks", sFilter); + if (m_pUser->IsAdmin()) { + AddCommandHelp(Table, "MoveNetwork", " [new network]", "Move an IRC network from one user to another", sFilter); + } + AddCommandHelp(Table, "JumpNetwork", "", "Jump to another network", sFilter); - Table.AddRow(); - Table.SetCell("Command", "AddNetwork"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Add a network to your user"); + AddCommandHelp(Table, "AddServer", " [[+]port] [pass]", "Add a server to the list of alternate/backup servers of current IRC network.", sFilter); + AddCommandHelp(Table, "DelServer", " [port] [pass]", "Remove a server from the list of alternate/backup servers of current IRC network", sFilter); - Table.AddRow(); - Table.SetCell("Command", "DelNetwork"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Delete a network from your user"); + AddCommandHelp(Table, "EnableChan", "<#chan>", "Enable the channel", sFilter); + AddCommandHelp(Table, "DisableChan", "<#chan>", "Disable the channel", sFilter); + AddCommandHelp(Table, "Detach", "<#chan>", "Detach from the channel", sFilter); + AddCommandHelp(Table, "Topics", "", "Show topics in all your channels", sFilter); - Table.AddRow(); - Table.SetCell("Command", "ListNetworks"); - Table.SetCell("Description", "List all networks"); + AddCommandHelp(Table, "PlayBuffer", "<#chan|query>", "Play back the specified buffer", sFilter); + AddCommandHelp(Table, "ClearBuffer", "<#chan|query>", "Clear the specified buffer", sFilter); + AddCommandHelp(Table, "ClearAllChannelBuffers", "", "Clear the channel buffers", sFilter); + AddCommandHelp(Table, "ClearAllQueryBuffers", "", "Clear the query buffers", sFilter); + AddCommandHelp(Table, "SetBuffer", "<#chan|query> [linecount]", "Set the buffer count", sFilter); if (m_pUser->IsAdmin()) { - Table.AddRow(); - Table.SetCell("Command", "MoveNetwork"); - Table.SetCell("Arguments", "old-user old-net new-user [new-net]"); - Table.SetCell("Description", "Move an IRC network from one user to another"); - } - - Table.AddRow(); - Table.SetCell("Command", "JumpNetwork"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Jump to another network"); - - Table.AddRow(); - Table.SetCell("Command", "AddServer"); - Table.SetCell("Arguments", " [[+]port] [pass]"); - Table.SetCell("Description", "Add a server to the list of alternate/backup servers of current IRC network."); - - Table.AddRow(); - Table.SetCell("Command", "DelServer"); - Table.SetCell("Arguments", " [port] [pass]"); - Table.SetCell("Description", "Remove a server from the list of alternate/backup servers of current IRC network"); - - Table.AddRow(); - Table.SetCell("Command", "Enablechan"); - Table.SetCell("Arguments", "<#chan>"); - Table.SetCell("Description", "Enable the channel"); - - Table.AddRow(); - Table.SetCell("Command", "Disablechan"); - Table.SetCell("Arguments", "<#chan>"); - Table.SetCell("Description", "Disable the channel"); - - Table.AddRow(); - Table.SetCell("Command", "Detach"); - Table.SetCell("Arguments", "<#chan>"); - Table.SetCell("Description", "Detach from the channel"); - - Table.AddRow(); - Table.SetCell("Command", "Topics"); - Table.SetCell("Description", "Show topics in all your channels"); - - Table.AddRow(); - Table.SetCell("Command", "PlayBuffer"); - Table.SetCell("Arguments", "<#chan|query>"); - Table.SetCell("Description", "Play back the specified buffer"); - - Table.AddRow(); - Table.SetCell("Command", "ClearBuffer"); - Table.SetCell("Arguments", "<#chan|query>"); - Table.SetCell("Description", "Clear the specified buffer"); - - Table.AddRow(); - Table.SetCell("Command", "ClearAllChannelBuffers"); - Table.SetCell("Description", "Clear the channel buffers"); - - Table.AddRow(); - Table.SetCell("Command", "ClearAllQueryBuffers"); - Table.SetCell("Description", "Clear the query buffers"); - - Table.AddRow(); - Table.SetCell("Command", "SetBuffer"); - Table.SetCell("Arguments", "<#chan|query> [linecount]"); - Table.SetCell("Description", "Set the buffer count"); - - if (m_pUser->IsAdmin()) { - Table.AddRow(); - Table.SetCell("Command", "AddBindHost"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Adds a bind host for normal users to use"); - - Table.AddRow(); - Table.SetCell("Command", "DelBindHost"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Removes a bind host from the list"); + AddCommandHelp(Table, "AddBindHost", "", "Adds a bind host for normal users to use", sFilter); + AddCommandHelp(Table, "DelBindHost", "", "Removes a bind host from the list", sFilter); } if (m_pUser->IsAdmin() || !m_pUser->DenySetBindHost()) { - Table.AddRow(); - Table.SetCell("Command", "ListBindHosts"); - Table.SetCell("Description", "Shows the configured list of bind hosts"); - - Table.AddRow(); - Table.SetCell("Command", "SetBindHost"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Set the bind host for this connection"); - - Table.AddRow(); - Table.SetCell("Command", "SetUserBindHost"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Set the default bind host for this user"); - - Table.AddRow(); - Table.SetCell("Command", "ClearBindHost"); - Table.SetCell("Description", "Clear the bind host for this connection"); - - Table.AddRow(); - Table.SetCell("Command", "ClearUserBindHost"); - Table.SetCell("Description", "Clear the default bind host for this user"); + AddCommandHelp(Table, "ListBindHosts", "", "Shows the configured list of bind hosts", sFilter); + AddCommandHelp(Table, "SetBindHost", "", "Set the bind host for this connection", sFilter); + AddCommandHelp(Table, "SetUserBindHost", "", "Set the default bind host for this user", sFilter); + AddCommandHelp(Table, "ClearBindHost", "", "Clear the bind host for this connection", sFilter); + AddCommandHelp(Table, "ClearUserBindHost", "", "Clear the default bind host for this user", sFilter); } - Table.AddRow(); - Table.SetCell("Command", "ShowBindHost"); - Table.SetCell("Description", "Show currently selected bind host"); - - Table.AddRow(); - Table.SetCell("Command", "Jump [server]"); - Table.SetCell("Description", "Jump to the next or the specified server"); - - Table.AddRow(); - Table.SetCell("Command", "Disconnect"); - Table.SetCell("Arguments", "[message]"); - Table.SetCell("Description", "Disconnect from IRC"); - - Table.AddRow(); - Table.SetCell("Command", "Connect"); - Table.SetCell("Description", "Reconnect to IRC"); - - Table.AddRow(); - Table.SetCell("Command", "Uptime"); - Table.SetCell("Description", "Show for how long ZNC has been running"); + AddCommandHelp(Table, "ShowBindHost", "", "Show currently selected bind host", sFilter); + AddCommandHelp(Table, "Jump", "[server]", "Jump to the next or the specified server", sFilter); + AddCommandHelp(Table, "Disconnect", "[message]", "Disconnect from IRC", sFilter); + AddCommandHelp(Table, "Connect", "", "Reconnect to IRC", sFilter); + AddCommandHelp(Table, "Uptime", "", "Show for how long ZNC has been running", sFilter); if (!m_pUser->DenyLoadMod()) { - Table.AddRow(); - Table.SetCell("Command", "LoadMod"); - Table.SetCell("Arguments", "[--type=global|user|network] "); - Table.SetCell("Description", "Load a module"); - - Table.AddRow(); - Table.SetCell("Command", "UnloadMod"); - Table.SetCell("Arguments", "[--type=global|user|network] "); - Table.SetCell("Description", "Unload a module"); - - Table.AddRow(); - Table.SetCell("Command", "ReloadMod"); - Table.SetCell("Arguments", "[--type=global|user|network] "); - Table.SetCell("Description", "Reload a module"); - + AddCommandHelp(Table, "LoadMod", "[--type=global|user|network] ", "Load a module", sFilter); + AddCommandHelp(Table, "UnloadMod", "[--type=global|user|network] ", "Unload a module", sFilter); + AddCommandHelp(Table, "ReloadMod", "[--type=global|user|network] ", "Reload a module", sFilter); if (m_pUser->IsAdmin()) { - Table.AddRow(); - Table.SetCell("Command", "UpdateMod"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Reload a module everywhere"); + AddCommandHelp(Table, "UpdateMod", "", "Reload a module everywhere", sFilter); } } - Table.AddRow(); - Table.SetCell("Command", "ShowMOTD"); - Table.SetCell("Description", "Show ZNC's message of the day"); + AddCommandHelp(Table, "ShowMOTD", "", "Show ZNC's message of the day", sFilter); if (m_pUser->IsAdmin()) { - Table.AddRow(); - Table.SetCell("Command", "SetMOTD"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Set ZNC's message of the day"); - - Table.AddRow(); - Table.SetCell("Command", "AddMOTD"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Append to ZNC's MOTD"); - - Table.AddRow(); - Table.SetCell("Command", "ClearMOTD"); - Table.SetCell("Description", "Clear ZNC's MOTD"); - - Table.AddRow(); - Table.SetCell("Command", "ListPorts"); - Table.SetCell("Description", "Show all active listeners"); - - Table.AddRow(); - Table.SetCell("Command", "AddPort"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Add another port for ZNC to listen on"); - - Table.AddRow(); - Table.SetCell("Command", "DelPort"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Remove a port from ZNC"); - - Table.AddRow(); - Table.SetCell("Command", "Rehash"); - Table.SetCell("Description", "Reload znc.conf from disk"); - - Table.AddRow(); - Table.SetCell("Command", "SaveConfig"); - Table.SetCell("Description", "Save the current settings to disk"); - - Table.AddRow(); - Table.SetCell("Command", "ListUsers"); - Table.SetCell("Description", "List all ZNC users and their connection status"); - - Table.AddRow(); - Table.SetCell("Command", "ListAllUserNetworks"); - Table.SetCell("Description", "List all ZNC users and their networks"); - - Table.AddRow(); - Table.SetCell("Command", "ListChans"); - Table.SetCell("Arguments", "[User ]"); - Table.SetCell("Description", "List all channels"); - - Table.AddRow(); - Table.SetCell("Command", "ListClients"); - Table.SetCell("Arguments", "[User]"); - Table.SetCell("Description", "List all connected clients"); - - Table.AddRow(); - Table.SetCell("Command", "Traffic"); - Table.SetCell("Description", "Show basic traffic stats for all ZNC users"); - - Table.AddRow(); - Table.SetCell("Command", "Broadcast"); - Table.SetCell("Arguments", "[message]"); - Table.SetCell("Description", "Broadcast a message to all ZNC users"); - - Table.AddRow(); - Table.SetCell("Command", "Shutdown"); - Table.SetCell("Arguments", "[message]"); - Table.SetCell("Description", "Shut down ZNC completely"); - - Table.AddRow(); - Table.SetCell("Command", "Restart"); - Table.SetCell("Arguments", "[message]"); - Table.SetCell("Description", "Restart ZNC"); + AddCommandHelp(Table, "SetMOTD", "", "Set ZNC's message of the day", sFilter); + AddCommandHelp(Table, "AddMOTD", "", "Append to ZNC's MOTD", sFilter); + AddCommandHelp(Table, "ClearMOTD", "", "Clear ZNC's MOTD", sFilter); + AddCommandHelp(Table, "ListPorts", "", "Show all active listeners", sFilter); + AddCommandHelp(Table, "AddPort", "<[+]port> [bindhost [uriprefix]]", "Add another port for ZNC to listen on", sFilter); + AddCommandHelp(Table, "DelPort", " [bindhost]", "Remove a port from ZNC", sFilter); + AddCommandHelp(Table, "Rehash", "", "Reload znc.conf from disk", sFilter); + AddCommandHelp(Table, "SaveConfig", "", "Save the current settings to disk", sFilter); + AddCommandHelp(Table, "ListUsers", "", "List all ZNC users and their connection status", sFilter); + AddCommandHelp(Table, "ListAllUserNetworks", "", "List all ZNC users and their networks", sFilter); + AddCommandHelp(Table, "ListChans", "[user ]", "List all channels", sFilter); + AddCommandHelp(Table, "ListClients", "[user]", "List all connected clients", sFilter); + AddCommandHelp(Table, "Traffic", "", "Show basic traffic stats for all ZNC users", sFilter); + AddCommandHelp(Table, "Broadcast", "[message]", "Broadcast a message to all ZNC users", sFilter); + AddCommandHelp(Table, "Shutdown", "[message]", "Shut down ZNC completely", sFilter); + AddCommandHelp(Table, "Restart", "[message]", "Restart ZNC", sFilter); } PutStatus(Table);