Пример #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));
        }