{- Copyright 2007 Dino Morelli This file is part of storylen storylen is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. storylen 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. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with storylen; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -} module StoryLen.Opts ( Flag (..), parseOpts, usageText ) where import System.Console.GetOpt data Flag = Number Int | Help options :: [OptDescr Flag] options = [ Option ['n'] ["number"] (ReqArg (Number . read) "NUM") "Categorize the explicit number of words given" , Option ['h'] ["help"] (NoArg Help) "This help text" ] parseOpts :: [String] -> IO ([Flag], [String]) parseOpts argv = case getOpt Permute options argv of (o,n,[] ) -> return (o,n) (_,_,errs) -> ioError (userError (concat errs ++ usageText)) usageText :: String usageText = (usageInfo header options) ++ "\n" ++ footer where header = init $ unlines [ "Usage: storylen [OPTIONS] [FILES]" , "Show story word count and categorization. This is intended to be run on" , "plain ascii text files. With no FILES, read from standard input." , "" , "Options:" ] footer = init $ unlines [ "Story categories are determined using the following table, found on" , "Wikipedia: http://en.wikipedia.org/wiki/Word_count" , "" , " <= 2000 - flash fiction" , " <= 7500 - short story" , " <= 17500 - novellette" , " <= 60000 - novella" , " <= 199999 - novel" , " above 199999 - epic" , "" , "Version 009 2007-Apr-30 Dino Morelli " ]