-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommandExecutor.cs
More file actions
27 lines (22 loc) · 871 Bytes
/
CommandExecutor.cs
File metadata and controls
27 lines (22 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using CliWrap;
using CliWrap.Buffered;
namespace Kiota.Autogen.Swagger;
public static class CommandExecutor
{
public static bool Execute(string command, out string output)
{
var (target, args) = PrepareCommand(command);
var result = Cli.Wrap(target)
.WithArguments(args)
.ExecuteBufferedAsync().ConfigureAwait(false).GetAwaiter().GetResult();
output = result.IsSuccess ? result.StandardOutput : result.StandardError;
return result.IsSuccess;
}
private static (string target, string args) PrepareCommand(string command)
{
var delimiterIndex = command.IndexOf(" ");
var target = command.Substring(0, delimiterIndex);
var args = command.Substring(delimiterIndex + 1, command.Length - delimiterIndex - 1);
return (target, args);
}
}