Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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()));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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));
            }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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));
        }