-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatting help text (ends of line) #529
Comments
You need not to use Rendering methods, only configure HelpText and set:
Wiki is updated to include new page: HelpText Configuration for generating custom help with examples that you can run online. |
Thank you very much. |
Is there a way to cut the empty lines from Default parser? Using the HelpText it works, but there's a different behavior. I am using a method for parsing subverbs, which works fine. If I use a single --help with Default parser, it shows the available verbs. But if I use HelpText.AutoBuild() setting AdditionalNewLineAfterOption = false, the single --help command won't show the available verbs. |
@moh-hassan, I confirm this works (tested with VB.NET). |
@downwater |
@leoformaggi |
@moh-hassan, I just realized I'm experiencing the same issue as @leoformaggi , but I didn't yet dig into it. I started from your sample to write the one below to show up the case:
Calling the program with
|
@downwater, @leoformaggi |
@moh-hassan, thank you for this first feedback. |
@downwater, @leoformaggi
Click to expand source code!// @nuget: CommandLineParser -Version 2.7.0-preview1
using System;
using System.Collections.Generic;
using CommandLine;
using CommandLine.Text;
public class Program
{
public static void Main()
{
StartUp("--help");
StartUp("--help write");
StartUp("write --dummy"); // Option 'dummy' is unknown
}
static void StartUp(string command)
{
Console.WriteLine($"------Args: '{command}' -------");
var args = command.Split();
var parser = new CommandLine.Parser(with => with.HelpWriter = null);
var parserResult = parser.ParseArguments<ReadOptions, WriteOptions>(args);
parserResult.WithParsed<ReadOptions>(options => Run(options)).WithParsed<WriteOptions>(options => Run(options)).WithNotParsed(errs => DisplayHelp(parserResult));
}
static void DisplayHelp<T>(ParserResult<T> result)
{
var helpText = HelpText.AutoBuild(result, h =>
{
h.AdditionalNewLineAfterOption = false; //remove the extra newline between options
h.Heading = "MyVerbApp 2.0.0-beta"; //change header
h.Copyright = "Copyright (c) 2019 Global.com"; //change copyrigt text
return h;
}
);
Console.WriteLine(helpText);
}
static void Run(WriteOptions options)
{
}
static void Run(ReadOptions options)
{
}
}
[Verb("read", HelpText = "Reads from source.")]
class ReadOptions
{
[Option("path", Default = false, HelpText = "Source path")]
public bool path
{
get;
set;
}
}
[Verb("write", HelpText = "Writes to destination.")]
class WriteOptions
{
[Option("path", Default = false, HelpText = "Destination path")]
public bool path
{
get;
set;
}
} Click to expand Help Screen!
|
@moh-hassan |
@moh-hassan, using the current release (2.7.82) and following the new code sample, it works. A last detail though. If the description of a parameter is longer than the console width, it returns to the line of course, but after two line feeds:
|
@downwater public static HelpText AutoBuild<T>(ParserResult<T> parserResult, Func<HelpText, HelpText> onError, int maxDisplayWidth = DefaultMaximumLength)
//change maxDisplayWidth to 120.
var helpText = HelpText.AutoBuild(result, h => {..}, 120);
```cs |
@moh-hassan I don't really understand (sorry), I was talking about word wrap. The HelpText object succeeds to perform word wrap with a correct left indentation, but adds an extra newline. Increasing
|
@moh-hassan I tested release 2.7.82 and it solved my problem like a charm. Thank you for the update. |
@leoformaggi |
@downwater, |
After several tries, the first issue seems to reproduce if the following conditions are fulfilled:
To reproduce:
Tested with Visual Studio 2010 on Windows Server 2008 Entreprise SP2 and Command Line Parser 2.7.82. |
It seems that the boundary of 80 column cause this issue
I couldn't catch this issue in xunit test. @NeilMacMullen |
@moh-hassan I believe the issue occurs because TextWrapper.WrapAndIndextText treats the supplied number of columns as the number available for non-whitespace but then appends a newline when converting back to a single string so in the case that we've wrapped to N columns and the line is exactly N characters long, the additional newline will push it to N+1 and the console behaviour is to wrap the line at the Nth character and "display" the newline on the following line. There are are a few alternate fixes:
Unfortunately I'm too busy to fix this myself but my suggested fix would be option 1 which is a trivial code fix that just requires some tedious test changes. Note though that TextWrapper is not the only thing that formats text and it's possible things like the copyright display also suffer from this problem. |
Thanks @NeilMacMullen for reply and suggestions. |
The command line wiki shows what help texts look like:
Each argument entry is followed by a double end of line. I wondered if there is a simple way to get a formatting with single eol, like this
grep
example:If I undestand correctly, I'll have to implement my own help screen and use
HelpText.RenderUsageText
orHelpText.RenderUsageTextAsLines
?The text was updated successfully, but these errors were encountered: