Skip to content
Browse files

cleaning up cabal file and readme

  • Loading branch information...
1 parent 7ea3d7a commit 0ca2c561e5a5cfe3578d40c45d49853794b5c0df @rampion committed
Showing with 98 additions and 37 deletions.
  1. +0 −3 README
  2. +50 −0 README.md
  3. +48 −34 ReadArgs.cabal
View
3 README
@@ -1,3 +0,0 @@
-This is a simple library for command line argument parsing for haskell.
-
-You can see a simple example of use in ReadArgsEx.hs, and a fuller list of features in ReadArgsSpec.hs.
View
50 README.md
@@ -0,0 +1,50 @@
+ReadArgs provides the readArgs IO action, which lets you tell the compiler
+to parse the command line arguments to fit the type signature you give.
+
+For example `(a :: Int, b :: String, c :: Float) <- readArgs` would
+parse the first runtime argument as an Int, the second as a String (no
+quotes required) and the third as a float.
+
+If the runtime arguments are incompatible with the type signature,
+then a simple usage statement is given of the types needed.
+
+Continuing the previous example, if it was used in a
+program named Example, the error message for the above
+action would be:
+
+ usage: Example Int String Float
+
+Any type that has both Typeable and Read instances
+can be used. Both Char and String are handled specially so that
+command line arguments for both do not require quotes (as their
+Read instances do).
+
+readArgs also supports optional arguments and variadic arguments.
+Optional arguments are specified using Maybe, and variadic arguments
+using a list. `(a :: Int, b :: Maybe String, c :: [Float]) <- readArgs`
+would successfully parse any of the following sets of command line arguments:
+
+ Example 1
+ Example 1 2 3 4
+ Example 1 foo
+ Example 1 foo 2 3 4
+
+But not
+
+ Example
+ Example foo
+ Example 1.0
+
+Usage statements for optional and variadic arguments use command-line
+parlance:
+
+ usage: Example Int [String] [Float..]
+
+Note that both optional and variadic parsers are greedy by default
+(so `Example 1 2 3 4` was parsed as `(1, "2", [3.0,4.0])`. They
+may both be made non-greedy through use of the NonGreedy constructor:
+
+ ( a :: Int
+ , NonGreedy b :: NonGreedy Maybe String
+ , NonGreedy c :: NonGreedy [] Float
+ ) <- readArgs
View
82 ReadArgs.cabal
@@ -1,53 +1,68 @@
--- ReadArgs.cabal auto-generated by cabal init. For additional
--- options, see
--- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.
--- The name of the package.
Name: ReadArgs
-
--- The package version. See the Haskell package versioning policy
--- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
--- standards guiding when and how versions should be incremented.
Version: 1.0
-
--- A short (one-line) description of the package.
Synopsis: Simple command line argument parsing
--- A longer description of the package.
--- Description:
+Description: ReadArgs provides the readArgs IO action, which lets you tell the compiler
+ to parse the command line arguments to fit the type signature you give.
--- URL for the project homepage or repository.
-Homepage: http://github.com/rampion/ReadArgs
+ For example `(a :: Int, b :: String, c :: Float) <- readArgs` would
+ parse the first runtime argument as an Int, the second as a String (no
+ quotes required) and the third as a float.
--- The license under which the package is released.
-License: BSD3
+ If the runtime arguments are incompatible with the type signature,
+ then a simple usage statement is given of the types needed.
--- The file containing the license text.
-License-file: LICENSE
+ Continuing the previous example, if it was used in a
+ program named Example, the error message for the above
+ action would be:
--- The package author(s).
-Author: Noah Luck Easterly
+ usage: Example Int String Float
--- An email address to which users can send suggestions, bug reports,
--- and patches.
-Maintainer: noah.easterly@gmail.com
+ Any type that has both Typeable and Read instances
+ can be used. Both Char and String are handled specially so that
+ command line arguments for both do not require quotes (as their
+ Read instances do).
--- A copyright notice.
--- Copyright:
+ readArgs also supports optional arguments and variadic arguments.
+ Optional arguments are specified using Maybe, and variadic arguments
+ using a list. `(a :: Int, b :: Maybe String, c :: [Float]) <- readArgs`
+ would successfully parse any of the following sets of command line arguments:
-Category: Command Line
+ Example 1
+ Example 1 2 3 4
+ Example 1 foo
+ Example 1 foo 2 3 4
-Build-type: Simple
+ But not
--- Extra files to be distributed with the package, such as examples or
--- a README.
-Extra-source-files: README
+ Example
+ Example foo
+ Example 1.0
--- Constraint on the version of Cabal needed to build this package.
-Cabal-version: >=1.2
+ Usage statements for optional and variadic arguments use command-line
+ parlance:
+
+ usage: Example Int [String] [Float..]
+ Note that both optional and variadic parsers are greedy by default
+ (so `Example 1 2 3 4` was parsed as `(1, "2", [3.0,4.0])`. They
+ may both be made non-greedy through use of the NonGreedy constructor:
+
+ ( a :: Int
+ , NonGreedy b :: NonGreedy Maybe String
+ , NonGreedy c :: NonGreedy [] Float
+ ) <- readArgs
+
+Homepage: http://github.com/rampion/ReadArgs
+License: BSD3
+License-file: LICENSE
+Author: Noah Luck Easterly
+Maintainer: noah.easterly@gmail.com
+Category: Command Line
+Build-type: Simple
+Cabal-version: >=1.2
Library
- -- Modules exported by the library.
Exposed-modules: ReadArgs
Build-depends:
@@ -60,7 +75,6 @@ Test-Suite ReadArgsSpec
Main-Is:
ReadArgsSpec.hs
- -- Packages needed in order to build this package.
Build-depends:
hspec

0 comments on commit 0ca2c56

Please sign in to comment.
Something went wrong with that request. Please try again.