sbergot / ArgParser

BSD 3-Clause "New" or "Revised" License
9 stars 2 forks source link

Multiple parsing artifacts #1

Open firegurafiku opened 10 years ago

firegurafiku commented 10 years ago

I was playing around with you library and wrote simple test program after you example in package documentation. It parses two flags and a variable number of positional arguments:

import System.Console.ArgParser

data MyTest = MyTest Bool Bool [String]
    deriving (Show)

myTestParser :: ParserSpec MyTest
myTestParser = MyTest
    `parsedBy` boolFlag "common-mode"
    `andBy`    boolFlag "docbook-mode"
    `andBy`    posArgs  "files" [] (\xs x -> xs ++ [x])

main = withParseResult myTestParser print

I've successfully compiled it and run several times and found that for me it works in a very misleading way:

$ ./Main  1 2 3
MyTest False False ["1","2","3"]
# As expected.

$ ./Main --common-mode -- 1 2 3
MyTest True False []
# As expected.

$ ./Main --common-mode 1 2 3
unexpected parameter(s)
# Expected: MyTest True False ["1", "2", "3"]

$ ./Main --unknown 1 2 3
MyTest False False []
# Expected: error message.

$ ./Main --help 1 2 3
MyTest False False []
# Expected: help message.

Also, if two flags are named starting with the same letter, they share their short form which is not possible in principle:

$ ./Main --help 
Main
usage : Main [-t] [-t] [files...] [-h] [--version]

mandatory arguments:
 files

optional arguments:
 -t, --to-docbook # <--- ???
 -t, --to-common  # <--- ???
 -h, --help                    show this help message and exit
 --version                     print the program version and exit

I'm very sorry if I've missed some points in documentation and artifacts above are not really bugs. Here is the package version:

$ cabal info argparser
* argparser        (library)
    Synopsis:      Command line parsing framework for console applications
    Versions available: 0.3.1, 0.3.2, 0.3.3
    Versions installed: 0.3.3
    Homepage:      [ Not specified ]
    Bug reports:   [ Not specified ]
    Description:   Provides a combinator library for defining a command line
                   parser.
    Category:      Console
    License:       BSD3
    Author:        Simon Bergot <simon.bergot@gmail.com>
    Maintainer:    Simon Bergot <simon.bergot@gmail.com>
    Source repo:   https://github.com/sbergot/ArgParser
    Dependencies:  base >=4.0 && <5, containers -any, argparser -any,
                   HUnit -any, containers -any, HTF >0.9, base >=4
    Documentation: [ Not installed ]
    Cached:        Yes
    Modules:
        System.Console.ArgParser
        System.Console.ArgParser.ArgsProcess
        System.Console.ArgParser.BaseType
        System.Console.ArgParser.Format
        System.Console.ArgParser.Params
        System.Console.ArgParser.Parser
        System.Console.ArgParser.QuickParams
        System.Console.ArgParser.Run
        System.Console.ArgParser.SubParser
sbergot commented 9 years ago

sorry for this late reply. Many of those points are valid bugs. In fact I will add your cases in my unit tests.

To be honest I haven't written a command line app for some time. Do you know what is the classic way to deal with flags starting with the same letters?

sbergot commented 9 years ago

@firegurafiku I have fixed the first issues, although error message are not always perfect. I am currently thinking about the doc issue.