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();
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)); }
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;
protected virtual CliString TransformArguments(CliString arguments) => ArgumentTransformer?.Invoke(arguments) ?? arguments;
protected abstract Task <CmdResult> RunRawAsyncImpl( CliString arguments, string?standardInput, CancellationToken cancellationToken);
public Task <CmdResult> RunRawAsync( CliString arguments, CancellationToken cancellationToken = default) => RunRawAsync(arguments, null, cancellationToken);
protected Task <CmdResult> RunRawAsync( CliString command, object?arguments, CliString tail = default, CancellationToken cancellationToken = default) => RunRawAsync(command + CliFormatter.Format(arguments) + tail, cancellationToken);
protected Task <CmdResult> RunRawAsync( object?arguments, CliString tail = default, CancellationToken cancellationToken = default) => RunRawAsync("", arguments, tail, cancellationToken);
public static CliString GetShellArguments(CliString command, CliString?prefix = default) => (prefix ?? ShellCmd.DefaultPrefix) + QuoteIfNonWindows(command);
private static CliString QuoteIfNonWindows(CliString source) => OSInfo.Kind != OSKind.Windows ? source.Quote() : source;