public void Write(string cmdName) { Command cmd = Command.INVALID; foreach (Command testcmd in Enum.GetValues(typeof(Command))) { if (testcmd.ToString().ToLower() == cmdName.ToLower()) { cmd = testcmd; } } if (cmd == Command.INVALID || cmd == Command.NONE) { throw new UsageException(string.Format("unknown command: {0} - run 'vault.exe HELP' for help", cmdName.ToUpper())); } CommandHelpEntry he = (CommandHelpEntry)commandHelpHash[cmd]; _xml.Begin("usage"); Copyright(_xml); if (he.OptionList.Length == 0) { _xml.WriteContent(string.Format("usage: vault.exe {0} {1}", cmdName.ToUpper(), he.Usage)); } else { _xml.WriteContent(string.Format("usage: vault.exe {0} [options] {1}", cmdName.ToUpper(), he.Usage)); } _xml.WriteContent(); _xml.WriteContent(he.LongDetails); _xml.WriteContent(); if (VaultCmdLineClient.CommandNeedsAdmin(cmd)) { _xml.WriteContent("This command requires administrative privileges."); _xml.WriteContent(); } if (VaultCmdLineClient.CommandNeedsLogin(cmd)) { Option[] optionList = null; if (VaultCmdLineClient.CommandNeedsRepositorySpecified(cmd)) { optionList = new Option[] { Option.HOST, Option.SSL, Option.USER, Option.PASSWORD, Option.PROXYSERVER, Option.PROXYPORT, Option.PROXYUSER, Option.PROXYPASSWORD, Option.PROXYDOMAIN, Option.REPOSITORY }; } else { optionList = new Option[] { Option.HOST, Option.SSL, Option.USER, Option.PASSWORD, Option.PROXYSERVER, Option.PROXYPORT, Option.PROXYUSER, Option.PROXYPASSWORD, Option.PROXYDOMAIN }; } _xml.WriteContent("Server and authentication information is specified by:"); foreach (Option opt in optionList) { string optName = opt.ToString().ToLower(); OptionHelpEntry ohe = (OptionHelpEntry)optionHelpHash[opt]; if (ohe != null) { string details = ohe.Details.Replace("\n", "\n "); _xml.WriteContent(string.Format(" -{0} {1}\n {2}", optName, ohe.Usage, details)); } else { _xml.WriteContent(string.Format(" -{0}", optName)); } } _xml.WriteContent(); } if (he.OptionList.Length > 0) { _xml.WriteContent("This is a list of possible options:"); foreach (Option opt in he.OptionList) { string optName = opt.ToString().ToLower(); OptionHelpEntry ohe = (OptionHelpEntry)optionHelpHash[opt]; if (ohe != null) { string details = ohe.Details.Replace("\n", "\n "); _xml.WriteContent(string.Format(" -{0} {1}\n {2}", optName, ohe.Usage, details)); } else { _xml.WriteContent(string.Format(" -{0}", optName)); } } } _xml.End(); }
public void WriteHTML() { try { //create a new html file FileInfo fi = new FileInfo("./help.htm"); StreamWriter sw = fi.CreateText(); sw.AutoFlush = true; string heading = string.Empty; string text = string.Empty; string text1 = string.Empty; string text2 = string.Empty; heading = string.Format("<h><b>SourceGear Vault Command Line Client</b></h><br>"); heading += string.Format("<p>usage: vault commandname [options] [parameters]</p>"); heading += string.Format("<p>This is a list of possible commands:</p>"); text += ("<table cellpadding=\"5\" border=\"1\" width=\"1000\">"); text1 += ("<table cellpadding=\"5\" border=\"1\" width=\"1000\">"); foreach (Command cmd in Enum.GetValues(typeof(Command))) { if (cmd == Command.NONE || cmd == Command.INVALID) { continue; } string cmdName = cmd.ToString().ToUpper(); CommandHelpEntry he = (CommandHelpEntry)commandHelpHash[cmd]; if (he != null) { text += string.Format("<tr><td><a rel=index href=#{0}>{0}</a></tr><td>{1}</td></tr>", cmdName, he.ShortDetails); if (he.OptionList != null) { if (he.OptionList.Length == 0) { text1 += string.Format("<tr><td><a rel=index name=#{0}><b>{0}</b></tr>", cmdName); text1 += string.Format("<tr><td>usage: vault.exe {0} {1}<br>", cmdName.ToUpper(), he.Usage); text1 += string.Format("<br>{0}<br>", he.LongDetails); } else { text1 += string.Format("<tr><td><a rel=index name=#{0}><b>{0}</b></tr>", cmdName); text1 += string.Format("<tr><td>usage: vault.exe {0} [options] {1}<br>", cmdName.ToUpper(), he.Usage); text1 += string.Format("<br>{0}<br>", he.LongDetails); } } } else { text += string.Format("<tr><td><a rel=index href=#{0}>{0}</a></tr><td>{1}</td></tr>", cmdName, he.ShortDetails); } if (VaultCmdLineClient.CommandNeedsLogin(cmd)) { Option[] optionList = null; if (VaultCmdLineClient.CommandNeedsRepositorySpecified(cmd)) { optionList = new Option[] { Option.HOST, Option.SSL, Option.USER, Option.PASSWORD, Option.REPOSITORY }; } else { optionList = new Option[] { Option.HOST, Option.SSL, Option.USER, Option.PASSWORD }; } text1 += string.Format("<br>Server and authentication information is specified by:"); foreach (Option opt in optionList) { string optName = opt.ToString().ToLower(); OptionHelpEntry ohe = (OptionHelpEntry)optionHelpHash[opt]; if (ohe != null) { string details = ohe.Details.Replace("\n", "\n "); text1 += string.Format("<ul> -{0} {1}\n <ul>{2}</ul></ul>", optName, ohe.Usage, details); } else { text1 += string.Format("<ul> -{0}</ul>", optName); } } } if (he.OptionList.Length > 0) { text1 += string.Format("This is a list of possible options:<p>"); foreach (Option opt in he.OptionList) { string optName = opt.ToString().ToLower(); OptionHelpEntry ohe = (OptionHelpEntry)optionHelpHash[opt]; if (ohe != null) { string details = ohe.Details.Replace("\n", "\n "); text1 += string.Format("<ul> -{0} {1}\n <ul>{2}</ul></ul>", optName, ohe.Usage, details); } else { text1 += string.Format("<ul> -{0}<ul></td>", optName); } } } } text += ("</table>"); text1 += ("</table>"); text1 = text1.Replace("\n", "<br>"); sw.Write(heading); sw.Write(text); text2 += string.Format("<p></p>"); sw.Write(text2); sw.Write(text1); sw.Close(); Process p = new Process(); p.StartInfo.FileName = fi.Name; p.Start(); } catch (Exception) { throw new UsageException(string.Format("Unable to process the HTML file. Please use the 'Vault Help' command instead.")); } }