SideCarCLI-send arguments to interceptors

Summary links SideCarCLI

NoName + Link 
3Refactor specifications and code
4Create Release
5Finish interceptors
6Send part of command to interceptors
7Line Interceptors
8Finish process after some time
9Documetation Diagram
10Technical Summary
11Create dotnet tool
( Description : SideCar for CLI applications. Interceptors for Line, Finish, Timer . See Code )

For the SideCarCLI I want the interceptors ( line, finish , timer) to receive parts of the command line of the original application. But how to parse the command line and how to pass to the interceptors ?  RegEx to the rescue!

I will let the user define the command line of the starting application and parse the command line with his own regex.

For example , if he put as arguments

x=y z=t

a possible regex  will be

(?<FirstArg>\w+)=((\w+)) (?<LastArg>\w+)=((\w+))

Also, if the starting application is ping.exe and the command line is

-n 20 \”\”

then a possible regex to have the site is

(?<FirstArg>.+) (?<site>.+)

Then , in the interceptors , I will put

“LineInterceptors”: [
“Name”: “WindowsStandardWindowsOutputInterceptor”,
“Arguments”: “/c echo \”{site} {line}\””,
“FullPath”: “cmd.exe”,
“FolderToExecute”: null,
“InterceptOutput”: true

and  will replace the

  “Arguments”: “/c echo \”{site} {line}\””,

with the


parsed from regex.

The code is pretty simple . As inputs, we have this.regEx for the regex and this.Arguments for the command line

var regex = new Regex(this.regEx);
var names = regex.
Where(it => !int.TryParse(it, out var _)).

var matches = regex.Matches(this.Arguments);
if (matches.Count == 0)
throw new ArgumentException($” the regex {regEx} has no matches for {Arguments}”);

var m = matches.FirstOrDefault();
foreach(var g in names)
if (m.Groups[g].Success)
throw new ArgumentException($”cannot find {g}  in regex {regEx} when parsing {Arguments}”);

That’s all! You can find code at