public static CommandLine Parse(string commandLine) { if (String.IsNullOrEmpty(commandLine)) { return(null); } var args = commandLine.Split(' ') .Select(x => x.Trim()) .Where(x => !String.IsNullOrEmpty(x)) .ToList(); if (args.Count == 0) { return(null); } if (args[0] == "-") { throw new InvalidOperationException("Char '-' must be followed by command or option name."); } var cmdLine = new CommandLine(args[0].Substring(1)); for (var i = 1; i < args.Count; i++) { var arg = args[i]; if (arg.StartsWith("-")) { cmdLine.Options = CommandOptionCollection.Parse(args.Skip(i).ToList()); break; } else { cmdLine.Parameters.Add(arg); } } return(cmdLine); }