public void TestSuggestion() { // SETUP string result = string.Empty; var expected = $"'tst' is not recognized as a valid command or option.{Environment.NewLine}{Environment.NewLine}Did you mean: {Environment.NewLine}\tTest{Environment.NewLine}"; var consoleMock = new Mock <IConsole>(); consoleMock.Setup(_ => _.WriteLine(It.IsAny <string>())).Callback((string s) => result = s).Verifiable(); Services.AddSingleton(consoleMock.Object); Services.AddSingleton(Logger); Services.AddCommandLineParser <OptionModel>(); var parser = ResolveParser <OptionModel>(); var cmdConfig = parser.AddCommand <OptionModel>(); cmdConfig.Name("ZZZZZZZZZZZZZZ").Configure(o => o.Option).Name("tst"); parser.AddCommand().Name("Test"); parser.Configure(o => o.Option).Name("Test1"); var model = new UnusedArgumentModel("tst", (IArgument)parser); var printer = parser.Services.GetRequiredService <IUsagePrinter>(); // ACT printer.PrintSuggestion(model); // ASSERT consoleMock.VerifyAll(); Assert.Equal(expected, result); }
private void AddUnprocessedArgument(ArgumentRecord rec) { var arg = CurrentContext.CurrentOption != null ? (IArgument)CurrentContext.CurrentOption : (IArgument)CurrentContext.CurrentCommand; var item = new UnusedArgumentModel(rec.RawData, arg); unprocessedArguments.Add(item); }
/// <inheritdoc/> public virtual bool PrintSuggestion(UnusedArgumentModel model) { var suggestions = suggestionProvider.GetSuggestions(model.Key, model.Argument as ICommandLineCommandContainer); if (!suggestions.Any()) { return(false); } Builder.AddSuggestionHeader(model.Key); Builder.AddSuggestion(suggestions.First()); console.WriteLine(Builder.Build()); return(true); }