public static CliApplicationBuilder WithTool <TTool>(this CliApplicationBuilder builder) where TTool : CltToolBase { var toolType = typeof(TTool); var toolAttr = toolType.GetCustomAttribute <CltToolAttribute>(true); if (toolAttr is null) { throw new InvalidOperationException($"The type \"{toolType.FullName}\" needs to have a CltToolAttribute."); } var command = builder.CommandFactory.Create <TTool>(); if (toolAttr.WriteExitCodesMethodName is not null) { command.AddChildCommand(builder.CommandFactory.Create <ExitCodeCommand>()); builder.ConfigureServices(s => s.TryAddScoped <ExitCodeCommand>()); } builder.WithCommand(command); if (toolAttr.CreatorMethodName is not null) { var mi = toolType.GetMethod(toolAttr.CreatorMethodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); mi?.Invoke(null, new object[] { builder }); } if (toolType.IsAssignableTo(typeof(IHelpPageMutator))) { builder.ConfigureServices(s => s.AddScoped <IHelpPageMutator>(x => (IHelpPageMutator)x.GetRequiredService(toolType))); } return(builder); }
/// <summary> /// Adds an interactive mode to the application (enabled with [interactive] directive or `interactive` command). /// By default this adds [interactive], [default], [>], [.], and [..], as well as `interactive` command and advanced command input. /// </summary> public static CliApplicationBuilder UseInteractiveMode(this CliApplicationBuilder builder, bool asStartup = false, Action <InteractiveModeOptions>?options = null, InteractiveModeBuilderSettings?builderSettings = null) { builderSettings ??= new InteractiveModeBuilderSettings(); builder.RegisterMode <InteractiveMode>(asStartup); options ??= (InteractiveModeOptions cfg) => { }; builder.ConfigureServices((IServiceCollection sc) => sc.Configure(options)); builder.AddDirective <DefaultDirective>(); if (builderSettings.AddInteractiveCommand) { builder.AddCommand <InteractiveCommand>(); } if (builderSettings.AddInteractiveDirective) { builder.AddDirective <InteractiveDirective>(); } if (builderSettings.AddScopeDirectives) { builder.AddDirective <ScopeDirective>(); builder.AddDirective <ScopeResetDirective>(); builder.AddDirective <ScopeUpDirective>(); } return(builder); }
public static void RegisterSubCommands(CliApplicationBuilder builder) { builder.ConfigureServices(s => s.AddSingleton <ISudoService, SudoService>()); builder.WithCommand <RunCommand>() .WithCommand <DoCommand>() .WithCommand <WatchCommand>() .WithCommand <RepeatCommand>(); }
public static void RegisterSubCommands(CliApplicationBuilder builder) { builder.ConfigureServices(s => s.AddSingleton <ITemplateService, TemplateService>() .AddSingleton <ICommandsService, CommandsService>()); builder.WithCommand <ListCommand>() .WithCommand <AddCommand>() .WithCommand <RemoveCommand>() .WithCommand <InstallCommand>() .WithCommand <UninstallCommand>() .WithCommand <CleanupCommand>(); }