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