/// <summary> /// Constructs a user-friendly usage string describing the command-line /// argument syntax. /// </summary> /// <param name="maxUsageWidth">Maximum width in characters for the /// usage text; used to wrap it.</param> /// <param name="commandName">Command name to display in the usage /// information.</param> /// <param name="options">Options for generating info.</param> /// <param name="destination">Destination object, optionally.</param> /// <returns>The constructed usage information string.</returns> public ColoredMultistring GetUsageInfo(int maxUsageWidth, string commandName, UsageInfoOptions options, object destination = null) { // Construct info for argument set. var info = new ArgumentSetUsageInfo { Name = commandName ?? AssemblyUtilities.GetAssemblyFileName(), Description = _argumentSet.Attribute.AdditionalHelp, DefaultShortNamePrefix = _argumentSet.Attribute.ShortNameArgumentPrefixes.FirstOrDefault() }; // Add parameters and examples. info.AddParameters(GetArgumentUsageInfo(destination)); if (_argumentSet.Attribute.Examples != null) { info.AddExamples(_argumentSet.Attribute.Examples); } // Update logo, if one was provided. if (_argumentSet.Attribute.LogoString != null) { info.Logo = _argumentSet.Attribute.LogoString; } // Compose remarks, if any. const string defaultHelpArgumentName = "?"; var namedArgPrefix = _argumentSet.Attribute.ShortNameArgumentPrefixes.FirstOrDefault(); if (_argumentSet.TryGetNamedArgument(defaultHelpArgumentName, out ArgumentDefinition ignored) && namedArgPrefix != null) { info.Remarks = string.Format(Strings.UsageInfoHelpAdvertisement, $"{info.Name} {namedArgPrefix}{defaultHelpArgumentName}"); } // Construct formatter and use it. HelpFormatter formatter; if (options.HasFlag(UsageInfoOptions.VerticallyExpandedOutput)) { formatter = new PowershellStyleHelpFormatter(); } else { formatter = new CondensedHelpFormatter(); } formatter.MaxWidth = maxUsageWidth; formatter.Options = options; return(formatter.Format(info)); }