cmdargs icon indicating copy to clipboard operation
cmdargs copied to clipboard

Ability to change the value of defaultWrap

Open ozgurakgun opened this issue 10 years ago • 6 comments

As the title says, I'd like to be able to change the value of defaultWrap in my program. I know I can pass, for example, --help=120 if I wanted to but I want to change the default, which is currently 80.

I am not sure how portable or worth the effort this is, but the terminal-size library or something similar could also be nice.

This becomes particularly important when a program has a lot of command line flags and long descriptions for each of them.

As a side issue/question, line-breaks seem to be dropped from the help text. What's the reason for that?

Thanks for the great library!

ozgurakgun avatar Nov 05 '14 16:11 ozgurakgun

If I integrated terminal-size, would you still want to set the default wrap? That might be a nicer way to go.

When you say line breaks are dropped from help text, you mean within descriptions? I suspect I split into words, and just never considered what happened if the separator was not a space. Certainly something that is fixable.

ndmitchell avatar Nov 06 '14 20:11 ndmitchell

Currently I cannot see why I would want to be able to change the value of default warp if terminal-size were to be integrated. But if it is easy enough, why not offer both? The default wrap option can be useful when/if terminal-size isn't supported on a platform. It probably doesn't work on Windows...

And with the line breaks, yes I mean the descriptions. The string that is passed to help.

ozgurakgun avatar Nov 06 '14 21:11 ozgurakgun

I am intending to fix terminal-size on Windows for another project, so that won't be an issue: https://github.com/biegunka/terminal-size/issues/3

It's usually easier not to provide something, since as soon as I provide it I have to keep it working forever, I have to figure out how it interacts with terminal-size (which takes preference) etc. If there's a good use case, I'm happy to, but without a use case its easier to leave it out for now.

Can you give me an example of which help string you mean? Just the few lines with your newlines in help. You can put help on flags, modes and the whole program. I suspect it's flags that are giving you issues, but I'd like to be sure, and use your particular example as a test case.

ndmitchell avatar Nov 06 '14 21:11 ndmitchell

teminal-size integration alone will make me happy.

About the help-text, here is what I mean. (I probably should have created a separate issue for this, sorry.)

{-# LANGUAGE DeriveDataTypeable #-}
{-# OPTIONS_GHC -fno-cse #-}

module Main where

-- cmdargs-0.10.12
import System.Console.CmdArgs

data Program = Program { someFile :: FilePath }
    deriving (Eq, Ord, Show, Data, Typeable)

ui :: Program
ui = Program
    { someFile = def &= help "Help line 1\n\
                             \Help line 2."
    } &= help "Some more\ntext."

main :: IO ()
main = cmdArgs ui >>= print

The output I get is the following.

$ ghc -O2 repro.hs && ./repro --help
[1 of 1] Compiling Main             ( repro.hs, repro.o )
Linking repro ...
The program program

program [OPTIONS]
  Some more text.

Common flags:
  -s --somefile=ITEM  Help line 1 Help line 2.
  -? --help           Display help message
  -V --version        Print version information

ozgurakgun avatar Nov 06 '14 21:11 ozgurakgun

The new version of terminal-size now works on Windows, which means using terminal-size by default for the help width should work.

I've split out the newline thing into #18 and will track it there. Generally, it's very easy for me to split/merge bugs, but impossible for me to fix bugs people don't report, so I'm grateful for the bug reports however they arrive. Thanks for taking the time to report it!

ndmitchell avatar Nov 07 '14 20:11 ndmitchell

Any updates on using terminal-size for this?

ozgurakgun avatar May 21 '16 14:05 ozgurakgun