public static CommandLineParameters Parse(string[] args) { var clp = new CommandLineParameters(); clp.DoParse(args); return(clp); }
/// <summary> /// Parses the specified string arguments into a new instance of the Options class. /// </summary> /// <param name="args">The arguments to parse.</param> /// <returns>A new instance of the Options class initialized from the specidifed string arguments</returns> /// <exception cref="ArgumentException">There is an error parsing an argument.</exception> public static Options Parse(string[] args) { var parameters = CommandLineParameters.Parse(args); var options = CreateOptions(parameters); CheckForInvalidParameters(parameters); return(options); }
private static void CheckForInvalidParameters(CommandLineParameters parameters) { if (parameters.Named.Count > 0) { foreach (var name in parameters.Named.Keys) { throw new ArgumentException("Invalid option /" + name); } } if (parameters.Positionals.Count > 0) { throw new ArgumentException(string.Format("Invalid argument \"{0}\"", parameters.Positionals[0])); } }
private static Options CreateOptions(CommandLineParameters parameters) { var options = new Options(); options.HelpWanted = parameters.DetachNamedBool("?"); if (options.HelpWanted) { return options; } options.DirectoryPath = parameters.DetachPositional(); options.Filter = parameters.DetachNamed("f"); options.EnableColorSchema = !parameters.DetachNamedBool("nc"); options.ColorSchemaName = parameters.DetachNamed("c"); if (!options.EnableColorSchema && !string.IsNullOrEmpty(options.ColorSchemaName)) { throw new ArgumentException("Options nc and c are incompatible with each other"); } return options; }
private static Options CreateOptions(CommandLineParameters parameters) { var options = new Options(); options.HelpWanted = parameters.DetachNamedBool("?"); if (options.HelpWanted) { return(options); } options.DirectoryPath = parameters.DetachPositional(); options.Filter = parameters.DetachNamed("f"); options.EnableColorSchema = !parameters.DetachNamedBool("nc"); options.ColorSchemaName = parameters.DetachNamed("c"); if (!options.EnableColorSchema && !string.IsNullOrEmpty(options.ColorSchemaName)) { throw new ArgumentException("Options nc and c are incompatible with each other"); } return(options); }
public static CommandLineParameters Parse(string[] args) { var clp = new CommandLineParameters(); clp.DoParse(args); return clp; }