using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main()
var CliInput=new ParsedOptions();
string argline="-f \"terefere kukuryku\" -n \"Ethernet \"20\" 1\" -d \"a b c\"";
argline=argline.Replace("\"", "");
string[] args = Regex.Split(argline, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
var parser = new CommandLine.Parser(with=>
var result=parser.ParseArguments<Options>(args);
result.WithParsed(opts =>
Console.WriteLine(CliInput.ToString());
var helpText = HelpText.AutoBuild(result, h =>
Console.WriteLine($"Error: {e.Message}. \nType 'execName -h' for help.");
static void HandleErrors(IEnumerable<Error> errors) {
Console.WriteLine("Command line parsing error!");
foreach (var error in errors) {
switch((CommandLine.ErrorType)error.Tag) {
case CommandLine.ErrorType.UnknownOptionError: {
var err = (CommandLine.UnknownOptionError)error;
Console.WriteLine($"Error: Unknown option: '-{err.Token}'");
case CommandLine.ErrorType.MissingValueOptionError: {
var err = (CommandLine.MissingValueOptionError)error;
Console.WriteLine($"Error: Missing value for '-{err.NameInfo.ShortName}'");
case CommandLine.ErrorType.MissingRequiredOptionError:{
var err = (CommandLine.MissingRequiredOptionError)error;
Console.WriteLine($"Error: Missing required option for '-{err.NameInfo.ShortName}' (could be caused also by improper quotation marks placing)");
Console.WriteLine($"Error: '{error.Tag}' (could be caused also by improper quotation marks placing)");
string execName="<tu wstawić nazwę execa>";
Console.WriteLine($"Type '{execName} -h' for help.");
[Option('d', HelpText="Space separated IPv4 addresses")]
public IEnumerable<string> Data { get; set; }
[Option('n', HelpText = "Network Interface name")]
public IEnumerable<string> Nic { get; set; }
[Option('f', Required = true, HelpText = "Target firmware path")]
public IEnumerable<string> TargetFirmwarePath { get; set; }
public class ParsedOptions
public string NicName {get; set;}
public List<string> Devices {get; set;}
public string TargetFirmwarePath {get; set;}
this.Devices=new List<string>();
public void SetOpts(Options options) {
NicName=string.Join(" ",options.Nic).Replace("\"", string.Empty);
foreach (var IpAddr in options.Data) {
TargetFirmwarePath=string.Join(" ",options.TargetFirmwarePath);
public override string ToString()
return string.Join(", ", new string[]{
string.Format("NicName= {0}", this.NicName),
string.Format("Devices= [{0}]", string.Join(", ", this.Devices)),
string.Format("TargetFirmwarePath= {0}", this.TargetFirmwarePath)