コード例 #1
0
        public Task CommandAppAsyncTest(string[] args,
                                        string commandName,
                                        Action <CommandConfiguration <Models.BuildOptions> > configure,
                                        Models.BuildOptions expectedOptions)
        {
            var configuration = new ApplicationConfiguration <Models.Options>();

            configuration
            .Command <Models.BuildOptions>(commandName, cfg =>
            {
                configure(cfg);
                cfg.OnExecuteAsync(opt =>
                {
                    opt.ShouldBe(expectedOptions);
                    return(Task.CompletedTask);
                });
            })
            .PositionArgument(arg => arg.Map.ToProperty(o => o.Project))
            .OnExecuteAsync(_ =>
            {
                false.ShouldBeTrue("App handler called, shouldn't been");
                return(Task.CompletedTask);
            });
            return(RuntimeCommandBuilder.Build(configuration, args, out var options)
                   .InvokeAsync(options, CancellationToken.None));
        }
コード例 #2
0
 /// <summary>
 /// Executes the application asynchronously.
 /// </summary>
 /// <param name="configuration">Configuration instance.</param>
 /// <param name="arguments">Arguments given on the command line.</param>
 public static Task RunAsync(ICommandLineConfiguration configuration,
                             IEnumerable <string> arguments)
 {
     return(RuntimeCommandBuilder
            .Build(configuration, arguments, out var options)
            .InvokeAsync(options, CancellationToken.None));
 }
コード例 #3
0
 /// <summary>
 /// Executes the application.
 /// </summary>
 /// <param name="configuration">Configuration instance.</param>
 /// <param name="arguments">Arguments given on the command line.</param>
 public static void Run(ICommandLineConfiguration configuration,
                        IEnumerable <string> arguments)
 {
     RuntimeCommandBuilder
     .Build(configuration, arguments, out var options)
     .Invoke(options);
 }
コード例 #4
0
        /// <summary>
        /// Parses the arguments without invoking the client handler.
        /// </summary>
        /// <typeparam name="TOptions">Options type.</typeparam>
        /// <param name="configuration">Configuration</param>
        /// <param name="arguments">Arguments given on the command line</param>
        /// <returns>Populated options object</returns>
        public static TOptions ParseArguments <TOptions>(ICommandLineConfiguration configuration,
                                                         IEnumerable <string> arguments)
            where TOptions : class
        {
            RuntimeCommandBuilder.Build(configuration, arguments, out var options);

            return((TOptions)options);
        }
コード例 #5
0
        public void HelpWithNoProviderThrows()
        {
            var config     = new ApplicationConfiguration <Models.Options>();
            var writerMock = new Mock <IHelpWriter>();

            config.HelpOption("--help", writerMock.Object);
            Should.Throw <ConfigurationException>(() => RuntimeCommandBuilder.Build(config, new[] { "--help" },
                                                                                    out var options).Invoke(options));
        }
コード例 #6
0
        public void BaseAppTest(string[] args,
                                Action <ApplicationConfiguration <Models.Options> > configure,
                                Models.Options expectedOptions)
        {
            var configuration = new ApplicationConfiguration <Models.Options>();

            configure(configuration);
            configuration.OnExecute(opt => opt.ShouldBe(expectedOptions));
            RuntimeCommandBuilder.Build(configuration, args, out var options).Invoke(options);
        }
コード例 #7
0
        public void HelpInvoked()
        {
            var config     = new ApplicationConfiguration <Models.Options>();
            var writerMock = new Mock <IHelpWriter>();

            writerMock.Setup(m => m.WriteContent(It.IsAny <IReadOnlyCollection <string> >())).Verifiable();
            config.HelpOption("--help", writerMock.Object)
            .Help.UseContent(new[] { "help" });
            RuntimeCommandBuilder.Build(config, new[] { "--help" }, out var options).Invoke(options);
            writerMock.Verify(m => m.WriteContent(It.IsAny <IReadOnlyCollection <string> >()), Times.Once);
        }
コード例 #8
0
        public void ThrowsForInvalidOption()
        {
            var config = new ApplicationConfiguration <Models.Options>();

            config
            .PositionArgument(arg => arg.Map.ToProperty(o => o.Project))
            .OnExecute(_ => { });

            Should.Throw <UsageException>(() => RuntimeCommandBuilder.Build(
                                              config, new[] { "-f" }, out var options).Invoke(options));
            ;
        }
コード例 #9
0
        public Task BaseAppAsyncTest(string[] args,
                                     Action <ApplicationConfiguration <Models.Options> > configure,
                                     Models.Options expectedOptions)
        {
            var configuration = new ApplicationConfiguration <Models.Options>();

            configure(configuration);
            configuration.OnExecuteAsync(opt =>
            {
                opt.ShouldBe(expectedOptions);
                return(Task.CompletedTask);
            });
            return(RuntimeCommandBuilder.Build(configuration, args, out var options).InvokeAsync(options,
                                                                                                 CancellationToken.None));
        }
コード例 #10
0
        public void CommandAppTest(string[] args,
                                   string commandName,
                                   Action <CommandConfiguration <Models.BuildOptions> > configure,
                                   Models.BuildOptions expectedOptions)
        {
            var configuration = new ApplicationConfiguration <Models.Options>();

            configuration
            .Command <Models.BuildOptions>(commandName, cfg =>
            {
                configure(cfg);
                cfg.OnExecute(opt => opt.ShouldBe(expectedOptions));
            })
            .PositionArgument(arg => arg.Map.ToProperty(o => o.Project))
            .OnExecute(_ => false.ShouldBeTrue("App handler called, shouldn't been"));
            RuntimeCommandBuilder.Build(configuration, args, out var options).Invoke(options);
        }
コード例 #11
0
 public void BuildWithNullArgsThrows()
 {
     Should.Throw <ArgumentNullException>(() =>
                                          RuntimeCommandBuilder.Build(new ApplicationConfiguration <object>(), null !, out _));
 }