/// <summary> /// Generates a CommandLine instance from the provided string /// </summary> /// <param name="cmdLine">Command line string</param> /// <returns>The command line instance parsed from cmdLine</returns> public static CommandLine FromString(string cmdLine) { cmdLine = (cmdLine == null) ? string.Empty : cmdLine; var splitCommandLine = CommandLineArgExtensions.SplitCommandLine(cmdLine); return(new CommandLine( splitCommandLine.FirstOrDefault(), splitCommandLine.Skip(1) )); }
/// <summary> /// Normalizes the file path and adds quotes should the path not be quoted already /// </summary> /// <param name="filePath">The path to notmalized</param> /// <returns>A normalized file path</returns> private static string NormalizePath(string filePath) { var path = filePath?.Trim(); // Invalid input, return immediately if (string.IsNullOrEmpty(path)) { return(path); } const char mark = '"'; // If the path is already quoted, leave as is if (CommandLineArgExtensions.IsQuoted(path, mark)) { return(path); } return(path.Contains(' ') ? (mark + path + mark) : path); }