hskeleton (empty) → 0.1
raw patch · 5 files changed
+128/−0 lines, 5 filesdep +Cabaldep +basesetup-changed
Dependencies added: Cabal, base
Files
- LICENSE +36/−0
- Setup.lhs +3/−0
- System/Console/GetOpt/Skeleton.hs +33/−0
- System/Console/GetOpt/StandardOpts.hs +32/−0
- hskeleton.cabal +24/−0
+ LICENSE view
@@ -0,0 +1,36 @@+Copyright (c) 2004-2008, David Himmelstrup+Copyright (c) 2009, Robin Green+All rights reserved.++Redistribution and use in source and binary forms,+with or without modification, are permitted provided+that the following conditions are met:++ * Redistributions of source code must retain+ the above copyright notice, this list of+ conditions and the following disclaimer.+ * Redistributions in binary form must reproduce+ the above copyright notice, this list of+ conditions and the following disclaimer in the+ documentation and/or other materials provided+ with the distribution.+ * Neither the name of Robin Green nor the+ names of other contributors may be used to+ endorse or promote products derived from this+ software without specific prior written permission.+++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE+USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY+OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ System/Console/GetOpt/Skeleton.hs view
@@ -0,0 +1,33 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+module System.Console.GetOpt.Skeleton where++import Data.Monoid ( Last(..), Monoid(..) )+import Distribution.Version ( Version )+import System.Console.GetOpt ( OptDescr (..), getOpt', ArgOrder (..) )+import System.Console.GetOpt.StandardOpts ( printHelp, printVersion, StandardFlag(..) )+import System.Environment ( getProgName )+import System.Exit ( exitWith, ExitCode (..) )+import Data.Maybe ( fromJust, isJust )++-- | *basic* command-line argument parsing - you may wish to write your own parseArgs, based on+-- the source code of this one.+parseArgs :: Version -> [OptDescr a] -> ([a] -> b) -> (b -> Maybe StandardFlag) -> [String] -> IO b+parseArgs progVersion globalOptions postProcess findStandard args =+ do+ progName <- getProgName+ let pHelp = printHelp progName globalOptions+ case getOpt' RequireOrder globalOptions args of+ (flags, _, _, []) | isJust (findStandard $ postProcess flags) -> do+ case fromJust (findStandard $ postProcess flags) of+ HelpFlag -> pHelp+ VersionFlag -> printVersion progName progVersion+ exitWith ExitSuccess+ (flags, [], _, []) -> return $ postProcess flags+ (_, _, _, errs) -> do putStrLn "Errors when parsing command-line arguments:"+ mapM_ putStrLn errs+ pHelp+ exitWith $ ExitFailure 1++-- | Special version of parseArgs for monoids+mParseArgs :: Monoid b => Version -> [OptDescr (b -> b)] -> (b -> Last StandardFlag) -> [String] -> IO b+mParseArgs progVersion globalOptions getStandard = parseArgs progVersion globalOptions (foldr id mempty) $ getLast . getStandard
+ System/Console/GetOpt/StandardOpts.hs view
@@ -0,0 +1,32 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+module System.Console.GetOpt.StandardOpts where++import Control.Applicative ( (<$>) )+import Distribution.Text ( display )+import Distribution.Version ( Version )+import System.Console.GetOpt ( ArgDescr (..), OptDescr (..), usageInfo )++data StandardFlag = HelpFlag | VersionFlag++standardOptions :: [OptDescr StandardFlag]+standardOptions = [ Option "h?" ["help"] (NoArg HelpFlag) "Show this help text"+ , Option "v" ["version"] (NoArg VersionFlag) "Show the version number of this program"+ ]++-- These instances should be moved to the main GetOpt module+instance Functor ArgDescr where+ fmap f (NoArg x) = NoArg $ f x+ fmap f (ReqArg p s) = ReqArg (f . p) s+ fmap f (OptArg p s) = OptArg (f . p) s++instance Functor OptDescr where+ fmap f (Option short long ad desc) = Option short long (f <$> ad) desc++stdOpts :: (StandardFlag -> a) -> [OptDescr a]+stdOpts f = (f <$>) <$> standardOptions++printHelp :: String -> [OptDescr a] -> IO ()+printHelp progName = putStrLn . usageInfo ("Usage" ++ progName ++ " [FLAGS]\n")++printVersion :: String -> Version -> IO ()+printVersion name version = putStrLn $ name ++ ' ' : display version
+ hskeleton.cabal view
@@ -0,0 +1,24 @@+Name: hskeleton+Version: 0.1+Cabal-version: >= 1.6+License: BSD3+License-file: LICENSE+Maintainer: Robin Green <greenrd@greenrd.org>+Build-type: Simple+Copyright: see LICENSE+Category: Console+Synopsis: Skeleton for new Haskell programs+Description: Currently, this just handles --help and --version arguments for you.+ In future, it may do more.+Bug-reports: mailto:greenrd@greenrd.org+Stability: experimental+Tested-with: GHC == 6.10.2++Source-repository head+ Type: darcs+ Location: http://patch-tag.com/publicrepos/hskeleton++Library+ Build-depends: base, Cabal >= 1.6+ Exposed-modules: System.Console.GetOpt.Skeleton, System.Console.GetOpt.StandardOpts+ GHC-options: -Wall