Esempio n. 1
0
        public CommandContext(HttpContext context, Request request, Response response, CommandInfo info, ICommand command)
        {
            HttpContext = context ?? throw new ArgumentNullException(nameof(context));
            Request     = request ?? throw new ArgumentNullException(nameof(request));
            Response    = response ?? throw new ArgumentNullException(nameof(response));
            Info        = info ?? throw new ArgumentNullException(nameof(info));
            Command     = command ?? throw new ArgumentNullException(nameof(command));

            // these TextWriters are for writing console out and error messages, just
            // like Console.Out and Console.Error
            OutWriter = new ResponseMessageTextWriter(text =>
            {
                Response.Messages.Add(ResponseMessage.Plain(text));
            });

            ErrorWriter = new ResponseMessageTextWriter(text =>
            {
                Response.Messages.Add(ResponseMessage.Error(text));
            });

            Processor = new CommandLineApplication
            {
                Name        = info.Name,
                FullName    = info.Description,
                Description = info.LongDescription,
                Out         = OutWriter,
                Error       = ErrorWriter
            };

            Processor.HelpOption("-?|-h|--help");

            HttpContext.Response.OnCompleted(OnResponseSent);
        }
Esempio n. 2
0
 /// <summary>
 /// Writes plain text messages.
 /// </summary>
 public static void WriteText(this CommandContext context, params string[] messages)
 {
     foreach (var message in messages)
     {
         context.Response.Messages.Add(ResponseMessage.Plain(message));
     }
 }