parseargs 0.2 → 0.2.0.1
raw patch · 5 files changed
+43/−36 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- COPYING +3/−1
- README.md +8/−5
- System/Console/ParseArgs.hs +20/−26
- parseargs-example.hs +6/−2
- parseargs.cabal +6/−2
COPYING view
@@ -1,4 +1,6 @@-Copyright © 2008 Bart Massey+Copyright © 2007 Bart Massey++[This program is licensed under the "3-clause ('new') BSD License"] Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
README.md view
@@ -1,6 +1,5 @@-# parseargs-Command-line argument parsing for Haskell programs -Bart Massey <bart@cs.pdx.edu>+# parseargs: Command-line argument parsing for Haskell programs+Copyright © 2007 Bart Massey This library provides System.Console.Parseargs, a module to assist in argument parsing for Haskell stand-alone command@@ -43,6 +42,9 @@ namespace. This allows the use of the name `args` by the user to describe program arguments. +The 0.2.0.1 release cleans up a bunch of documentation nits+and cleans up copyright notices and license information.+ This library is not what I set out to build. It definitely could also use some work. However, I use it all the time for writing little programs. I thought others might find it@@ -51,5 +53,6 @@ Have fun with it, and let me know if there are problems. -This code is released under a "3-clause BSD" license. Please-see the file COPYING in this distribution for license terms.+This program is licensed under the "3-clause ('new') BSD+License". Please see the file COPYING in this distribution+for license terms.
System/Console/ParseArgs.hs view
@@ -1,18 +1,9 @@ {-# LANGUAGE FlexibleInstances, DeriveDataTypeable #-}--- Full-featured argument parsing library for Haskell programs--- Bart Massey <bart@cs.pdx.edu>---- Copyright © 2007-2010 Bart Massey--- ALL RIGHTS RESERVED+-- Copyright © 2007 Bart Massey+-- This program is licensed under the "3-clause ('new') BSD License".+-- Please see the file COPYING in this distribution for license terms. --- You can redistribute and/or modify this library under the--- terms of the "3-clause BSD LICENSE", as stated in the file--- COPYING in the top-level directory of this distribution.--- --- This library is distributed in the hope that it will be--- useful, but WITHOUT ANY WARRANTY; without even the--- implied warranty of MERCHANTABILITY or FITNESS FOR A--- PARTICULAR PURPOSE.+-- Full-featured argument parsing library for Haskell programs -- |This module supplies an argument parser. -- Given a description of type [`Arg`] of the legal@@ -28,11 +19,11 @@ -- supplied as a list of `Arg` records, built up -- using the functions described here. Arg(..),- Argtype(..), + Argtype(..), ArgsComplete(..), ArgsDash(..),- ArgsParseControl(..), APCData(..),+ ArgsParseControl(..), -- ** DataArg and its pseudo-constructors DataArg, argDataRequired, argDataOptional, argDataDefaulted,@@ -85,10 +76,8 @@ -- for positional data arguments. -- -- There are two cases:--- -- (1) The argument is a flag, in which case at least -- one of `argAbbr` and `argName` is provided;--- -- (2) The argument is positional, in which case neither -- `argAbbr` nor `argName` are provided, but `argData` is. -- @@ -104,7 +93,7 @@ , argName :: Maybe String -- ^\"Long name\" of flag. , argData :: Maybe DataArg -- ^Datum description. , argDesc :: String -- ^Documentation for the argument.- } + } -- |The types of an argument carrying data. The constructor@@ -292,7 +281,7 @@ keymap_from_list l = foldl add_entry Map.empty l where- add_entry m (k, a) = + add_entry m (k, a) = case Map.member k m of False -> Map.insert k a m True -> argdesc_error ("duplicate argument description name " ++@@ -336,7 +325,9 @@ -- |Record containing the collective parse control information. data ArgsParseControl = ArgsParseControl {+ -- |Level of completeness of parse. apcComplete :: ArgsComplete,+ -- |Handling of dashes in parse. apcDash :: ArgsDash } -- |Class for building parse control information,@@ -438,7 +429,7 @@ posn_args = filter arg_posn argd n = maximum (map (length . arg_string) argd) --- top (summary) line- summary_line = + summary_line = "usage: " ++ prog_name ++ perhaps (not (null flag_args))@@ -454,7 +445,7 @@ arg_lines = concatMap (arg_line n) argd where arg_line na a = let s = arg_string a in- " " ++ s ++ + " " ++ s ++ replicate (na - (length s)) ' ' ++ " " ++ argDesc a ++ "\n" --- simple recursive-descent parser@@ -466,22 +457,22 @@ parse usage name_hash abbr_hash (am, posn, rest) av@(aa : aas) = case aa of "--" -> case getAPCData apcData of- ArgsParseControl ArgsComplete ArgsHardDash -> + ArgsParseControl ArgsComplete ArgsHardDash -> parseError usage ("unexpected -- " ++ "(extra arguments not allowed)") _ -> ([], (am, posn, (rest ++ aas)))- s@('-' : '-' : name) + s@('-' : '-' : name) | isJust (Map.lookup name name_hash) || apcDash (getAPCData apcData) == ArgsHardDash -> case Map.lookup name name_hash of- Just ad -> + Just ad -> let (args', am') = peel s ad aas in (args', (am', posn, rest)) Nothing -> case getAPCData apcData of ArgsParseControl ArgsInterspersed _ -> (aas, (am, posn, rest ++ ["--" ++ name]))- _ -> + _ -> parseError usage ("unknown argument --" ++ name) ('-' : abbr : abbrs)@@ -509,7 +500,7 @@ let (_, req_posn) = partition arg_optional posn in case length av - length req_posn of n_extra | n_extra > 0 || (n_extra == 0 && arg_required p) ->- let (args', am') = peel (dataArgName $ fromJust $ + let (args', am') = peel (dataArgName $ fromJust $ argData p) p av in (args', (am', ps, rest)) 0 -> (av, (am, ps, rest))@@ -574,16 +565,19 @@ -- |Type of values that can be parsed by the argument parser. class ArgType b where+ -- |Fetch an argument's value if it is present. getArg :: (Show a, Ord a) => Args a -- ^Parsed arguments. -> a -- ^Index of argument to be retrieved. -> Maybe b -- ^Argument value if present.+ -- |Fetch the value of a required argument. getRequiredArg :: (Show a, Ord a) => Args a -- ^Parsed arguments. -> a -- ^Index of argument to be retrieved. -> b -- ^Argument value.+ getRequiredArg ads index = case getArg ads index of Just v -> v
parseargs-example.hs view
@@ -1,3 +1,7 @@+-- Copyright © 2010 Bart Massey+-- This program is licensed under the "3-clause ('new') BSD License".+-- Please see the file COPYING in this distribution for license terms.+ module Main where @@ -49,8 +53,8 @@ main :: IO () main = do- args <- parseArgsIO - (ArgsParseControl (ArgsTrailing "junk") ArgsSoftDash) + args <- parseArgsIO+ (ArgsParseControl (ArgsTrailing "junk") ArgsSoftDash) argd putStrLn "parse successful" when (gotArg args OptionFlag)
parseargs.cabal view
@@ -1,8 +1,12 @@+-- Copyright © 2010 Bart Massey+-- This work is licensed under the "3-clause ('new') BSD License".+-- Please see the file COPYING in this distribution for license terms.+ Name: parseargs Build-Type: Simple Description: Parse command-line arguments -- Don't forget to bump the source-repository this below-Version: 0.2+Version: 0.2.0.1 Cabal-Version: >= 1.6 License: BSD3 License-File: COPYING@@ -30,4 +34,4 @@ Source-repository this Type: git Location: git://github.com/BartMassey/parseargs.git- Tag: v0.2+ Tag: v0.2.0.1