예제 #1
0
        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);
        }
예제 #2
0
        public static void RegisterSubCommands(CliApplicationBuilder builder)
        {
            builder.ConfigureServices(s =>
                                      s.AddSingleton <ISudoService, SudoService>());

            builder.WithCommand <RunCommand>()
            .WithCommand <DoCommand>()
            .WithCommand <WatchCommand>()
            .WithCommand <RepeatCommand>();
        }
예제 #3
0
 public static void RegisterSubCommands(CliApplicationBuilder builder)
 {
     builder.WithCommand <OpenCommand>()
     .WithCommand <CopyCommand>()
     .WithCommand <AddCommand>()
     .WithCommand <RemoveCommand>()
     .WithCommand <ListCommand>()
     .WithCommand <InstallCommand>()
     .WithCommand <UninstallCommand>()
     .WithCommand <ConfigCommand>();
 }
예제 #4
0
        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>();
        }