예제 #1
0
 /// <summary>
 /// Standard input redirection as in bash. The given <paramref name="file"/> is written to the <see cref="Command"/>'s
 /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
 /// of both this <see cref="Command"/> and the IO being performed
 /// </summary>
 public static Command operator <(Command command, FileInfo file)
 {
     Throw.IfNull(command, "command");
     return(command.RedirectFrom(file));
 }
예제 #2
0
 /// <summary>
 /// Standard input redirection as in bash. The items in <paramref name="lines"/> are written to the <see cref="Command"/>'s
 /// standard output as lines of text. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the
 /// progress of both this <see cref="Command"/> and the IO being performed
 /// </summary>
 public static Command operator <(Command command, IEnumerable <string> lines)
 {
     Throw.IfNull(command, "command");
     return(command.RedirectFrom(lines));
 }
예제 #3
0
        /// <summary>
        /// Standard input redirection as in bash. The items in <paramref name="chars"/> are written to the <see cref="Command"/>'s
        /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the
        /// progress of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public static Command operator <(Command command, IEnumerable <char> chars)
        {
            Throw.IfNull(command, "command");

            return(new IoCommand(command, command.StandardInput.PipeFromAsync(chars)));
        }
예제 #4
0
        /// <summary>
        /// Standard error redirection as in bash. The <see cref="Command"/>'s standard error is written to the given
        /// <paramref name="stream"/>. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
        /// of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectStandardErrorTo(Stream stream)
        {
            Throw.IfNull(stream, nameof(stream));

            return(new IoCommand(this, this.StandardError.PipeToAsync(stream, leaveStreamOpen: true)));
        }
예제 #5
0
 /// <summary>
 /// Throws an <see cref="ArgumentNullException"/> if the given value is null
 /// </summary>
 public static void IfNull <T>(T value, string parameterName)
 {
     Throw <ArgumentNullException> .If(value == null, parameterName);
 }
예제 #6
0
        /// <summary>
        /// Standard input redirection as in bash. The given <paramref name="stream"/> is written to the <see cref="Command"/>'s
        /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
        /// of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public static Command operator <(Command command, Stream stream)
        {
            Throw.IfNull(command, "command");

            return(new IoCommand(command, command.StandardInput.PipeFromAsync(stream, leaveStreamOpen: true)));
        }
예제 #7
0
        /// <summary>
        /// Standard error redirection as in bash. The chars of <see cref="Command"/>'s standard error are added to the given
        /// collection (<paramref name="chars"/> Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks
        /// the progress of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectStandardErrorTo(ICollection <char> chars)
        {
            Throw.IfNull(chars, nameof(chars));

            return(new IoCommand(this, this.StandardError.PipeToAsync(chars)));
        }
예제 #8
0
 /// <summary>
 /// Creates a shell whose commands will receive the given configuration options
 /// </summary>
 public Shell(Action <Options> options)
 {
     Throw.IfNull(options, nameof(options));
     this.Configuration = options;
 }
예제 #9
0
        /// <summary>
        /// Standard error redirection as in bash. The lines of <see cref="Command"/>'s standard error are added to the given
        /// collection (<paramref name="lines"/> Returns a new <see cref="Command"/>  whose <see cref="Command.Task"/> tracks
        /// the progress of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectStandardErrorTo(ICollection <string> lines)
        {
            Throw.IfNull(lines, nameof(lines));

            return(new IoCommand(this, this.StandardError.PipeToAsync(lines)));
        }
예제 #10
0
        /// <summary>
        /// Standard input redirection as in bash. The items in <paramref name="lines"/> are written to the <see cref="Command"/>'s
        /// standard output as lines of text. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the
        /// progress of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectFrom(IEnumerable <string> lines)
        {
            Throw.IfNull(lines, nameof(lines));

            return(new IoCommand(this, this.StandardInput.PipeFromAsync(lines)));
        }
예제 #11
0
        /// <summary>
        /// Standard input redirection as in bash. The given <paramref name="file"/> is written to the <see cref="Command"/>'s
        /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
        /// of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectFrom(FileInfo file)
        {
            Throw.IfNull(file, nameof(file));

            return(new IoCommand(this, this.StandardInput.PipeFromAsync(file)));
        }
예제 #12
0
        /// <summary>
        /// Standard error redirection as in bash. The <see cref="Command"/>'s standard error is written to the given
        /// <paramref name="file"/>. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
        /// of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectStandardErrorTo(FileInfo file)
        {
            Throw.IfNull(file, nameof(file));

            return(new IoCommand(this, this.StandardError.PipeToAsync(file)));
        }
예제 #13
0
        /// <summary>
        /// Standard input redirection as in bash. The given <paramref name="stream"/> is written to the <see cref="Command"/>'s
        /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
        /// of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectFrom(Stream stream)
        {
            Throw.IfNull(stream, nameof(stream));

            return(new IoCommand(this, this.StandardInput.PipeFromAsync(stream, leaveStreamOpen: true)));
        }
