public void Show_1() { MockOutput output = new MockOutput(); OutputHelp outputHelp = new OutputHelp(CliOptions.WindowsStyle, output); List <Description> descs = new List <Description> { new Description("width", "The width of the rectangle.", eROLE.NAMED, new ParamString(), eSCOPE.REQUIRED, eMULTIPLICITY.ONCE), new Description("filename", "The input file.", eROLE.PASSED, new ParamString(), eSCOPE.OPTIONAL, eMULTIPLICITY.ONCE) }; outputHelp.Show(descs); string[] lines = output.getLines(); CollectionAssert.AreEqual( new[] { "Usage: GemsCLI [/options] [filename]", "Where options include:", "/width The width of the rectangle.", "filename* The input file.", "* shows optional parameters." }, lines); }
/// <summary> /// The main entry point for the example. /// </summary> /// <param name="pArgs">The arguments from the command line.</param> private static void Main(string[] pArgs) { WriteGreeting(); CliOptions options = CliOptions.WindowsStyle; List <Description> descs = DescriptionFactory.Create( options, new HelpResource(Help.ResourceManager), "/echo [/mode:string#] /address:string /database:string /username:string [/password:string] filename [output:string]" ); ConsoleFactory consoleFactory = new ConsoleFactory(); if (pArgs.Length == 0) { OutputHelp outputHelp = new OutputHelp(options, consoleFactory.Create()); outputHelp.Show(descs); return; } Request request = RequestFactory.Create(options, pArgs, descs, consoleFactory); }
/// <summary> /// Entry /// </summary> /// <param name="pArgs">The arguments from the command line.</param> private static void Main(string[] pArgs) { ConsoleFactory consoleFactory = new ConsoleFactory(); iOutputStream outS = consoleFactory.Create(); WriteGreeting(outS); CliOptions options = CliOptions.WindowsStyle; List <Description> descs = DescriptionFactory.Create( options, new HelpResource(Help.ResourceManager), "[/domains:string] [/limit:int] [/count] [/sort:string] [/desc] [/max:int] [/min:int] pattern" ); if (pArgs.Length == 0) { OutputHelp outputHelp = new OutputHelp(options, consoleFactory.Create()); outputHelp.Show(descs); return; } Request req = RequestFactory.Create(options, pArgs, descs, consoleFactory); if (!req.Valid) { return; } string pattern = req.Get <string>("pattern"); outS.Standard(pattern); outS.Standard(""); int max = req.Contains("max") ? Math.Min(req.Get <int>("max"), _MAX_LENGTH) :_MAX_LENGTH; int min = req.Contains("min") ? Math.Max(req.Get <int>("min"), 1) : 1; IEnumerable <string> domains = (from topLevel in getTopLevel(req) from domain in getPattern(req) where !domain.StartsWith("-") && !domain.EndsWith("-") && domain.Length <= max && domain.Length >= min let str = string.Format("{0}.{1}", domain, topLevel) where str.Length <= _MAX_LENGTH && !AnyLabelTooLong(domain, 63) select str).Distinct(); if (req.Contains("count")) { outS.Standard(domains.Count().ToString(CultureInfo.InvariantCulture)); return; } if (req.Contains("sort")) { string sort = req.Get <string>("sort").ToLower(); domains = sort == "width" ? domains.OrderBy(pDomain => pDomain.Length) : domains.OrderBy(pDomain => pDomain); if (req.Contains("desc")) { domains = domains.Reverse(); } } foreach (string domain in setLimit(req, domains)) { if (isFree(domain)) { outS.Standard(domain); } } }