public OperationHelp(OperationSymbol operationSymbol, Type type, string?userDescription) { this.OperationSymbol = operationSymbol; this.Type = type; this.Info = HelpGenerator.GetOperationHelp(type, operationSymbol); this.UserDescription = userDescription; }
private static void ParseArgs(string[] args) { var opt = new Verbs(); var helpGen = new HelpGenerator <Verbs>(); helpGen.DescriptionDistance = 25; var parser = new CliParser <Verbs>(opt, ParserOptions.CaseInsensitive, helpGen); parser.StrictParse(args); if (opt.Start != null) { StartService(opt.Start.ReadOnly); } else if (opt.Stop != null) { StopService(); } else if (opt.Set != null) { SetFanSpeed(opt.Set); } else if (opt.Config != null) { ConfigureService(opt.Config); } else if (opt.Status != null) { PrintStatus(opt.Status); } else { Console.WriteLine(helpGen.GetHelp(parser.Config)); } }
public PropertyHelp(PropertyRoute propertyRoute, string?userDescription) { if (propertyRoute.PropertyRouteType != PropertyRouteType.FieldOrProperty) { throw new ArgumentException("propertyRoute should be of type Property"); } this.PropertyRoute = propertyRoute; this.Info = HelpGenerator.GetPropertyHelp(propertyRoute); this.UserDescription = userDescription; }
public void When_There_Is_No_Type_It_Prints_Warning() { var typeFinderMock = new Mock <IVerbTypeFinder>(); typeFinderMock.Setup(a => a.FindAll()).Returns(new List <Type>()); var helpGenerator = new HelpGenerator(typeFinderMock.Object); var helpText = helpGenerator.Build(); Assert.NotEmpty(helpText.ToString()); Assert.Equal("No help is found!", helpText.ToString()); }
public void ResultHelpTextContainsNecessaryInfo() { var help = new HelpGenerator(); var text = help.Generate(typeof(TestOptions)); Assert.IsTrue(text.Contains(VerbName)); Assert.IsTrue(text.Contains(VerbHelpText)); Assert.IsTrue(text.Contains(ShortOptionName.ToString())); Assert.IsTrue(text.Contains(LongOptionName)); Assert.IsTrue(text.Contains(OptionHelpText)); }
public void Help(object _) { var switches = HelpGenerator.Generate <DyaOptions>("-").TrimEnd('\r', '\n'); var commands = HelpGenerator.Generate(typeof(CommandDispatcher), Prefix).TrimEnd('\r', '\n'); Printer.LineFeed(); Printer.Output("Command line switches:"); Printer.Output(switches); Printer.LineFeed(); Printer.Output("Commands:"); Printer.Output(commands); }
public void GenerateUsageTest() { var parser = new CmdLineParser <TestCmdLineObj>(); var results = parser.Parse(new string[] { }); results.ApplicationFileName = "test.exe"; var generator = new HelpGenerator(results); var usage = generator.GetUsage(); Assert.AreEqual("test.exe <Name|String> [/Type <Father|Mother|Child>]", usage); }
public QueryHelp(object queryName, CultureInfo ci, QueryHelpEntity?entity) { QueryName = queryName; Culture = ci; Info = HelpGenerator.GetQueryHelp(QueryLogic.Queries.GetQuery(queryName).Core.Value); var cols = entity?.Columns.ToDictionary(a => a.ColumnName, a => a.Description); Columns = QueryLogic.Queries.GetQuery(queryName).Core.Value.StaticColumns.ToDictionary( cf => cf.Name, cf => new QueryColumnHelp(cf, cf.DisplayName(), HelpGenerator.GetQueryColumnHelp(cf), cols?.TryGetCN(cf.Name))); DBEntity = entity; UserDescription = entity?.Description; }
public void When_Types_Found_Help_Generated() { var typeFinderMock = new Mock <IVerbTypeFinder>(); typeFinderMock.Setup(a => a.FindAll()).Returns(new List <Type>() { typeof(TestVerb) }); var helpGenerator = new HelpGenerator(typeFinderMock.Object); var helpText = helpGenerator.Build(); Assert.NotEmpty(helpText.ToString()); Assert.True(helpText.ToString().Contains("TestVerb")); }
public override Task Execute(State state) { if (ShowHelp(state)) { var helpGenerator = new HelpGenerator(this); return(helpGenerator.Write()); } if (Next == null) { throw new Exception("TODO: Good message"); } return(Next.Execute(state)); }
internal static void WriteHelpText() { HelpGenerator.WriteUsage(); ToolConsole.WriteLine(); ToolConsole.WriteLine(); HelpGenerator.WriteCommonOptionsHelp(); ToolConsole.WriteLine(); ToolConsole.WriteLine(); HelpGenerator.WriteXmlSerializerTypeGenerationHelp(); ToolConsole.WriteLine(); ToolConsole.WriteLine(); HelpGenerator.WriteExamples(); ToolConsole.WriteLine(); ToolConsole.WriteLine(); }
public void WriteEmpty() { // Arrange var application = new KingpinApplication(console); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains("usage:", result); }
public void WriteGlobalFlagWithShortName() { // Arrange var application = new KingpinApplication(console); application.Flag("flag", "flag help").Short('f'); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"Flags:", result); Assert.Contains($" -f, --flag=<value> flag help", result); }
public void WriteGlobalArgument() { // Arrange var application = new KingpinApplication(console); application.Argument("arg", "arg help"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: [<arg>]", result); Assert.Contains($"Args:", result); Assert.Contains($" [<arg>] arg help", result); }
public void WriteGlobalCommand() { // Arrange var application = new KingpinApplication(console); application.Command("cmd", "command help"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: <command>", result); Assert.Contains($"Commands:", result); Assert.Contains($" cmd", result); Assert.Contains($" command help", result); }
public void WriteGlobalCommandWithFlagAndDefaultValue() { // Arrange var application = new KingpinApplication(console); var command = application.Command("cmd", "command help"); command.Flag("flag", "flag help").Default("1234.5678"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: <command>", result); Assert.Contains($"Commands:", result); Assert.Contains($" cmd --flag=<1234.5678> flag help command help", result); }
public void WriteHelpForNestedCommand() { // Arrange var application = new KingpinApplication(console); var command = application.Command("cmd1", "command1 help"); command.Command("cmd2", "command2 help"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.CommandHelp.liquid"); subject.Generate(command, writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: cmd1 <command>", result); Assert.Contains($"command1 help", result); Assert.Contains($"Commands:", result); Assert.Contains($" cmd2 command2 help", result); }
public void WriteGlobalCommandWithFlagAndExamples() { // Arrange var application = new KingpinApplication(console); var command = application.Command("cmd", "command help"); command.Flag("flag", "flag help").SetExamples("1", "2"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.CommandHelp.liquid"); subject.Generate(command, writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: cmd [<flags>]", result); Assert.Contains($" command help", result); Assert.Contains($"Flags:", result); Assert.Contains($" --flag=<value> flag help (e.g. 1, 2)", result); }
/// <summary> /// Creates an instance of the ITestModuleRunner /// </summary> /// <param name="runnerType">The type of the runner to create</param> /// <returns>An implementation of the ITestModuleRunner </returns> public ITestModuleRunner CreateRunner(Type runnerType) { LightweightDependencyInjectionContainer dependencyInjectionContainer = null; ITestModuleRunner runner = null; try { #if SILVERLIGHT runner = Activator.CreateInstance(runnerType) as ITestModuleRunner; #else runner = new RunnerBridge(runnerType); #endif dependencyInjectionContainer = new LightweightDependencyInjectionContainer(); var implementationSelector = new ImplementationSelector(); implementationSelector.AddAssembly(typeof(TestItem).GetAssembly()); var helpGenerator = new HelpGenerator(new LogLevelResolver(this.Parameters)); var availableParameters = helpGenerator.GetAvailableParameters(implementationSelector.Types); Dictionary <string, string> availableParametersLookup = this.Parameters.Where(kvp => availableParameters.Any(p => p.ParameterName == kvp.Key)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); // Any TestParameters passed in are not used for injecting dependencies into RunnerBridge var configurator = new DependencyInjectionConfigurator( implementationSelector, availableParametersLookup); configurator.RootLogger = Logger.Null; configurator.ConfigureDefaultDependencies(dependencyInjectionContainer); dependencyInjectionContainer.InjectDependenciesInto(runner); } finally { if (dependencyInjectionContainer != null) { dependencyInjectionContainer.Dispose(); } } return(runner); }
public void WriteNestedCommandWithGlobalCommandWithAFlag() { // Arrange var application = new KingpinApplication(console); var command = application.Command("cmd1", "command1 help"); command.Flag("flag", "flag help"); command.Command("cmd2", "command2 help"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: <command>", result); Assert.Contains($"Commands:", result); Assert.Contains($" cmd1 --flag=<value> flag help command1 help", result); Assert.Contains($" cmd1 cmd2 command2 help", result); }
public TypeHelp(Type type, CultureInfo culture, TypeHelpEntity?entity) { Type = type; Culture = culture; Info = HelpGenerator.GetEntityHelp(type); var props = DBEntity?.Properties.ToDictionaryEx(a => a.Property.ToPropertyRoute(), a => a.Info); var opers = DBEntity?.Operations.ToDictionaryEx(a => a.Operation, a => a.Info); Properties = PropertyRoute.GenerateRoutes(type) .ToDictionary(pp => pp, pp => new PropertyHelp(pp, props?.TryGetC(pp))); Operations = OperationLogic.TypeOperations(type) .ToDictionary(op => op.OperationSymbol, op => new OperationHelp(op.OperationSymbol, type, opers?.TryGetC(op.OperationSymbol))); var allQueries = HelpLogic.CachedQueriesHelp(); Queries = HelpLogic.TypeToQuery.Value.TryGetC(this.Type).EmptyIfNull().Select(a => allQueries.GetOrThrow(a)).ToDictionary(qh => qh.QueryName); DBEntity = entity; }
public Calculator2() { InitializeComponent(); col0 = InputGrid.ColumnDefinitions[0].Width.Value; col1 = InputGrid.ColumnDefinitions[1].Width.Value; col2 = InputGrid.ColumnDefinitions[2].Width.Value; _core = new PythonCore(this.Output); vars = new Dictionary <string, string>(); Calc.Core = _core; _buffer = new StringBuilder(); _calc = new Thread(TFunc); _help = new HelpGenerator(); _history = new ObservableCollection <HistoryItem>(); LbHistory.ItemsSource = _history; _canrun = true; _core.AttachTypeToRuntime(typeof(Calc)); _core.AttachTypeToRuntime(typeof(Maths.Fraction)); _core.AttachTypeToRuntime(typeof(UserInterface.InputForm)); CreateButtons(typeof(Maths.Functions), Functions); CreateButtons(typeof(Maths.Trigonometry), Trig); CreateButtons(typeof(Maths.Rnd), Rand); CreateButtons(typeof(Maths.Binary), Bin); CreateButtons(typeof(Maths.Complex), Cplx); CreateButtons(typeof(Maths.Sets), SetStat); CreateButtons(typeof(Maths.Stat), SetStat); CreateButtons(typeof(Maths.Matrices), Matrix); CreateButtons(typeof(Maths.Specials), Specials); CreateButtons(typeof(Maths.NumberInfo), Specials); CreateButtons(typeof(Maths.Const), ConstantsPanel); CreateButtons(typeof(UserInterface.UserInterface), Dialogs); _defaultvars = _core.VariablesNames; SynBox.SyntaxLexer = _core.SyntaxProvider; Output.WriteImage(new Uri("pack://application:,,,/MCalculator.Tool;component/icon/calcintro.png", UriKind.Absolute)); }
public void GenerateExitCodesTest() { // No exit codes have been defined. var parser = new CmdLineParser <TestCmdLineObj>(); var results = parser.Parse(new string[] { }); parser.Options.ExitCodes = null; var generator = new HelpGenerator(results); var help = generator.GetExitCodesDisplay(); Assert.AreEqual("", help); // Verify the parser can find the ExitCodes enum and InvalidArgs value. parser = new CmdLineParser <TestCmdLineObj>(); results = parser.Parse(new string[] { }); generator = new HelpGenerator(results); help = generator.GetExitCodesDisplay(); Assert.AreEqual(" 0 = Success!!!\r\n1234 = Failed :'(\r\n", help); Assert.AreEqual((int)ExitCodes.InvalidArgs, parser.Options.InvalidArgsExitCode); Assert.IsNull(parser.Options.FatalErrorExitCode); }
public void WriteFlagWithValueName() { // Arrange var application = new KingpinApplication(console); application.ApplicationName("x"); var command = application.Command("cmd", "command help"); command.Flag("flag", "flag help").ValueName("!name!"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: x <command>", result); Assert.Contains($"Commands:", result); Assert.Contains($" cmd --flag=!name!", result); Assert.Contains($" command help", result); }
public void GeneratePropHelpTest() { var parser = new CmdLineParser <TestCmdLineObj>(); var results = parser.Parse(new string[] { }); var generator = new HelpGenerator(results); var help = generator.GetPropertyHelp(results.Properties["Name"]); Assert.That.Contains("/Name <String> REQUIRED", help); Assert.That.Contains("\tTEST DESC", help); // Type doesn't have a description, but the flag is set to show it. help = generator.GetPropertyHelp(results.Properties["Type"]); Assert.That.Contains("/PersonType (/Type) <Father|Mother|Child>", help); Assert.That.Contains("\tDefault: Father", help); help = generator.GetPropertyHelp(results.Properties["Children"]); Assert.That.Contains("/Children", help); Assert.That.Contains("\tDefault: [\"One\", \"Two\", \"Three\"]", help); help = generator.GetPropertyHelp(results.Properties["Secret"]); Assert.That.Contains("/Secret", help); Assert.IsFalse(help.Contains("Shhh!")); }