Personal tools

Command line option parsers

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(convert package list to table)
(optparse-applicative on error messages)
 
(7 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
! Package !! Multi-mode !! Extensions !! Remark
 
! Package !! Multi-mode !! Extensions !! Remark
 
|-
 
|-
| {{HackagePackage|id=cmdargs}} || X || ? || <hask>unsafePerformIO</hask>
+
| {{HackagePackage|id=argparser}} || - || None (though it depends on package containers, which uses extensions) ||
 
|-
 
|-
| {{HackagePackage|id=cmdlib}}
+
| {{HackagePackage|id=cmdargs}} || X || TemplateHaskell, SYB generics, ViewPatterns, ... || <hask>unsafePerformIO</hask>
 
|-
 
|-
| {{HackagePackage|id=cmdtheline}}
+
| {{HackagePackage|id=cmdlib}} || X || SYB generics || based on [[GetOpt]]
 
|-
 
|-
| {{HackagePackage|id=console-program}}
+
| {{HackagePackage|id=cmdtheline}} || X || FlexibleInstances (although unnecessary) || shows help as man-page
 
|-
 
|-
| {{HackagePackage|id=getflag}}
+
| {{HackagePackage|id=console-program}} || X || (none) || configure options via files
 
|-
 
|-
| {{HackagePackage|id=hflags}}
+
| {{HackagePackage|id=getflag}} || - || Haskell98 || like [[GetOpt]] but with Unix/Plan 9 option syntax
 
|-
 
|-
| {{HackagePackage|id=multiarg}}
+
| {{HackagePackage|id=hflags}} || - || TemplateHaskell || inspired by Google's gflags, provides parsed options in top-level variables, allow to set options via environment variables
 
|-
 
|-
| {{HackagePackage|id=options}}
+
| {{HackagePackage|id=multiarg}} || - || CPP || long options with multiple arguments
 
|-
 
|-
| {{HackagePackage|id=optparse-applicative}}
+
| {{HackagePackage|id=options}} || X || TemplateHaskell ||
 
|-
 
|-
| {{HackagePackage|id=parseargs}}
+
| {{HackagePackage|id=optparse-applicative}} || X || GADT || Applicative Functor; for wrong arguments it does not show a specific error message but the general usage pattern
 
|-
 
|-
| {{HackagePackage|id=ReadArgs}}
+
| {{HackagePackage|id=parseargs}} || - || FlexibleInstances (although unnecessary) || supports a fixed set of argument types: <hask>Int, Integer, Float, Double, String, FileOpener</hask>
 
|-
 
|-
| {{HackagePackage|id=simpleargs}}
+
| {{HackagePackage|id=ReadArgs}} || - || OverlappingInstances, TypeOperators || No options, only arguments. The argument template is derived from the requested argument tuple.
 
|-
 
|-
| {{HackagePackage|id=yaop}}
+
| {{HackagePackage|id=simpleargs}} || - || OverlappingInstances (although unnecessary) || the same as ReadArgs
  +
|-
  +
| {{HackagePackage|id=yaop}} || - || TemplateHaskell, GeneralizedNewtypeDeriving || wrapper around GetOpt
 
|}
 
|}
  +
  +
The column for required Haskell extensions gives an idea of how easy it is to port the package to compilers other than [[GHC]].
  +
   
 
[[Category:Packages]]
 
[[Category:Packages]]

Latest revision as of 09:01, 26 October 2013

There are several packages that want to simplify the task of writing command line parsers. Unfortunately, they are distributed across several Hackage categories. Here is an attempt to list them:

Package Multi-mode Extensions Remark
argparser - None (though it depends on package containers, which uses extensions)
cmdargs X TemplateHaskell, SYB generics, ViewPatterns, ...
unsafePerformIO
cmdlib X SYB generics based on GetOpt
cmdtheline X FlexibleInstances (although unnecessary) shows help as man-page
console-program X (none) configure options via files
getflag - Haskell98 like GetOpt but with Unix/Plan 9 option syntax
hflags - TemplateHaskell inspired by Google's gflags, provides parsed options in top-level variables, allow to set options via environment variables
multiarg - CPP long options with multiple arguments
options X TemplateHaskell
optparse-applicative X GADT Applicative Functor; for wrong arguments it does not show a specific error message but the general usage pattern
parseargs - FlexibleInstances (although unnecessary) supports a fixed set of argument types:
Int, Integer, Float, Double, String, FileOpener
ReadArgs - OverlappingInstances, TypeOperators No options, only arguments. The argument template is derived from the requested argument tuple.
simpleargs - OverlappingInstances (although unnecessary) the same as ReadArgs
yaop - TemplateHaskell, GeneralizedNewtypeDeriving wrapper around GetOpt

The column for required Haskell extensions gives an idea of how easy it is to port the package to compilers other than GHC.