/// <summary> /// Generates help text based on custom arguments class /// </summary> internal static string Usage() { IDictionary <string, ArgumentData> data = ArgumentParserUtils.GetArgumentData <T>(); DetailsAttribute detailsAttr = typeof(T).GetCustomAttribute <DetailsAttribute>(); string details = detailsAttr != null ? detailsAttr.Details : string.Empty; ITemplate template = new CommandLineUsage { Name = Process.GetCurrentProcess().ProcessName, Description = details, Required = data.Values.Where(x => !x.Optional).Distinct(), Optional = data.Values.Where(x => x.Optional).Distinct(), }; return(template.Print()); }
/// <summary> /// Returns an instance of custom parameters class /// </summary> /// <param name="arg">List of arguments to parse</param> /// <returns>Parsed arguments</returns> public static T Parse(string[] arg) { var parser = new ArgumentParser <T>(arg, ArgumentParserUtils.GetArgumentData <T>()); if (!parser.Parse()) { // TODO: Remove calls to PrintUsage from consumers and uncomment below //if(parser.NeedHelp) //{ // PrintUsage(); //} return(default(T)); } return(parser.Result); }