private string Usage(Type type) { VerbAttribute verbAttr = type.GetCustomAttributes <VerbAttribute>().FirstOrDefault(); var options = OptionsClassProcessor.GetOptions(type); var values = OptionsClassProcessor.GetValues(type); var restOfInput = OptionsClassProcessor.GetRestOfInputProperty(type); StringBuilder result = new StringBuilder(); if (verbAttr != null) { result.AppendLine(verbAttr.HelpText.SplitToLines(LineWidth + 20, 0) + Environment.NewLine); } foreach (var option in options.Values) { result.AppendFormat("{0,-20} {1}" + Environment.NewLine, (option.IsShortOption ? "-" : "--") + option.Option, option.Description.SplitToLines(LineWidth, PrepadSpaces)); } foreach (var value in values.Values.OrderBy(v => v.Index)) { result.AppendFormat("#{0,-19} {1}" + Environment.NewLine, value.Index, value.Description.SplitToLines(LineWidth, PrepadSpaces)); } if (restOfInput != null) { result.AppendFormat("{0,-20} {1}" + Environment.NewLine, "rest of input", restOfInput.Item2.Description.SplitToLines(LineWidth, PrepadSpaces)); } return(result.ToString()); }
private static ParseResult <object> SetRestOfInputPropertyIfAvailable(Type type, object instance, Tokenizer tokenizer) { var restOfInputProp = OptionsClassProcessor.GetRestOfInputProperty(type); if (restOfInputProp != null) { if (restOfInputProp.Item2.Required && tokenizer.AtEnd) { return(ParseResult <object> .WithError("A value for the property '" + restOfInputProp.Item1.Name + "' is missing")); } restOfInputProp.Item1.SetValue(instance, tokenizer.RestOfInput); } return(null); // No error }