コード例 #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
ファイル: CmdHelpers.cs プロジェクト: servicetitan/Stl.Extras
        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
ファイル: CmdBase.cs プロジェクト: servicetitan/Stl.Extras
        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
ファイル: CmdBase.cs プロジェクト: servicetitan/Stl.Extras
 protected virtual CliString TransformArguments(CliString arguments)
 => ArgumentTransformer?.Invoke(arguments) ?? arguments;
コード例 #10
0
ファイル: CmdBase.cs プロジェクト: servicetitan/Stl.Extras
 protected abstract Task <CmdResult> RunRawAsyncImpl(
     CliString arguments, string?standardInput,
     CancellationToken cancellationToken);
コード例 #11
0
ファイル: CmdBase.cs プロジェクト: servicetitan/Stl.Extras
 public Task <CmdResult> RunRawAsync(
     CliString arguments,
     CancellationToken cancellationToken = default)
 => RunRawAsync(arguments, null, cancellationToken);
コード例 #12
0
ファイル: CmdBase.cs プロジェクト: servicetitan/Stl.Extras
 protected Task <CmdResult> RunRawAsync(
     CliString command, object?arguments, CliString tail = default,
     CancellationToken cancellationToken = default)
 => RunRawAsync(command + CliFormatter.Format(arguments) + tail, cancellationToken);
コード例 #13
0
ファイル: CmdBase.cs プロジェクト: servicetitan/Stl.Extras
 protected Task <CmdResult> RunRawAsync(
     object?arguments, CliString tail    = default,
     CancellationToken cancellationToken = default)
 => RunRawAsync("", arguments, tail, cancellationToken);
コード例 #14
0
ファイル: CmdHelpers.cs プロジェクト: servicetitan/Stl.Extras
 public static CliString GetShellArguments(CliString command, CliString?prefix = default)
 => (prefix ?? ShellCmd.DefaultPrefix) + QuoteIfNonWindows(command);
コード例 #15
0
ファイル: CmdHelpers.cs プロジェクト: servicetitan/Stl.Extras
 private static CliString QuoteIfNonWindows(CliString source)
 => OSInfo.Kind != OSKind.Windows ? source.Quote() : source;