Beispiel #1
0
        public static CommandLineHandlerBuilder AddStandardHandlers(
            this ICommandLineHandlerBuilder builder)
        {
            if (builder is null)
            {
                throw new System.ArgumentNullException(nameof(builder));
            }

            return(builder.AddFilter(new GnuFilter(builder.CommandLine)));
        }
Beispiel #2
0
        public static CommandLineHandlerBuilder AddHandler <TVerb>(
            this ICommandLineHandlerBuilder builder,
            Action <TVerb> handler, ICommandLineOptionParser <TVerb>?parser = null)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.CommandLine.AddMatch <TVerb>(new CommandLineTypeMatcher <Task <int> >(typeof(TVerb),
                                                                                          verb => MatchWithHandler(builder.CommandLine, verb, options => Invoke(handler, options), parser)));

            return(builder switch
            {
                CommandLineHandlerBuilder commandLineBuilder => commandLineBuilder,
                CommandLine commandLine => new CommandLineHandlerBuilder(commandLine),
                _ => throw new NotSupportedException($"接口 {nameof(ICommandLineHandlerBuilder)} 不支持第三方实现。"),
            });