Beispiel #1
0
 public new IEnumerator <IFormattable> GetEnumerator()
 => (this as IEnumerable <KeyValuePair <TKey, TValue> >)
 // ReSharper disable once HeapView.BoxingAllocation
 .Select(x => CliString.New(
             string.Format(CultureInfo.InvariantCulture, ItemTemplate, x.Key, x.Value)
             ) as IFormattable)
 .GetEnumerator();
Beispiel #2
0
        public static CliString GetEchoArguments(CliString source)
        {
            var result = source.Quote().Value;

            if (OSInfo.Kind != OSKind.Windows || result.Length < 2)
            {
                return(result);
            }
            return(result.Substring(1, result.Length - 2));
        }
Beispiel #3
0
        public virtual Task <CmdResult> RunRawAsync(
            CliString arguments, string?standardInput,
            CancellationToken cancellationToken = default)
        {
            arguments = TransformArguments(arguments);
            var command = $"{this} {arguments}";

            Log?.LogDebug($"Running: {command}");

            if (EchoMode)
            {
                var now             = DateTimeOffset.Now;
                var executionResult = new CmdResult(null !, 0, now, now, command);
                return(Task.FromResult(executionResult));
            }

            return(RunRawAsyncImpl(arguments, standardInput, cancellationToken));
        }
 protected ShellLikeCmdBase(CliString executable) : base(executable)
 {
 }
 protected override CliString TransformArguments(CliString arguments)
 => base.TransformArguments(GetPrefix() + arguments);
 public virtual Task <CmdResult> RunAsync(
     CliString command,
     string?standardInput,
     CancellationToken cancellationToken = default)
 => base.RunRawAsync(command, standardInput, cancellationToken);
 public virtual Task <CmdResult> RunAsync(
     CliString command,
     CancellationToken cancellationToken = default)
 => RunAsync(command, null, cancellationToken);
 public async Task <string> GetOutputAsync(
     CliString command,
     string?standardInput,
     CancellationToken cancellationToken = default)
 => (await RunAsync(command, standardInput, cancellationToken).ConfigureAwait(false))
 .StandardOutput;
Beispiel #9
0
 protected virtual CliString TransformArguments(CliString arguments)
 => ArgumentTransformer?.Invoke(arguments) ?? arguments;
Beispiel #10
0
 protected abstract Task <CmdResult> RunRawAsyncImpl(
     CliString arguments, string?standardInput,
     CancellationToken cancellationToken);
Beispiel #11
0
 public Task <CmdResult> RunRawAsync(
     CliString arguments,
     CancellationToken cancellationToken = default)
 => RunRawAsync(arguments, null, cancellationToken);
Beispiel #12
0
 protected Task <CmdResult> RunRawAsync(
     CliString command, object?arguments, CliString tail = default,
     CancellationToken cancellationToken = default)
 => RunRawAsync(command + CliFormatter.Format(arguments) + tail, cancellationToken);
Beispiel #13
0
 protected Task <CmdResult> RunRawAsync(
     object?arguments, CliString tail    = default,
     CancellationToken cancellationToken = default)
 => RunRawAsync("", arguments, tail, cancellationToken);
Beispiel #14
0
 public static CliString GetShellArguments(CliString command, CliString?prefix = default)
 => (prefix ?? ShellCmd.DefaultPrefix) + QuoteIfNonWindows(command);
Beispiel #15
0
 private static CliString QuoteIfNonWindows(CliString source)
 => OSInfo.Kind != OSKind.Windows ? source.Quote() : source;