예제 #14
0
 /// <summary>
 /// Standard input redirection as in bash. The items in <paramref name="chars"/> are written to the <see cref="Command"/>'s
 /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the
 /// progress of both this <see cref="Command"/> and the IO being performed
 /// </summary>
 public static Command operator <(Command command, IEnumerable <char> chars)
 {
     Throw.IfNull(command, "command");
     return(command.RedirectFrom(chars));
 }
예제 #15
0
        /// <summary>
        /// Standard input redirection as in bash. The items in <paramref name="chars"/> are written to the <see cref="Command"/>'s
        /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the
        /// progress of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectFrom(IEnumerable <char> chars)
        {
            Throw.IfNull(chars, nameof(chars));

            return(new IoCommand(this, this.StandardInput.PipeFromAsync(chars)));
        }
예제 #16
0
        /// <summary>
        /// Executes the given <paramref name="executable"/> with the given <paramref name="arguments"/>
        /// </summary>
        public Command Run(string executable, params object[] arguments)
        {
            Throw.IfNull(arguments, "arguments");

            return(this.Run(executable, arguments.AsEnumerable()));
        }
예제 #17
0
        /// <summary>
        /// Standard error redirection as in bash. The <see cref="Command"/>'s standard error is written to the given
        /// <paramref name="writer"/>. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
        /// of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectStandardErrorTo(TextWriter writer)
        {
            Throw.IfNull(writer, nameof(writer));

            return(new IoCommand(this, this.StandardError.PipeToAsync(writer, leaveWriterOpen: true)));
        }
예제 #18
0
            /// <summary>
            /// Adds or overwrites an environment variable to be passed to the <see cref="Medallion.Shell.Command"/>
            /// </summary>
            public Options EnvironmentVariable(string name, string value)
            {
                Throw.If(string.IsNullOrEmpty(name), "name is required");

                return(this.StartInfo(psi => psi.EnvironmentVariables[name] = value));
            }
예제 #19
0
        /// <summary>
        /// Standard input redirection as in bash. The given <paramref name="reader"/> is written to the <see cref="Command"/>'s
        /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
        /// of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public Command RedirectFrom(TextReader reader)
        {
            Throw.IfNull(reader, nameof(reader));

            return(new IoCommand(this, this.StandardInput.PipeFromAsync(reader, leaveReaderOpen: true)));
        }
예제 #20
0
 /// <summary>
 /// Throws an <see cref="ArgumentException"/> if the given condition is true
 /// </summary>
 public static void If(bool condition, string parameterName)
 {
     Throw <ArgumentException> .If(condition, parameterName);
 }
예제 #21
0
 /// <summary>
 /// Implements <see cref="Command"/> piping as in bash. The first <see cref="Command"/>'s standard output is piped
 /// to the second's standard input. Returns a new <see cref="Command"/> instance whose <see cref="Command.Task"/> tracks
 /// the progress of the entire chain
 /// </summary>
 public static Command operator |(Command first, Command second)
 {
     Throw.IfNull(first, "first");
     return(first.PipeTo(second));
 }
예제 #22
0
        /// <summary>
        /// Standard input redirection as in bash. The given <paramref name="file"/> is written to the <see cref="Command"/>'s
        /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
        /// of both this <see cref="Command"/> and the IO being performed
        /// </summary>
        public static Command operator <(Command command, FileInfo file)
        {
            Throw.IfNull(command, "command");

            return(new IoCommand(command, command.StandardInput.PipeFromAsync(file)));
        }
예제 #23
0
 /// <summary>
 /// Standard input redirection as in bash. The given <paramref name="stream"/> is written to the <see cref="Command"/>'s
 /// standard output. Returns a new <see cref="Command"/> whose <see cref="Command.Task"/> tracks the progress
 /// of both this <see cref="Command"/> and the IO being performed
 /// </summary>
 public static Command operator <(Command command, Stream stream)
 {
     Throw.IfNull(command, "command");
     return(command.RedirectFrom(stream));
 }
예제 #24
0
 /// <summary>
 /// Throws <see cref="ObjectDisposedException"/> if the <see cref="Command"/> has been disposed
 /// </summary>
 protected void ThrowIfDisposed()
 {
     Throw <ObjectDisposedException> .If(Volatile.Read(ref this._disposed) != 0, () => this.ToString());
 }
예제 #25
0
        /// <summary>
        /// Implements <see cref="Command"/> piping as in bash. The first <see cref="Command"/>'s standard output is piped
        /// to the second's standard input. Returns a new <see cref="Command"/> instance whose <see cref="Command.Task"/> tracks
        /// the progress of the entire chain
        /// </summary>
        public Command PipeTo(Command second)
        {
            Throw.IfNull(second, nameof(second));

            return(new PipedCommand(this, second));
        }