ndmitchell / cmdargs

Haskell library for command line argument processing
Other
91 stars 12 forks source link

Does not print help message for all options with the same help message in multiple modes #46

Closed ki11men0w closed 7 years ago

ki11men0w commented 7 years ago

I found that if in different modes there are options with the same help message then all options lacks this message except the first one. It is my test case program:

{-# LANGUAGE DeriveDataTypeable #-}
module Main where

import System.Console.CmdArgs

data Flags = Mode1 { opt1 :: Bool }
           | Mode2 { opt2 :: Bool }
           | Mode3 { opt3 :: Bool }
             deriving (Data, Typeable, Show)

commonHelpMessage = "Common help message"

mode1 = Mode1 { opt1 = def &= help commonHelpMessage }
mode2 = Mode2 { opt2 = def &= help commonHelpMessage }
mode3 = Mode3 { opt3 = def &= help commonHelpMessage }

main :: IO ()
main = do
  cmdArgs $ modes [mode1, mode2, mode3]
  return ()

and when running with a single option of --help the program prints to STDOUT:

The flags program

flags [COMMAND] ... [OPTIONS]

Common flags:
  -? --help     Display help message
  -V --version  Print version information

flags mode1 [OPTIONS]

  -o --opt1     Common help message

flags mode2 [OPTIONS]

  -o --opt2   

flags mode3 [OPTIONS]

  -o --opt3 

This error is reproduced with cmdargs=0.10.17 on Ubuntu 16.04. Just in case I created this repo for reproduction of the error.

ndmitchell commented 7 years ago

If you add {-# OPTIONS_GHC -fno-cse #-} does that solve the issue?

On Wed, 30 Aug 2017 at 1:37 am, Maksim Golubev notifications@github.com wrote:

I found that if in different modes there are options with the same help message then all options lacks this message except the first one. It is my test case program:

{-# LANGUAGE DeriveDataTypeable #-}module Main where import System.Console.CmdArgs data Flags = Mode1 { opt1 :: Bool } | Mode2 { opt2 :: Bool } | Mode3 { opt3 :: Bool } deriving (Data, Typeable, Show)

commonHelpMessage = "Common help message"

mode1 = Mode1 { opt1 = def &= help commonHelpMessage } mode2 = Mode2 { opt2 = def &= help commonHelpMessage } mode3 = Mode3 { opt3 = def &= help commonHelpMessage } main :: IO () main = do cmdArgs $ modes [mode1, mode2, mode3] return ()

and when running with a single option of --help the program prints to STDOUT:

The flags program

flags [COMMAND] ... [OPTIONS]

Common flags: -? --help Display help message -V --version Print version information

flags mode1 [OPTIONS]

-o --opt1 Common help message

flags mode2 [OPTIONS]

-o --opt2

flags mode3 [OPTIONS]

-o --opt3

This error is reproduced with cmdargs=0.10.17 on Ubuntu 16.04. Just in case I created this https://github.com/ki11men0w/cmdargs-case repo for reproduction of the error.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ndmitchell/cmdargs/issues/46, or mute the thread https://github.com/notifications/unsubscribe-auth/ABkx_c0_hgxEQKq7CEfLKhtNqdy4vdQIks5sdK64gaJpZM4PGuIb .

ki11men0w commented 7 years ago

Yes, disabling CSE optimisation solves the problem.

Thank you!