void WriteVerbBlock(IndentedTextWriter writer, string verb, VerbDef verbDef) { writer.WriteLine("{0}: {1}", verb, verbDef.Help); writer.Indent += 1; WriteOptionBlock(writer, verbDef.Options); writer.Indent -= 1; }
public ProgramOpts AddVerb(string verb, string help, Func <ParsedOpts, int> handler, Func <VerbDef, VerbDef> func) { var vdef = new VerbDef(verb, help, handler); if (func != null) { vdef = func(vdef); } Verbs.Add(verb, vdef); return(this); }
public string GetHelp(VerbDef verb) { var buffer = new StringWriter(); var writer = new IndentedTextWriter(buffer); if (Options.Count > 0) { writer.WriteLine("Common options:"); writer.Indent += 1; WriteOptionBlock(writer, Options); writer.WriteLine(); writer.Indent -= 1; } if (Verbs.Count > 0) { writer.WriteLine("Commands:"); writer.Indent += 1; var verbs = new List <string>(Verbs.Keys); verbs.Sort(StringComparer.Ordinal); foreach (string v in verbs) { if (verb != null && verb.Name != v) { continue; } WriteVerbBlock(writer, v, Verbs[v]); writer.WriteLine(); } writer.Indent -= 1; } writer.Flush(); buffer.Flush(); return(buffer.ToString()); }