private void AppendArguments(ConsoleStringBuilder sb) { const int optionBaseIndentation = 2; const int textIndentation = 32; const int aliasLength = 2; //-A const string aliasSeparator = ", "; // TODO: add [required] keyword foreach (var argument in explicitArguments) { var line = new string(' ', optionBaseIndentation); if (argument.GetAlias() != 0) { line += $"-{argument.GetAlias()}"; } if (!string.IsNullOrEmpty(argument.GetAction())) { line += argument.GetAlias() == 0 ? new string(' ', aliasLength + aliasSeparator.Length) : aliasSeparator; line += argument.GetAction() + " "; } line += new string(' ', textIndentation - line.Length); // TODO might be too long. if (argument.IsRequired()) { line += "[required] "; } if (!string.IsNullOrEmpty(argument.GetHelp())) { line += argument.GetHelp(); } sb.AppendLine(line, textIndentation); } }
public string ToString(int lineWidth = 80) { var appName = Assembly.GetExecutingAssembly().GetName().Name; var sb = new ConsoleStringBuilder(lineWidth); sb.Append($"Usage: {appName} "); if (actions.Count > 0 || actions.Count > 0) { sb.Append("[OPTION]... "); } if (positionalArguments.Count > 0) { sb.Append(PositionalToString()); } sb.AppendLine(); sb.AppendLine(); if (explicitArguments.Count > 0) { sb.AppendLine("Mandatory arguments to long options are mandatory for short options too."); // NOTE: might be optional? AppendArguments(sb); sb.AppendLine(); sb.AppendLine(); } var manualAttribute = typeof(T).GetCustomAttribute <CommandManualAttribute>(); if (manualAttribute != null) { sb.AppendLine(manualAttribute.Description); sb.AppendLine(); } return(sb.ToString()); }