Example #1
0
 public ParserService(CommandLineFacilitator cmd)
 {
     _parser = cmd
               .GetCommandLineBuilder()
               .UseVersionOption()
               .UseHelp()
               .UseEnvironmentVariableDirective()
               .UseParseDirective()
               .UseDebugDirective()
               .UseSuggestDirective()
               .RegisterWithDotnetSuggest()
               .UseTypoCorrections()
               .UseExceptionHandler()
               .CancelOnProcessTermination()
               .UseMiddleware(async(context, next) =>
     {
         if (context.ParseResult.Errors.Count > 0)
         {
             // TODO: EMIT ERROR MESSAGE
             context.InvocationResult = new ParseErrorResult();
         }
         else
         {
             await next(context);
         }
     }, MiddlewareOrder.ErrorReporting)
               .Build();
 }
Example #2
0
        static void Main()
        {
            var root = CommandLineFacilitator
                       .Create(new CustomActivator())
                       .AddCurrentAssembly()
                       .BuildRootCommand();

            while (true)
            {
                Console.WriteLine("try '--help' or 'exit':");
                var c = Console.ReadLine();
                if (c == "exit" || c is null)
                {
                    break;
                }
                root.Invoke(c);

                Console.WriteLine("\nPress to clear");
                Console.ReadKey();
                Console.Clear();
            }
        }
Example #3
0
        /// <summary>
        /// Register services.
        /// </summary>
        public static string[] Register(string[] args)
        {
            _container = new Container();

            var(startup, restArgs) = StartupArgsFactory.Build(args);
            var life = new MopLifeService(AppState.Life.Token);
            var cmd  = CommandLineFacilitator
                       .Create(new CustomActivator())
                       .AddCurrentAssembly();

            _container.Register(() => startup, Lifestyle.Singleton);
            _container.Register(() => cmd, Lifestyle.Singleton);
            _container.Register(() => life, Lifestyle.Singleton);
            _container.Register <ISettingsLoaderService <AppSettings>, SettingsLoaderService <AppSettings> >(Lifestyle.Singleton);
            _container.Register <ISettingsService, SettingsService>(Lifestyle.Singleton);
            _container.Register <ILogService, LogService>(Lifestyle.Singleton);
            _container.Register <IHostsHandlerService, HostsHandlerService>(Lifestyle.Singleton);
            _container.Register <IParserService, ParserService>(Lifestyle.Singleton);
            _container.Register <IActorService, ActorService>(Lifestyle.Singleton);
            _container.Register <ICommandLineService, CommandLineService>(Lifestyle.Singleton);

            return(restArgs);
        }