Esempio n. 1
0
 public Command ForwardStdErr(TextWriter to = null, bool onlyIfVerbose = false)
 {
     ThrowIfRunning();
     if (!onlyIfVerbose || CommandContext.IsVerbose())
     {
         if (to == null)
         {
             _stdErr.ForwardTo(write: Reporter.Error.Write, writeLine: Reporter.Error.WriteLine);
         }
         else
         {
             _stdErr.ForwardTo(write: to.Write, writeLine: to.WriteLine);
         }
     }
     return(this);
 }
Esempio n. 2
0
 public ICommand ForwardStdErr(TextWriter to = null, bool onlyIfVerbose = false, bool ansiPassThrough = true)
 {
     ThrowIfRunning();
     if (!onlyIfVerbose || CommandContext.IsVerbose())
     {
         if (to == null)
         {
             _stdErr.ForwardTo(writeLine: Reporter.Error.WriteLine);
             EnvironmentVariable(CommandContext.Variables.AnsiPassThru, ansiPassThrough.ToString());
         }
         else
         {
             _stdErr.ForwardTo(writeLine: to.WriteLine);
         }
     }
     return(this);
 }
Esempio n. 3
0
        public ICommand OnErrorLine(Action <string> handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            _stdErr.ForwardTo(writeLine: handler);

            return(this);
        }
Esempio n. 4
0
        public ICommand OnOutputLine(Action<string> handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            _stdOut.ForwardTo(writeLine: handler);

            return this;
        }
Esempio n. 5
0
        public virtual Task<CommandResult> ExecuteAsync(string args = "")
        {
            var commandPath = _command;
            ResolveCommand(ref commandPath, ref args);

            Console.WriteLine($"Executing - {commandPath} {args}");

            var stdOut = new StreamForwarder();
            var stdErr = new StreamForwarder();

            stdOut.ForwardTo(writeLine: Reporter.Output.WriteLine);
            stdErr.ForwardTo(writeLine: Reporter.Output.WriteLine);

            return RunProcessAsync(commandPath, args, stdOut, stdErr);
        }
Esempio n. 6
0
        public virtual CommandResult Execute(string args = "")
        {
            var commandPath = _command;
            ResolveCommand(ref commandPath, ref args);

            Log($"Executing - {commandPath} {args}");

            var stdOut = new StreamForwarder();
            var stdErr = new StreamForwarder();

            stdOut.ForwardTo(Log);
            stdErr.ForwardTo(Log);

            return RunProcess(commandPath, args, stdOut, stdErr);
        }
Esempio n. 7
0
        public virtual CommandResult Execute(string args = "")
        {
            var commandPath = _command;
            if (!Path.IsPathRooted(_command))
            {
                _command = Env.GetCommandPath(_command) ??
                           Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command);
            }

            Console.WriteLine($"Executing - {_command} {args}");

            var stdOut = new StreamForwarder();
            var stdErr = new StreamForwarder();

            stdOut.ForwardTo(write: Reporter.Output.Write, writeLine: Reporter.Output.WriteLine);
            stdErr.ForwardTo(write: Reporter.Error.Write, writeLine: Reporter.Output.WriteLine);

            return RunProcess(commandPath, args, stdOut, stdErr);
        }
Esempio n. 8
0
 private static void Forward(int bufferSize, ForwardOptions options, string str, string expectedCaptured, string[] expectedWrites)
 {
     var forwarder = new StreamForwarder(bufferSize);
     var writes = new List<string>();
     if ((options & ForwardOptions.WriteLine) != 0)
     {
         forwarder.ForwardTo(
             write: (options & ForwardOptions.Write) == 0 ? (Action<string>)null : writes.Add,
             writeLine: s => writes.Add(s + "\n"));
     }
     if ((options & ForwardOptions.Capture) != 0)
     {
         forwarder.Capture();
     }
     forwarder.Read(new StringReader(str));
     Assert.Equal(expectedWrites, writes);
     var captured = forwarder.GetCapturedOutput();
     Assert.Equal(expectedCaptured, captured);
 }
Esempio n. 9
0
        private void TestCapturingAndForwardingHelper(ForwardOptions options, string str, string expectedCaptured, string[] expectedWrites)
        {
            var forwarder = new StreamForwarder();
            var writes = new List<string>();

            if ((options & ForwardOptions.WriteLine) != 0)
            {
                forwarder.ForwardTo(writeLine: s => writes.Add(s + Environment.NewLine));
            }
            if ((options & ForwardOptions.Capture) != 0)
            {
                forwarder.Capture();
            }

            forwarder.Read(new StringReader(str));
            Assert.Equal(expectedWrites, writes);

            var captured = forwarder.CapturedOutput;
            Assert.Equal(expectedCaptured, captured);
        }