console-program 0.3.0.0 → 0.3.0.1
raw patch · 5 files changed
+29/−30 lines, 5 files
Files
- console-program.cabal +7/−7
- src/System/Console/Argument.hs +8/−6
- src/System/Console/Command.hs +6/−9
- src/System/Console/Internal.hs +3/−5
- src/System/Console/Program.hs +5/−3
console-program.cabal view
@@ -1,29 +1,29 @@ Name: console-program-Version: 0.3.0.0+Version: 0.3.0.1 Cabal-Version: >= 1.6 License: BSD3 Author: Arie Peterson Maintainer: ariep@xs4all.nl Category: Console-Synopsis: Interprets command line arguments and the contents of a config file as commands and options+Synopsis: Interpret the command line and contents of a config file as commands and options Description: This library provides an infrastructure to build command line programs. It provides the following features: .- - declare any number of \"actions\" (commands, or modes of operation, of the program);+ - declare any number of \"commands\" (modes of operation) of the program; .- - declare options of the program;+ - declare options of these commands; .- - collect options and actions from a configuration file and the command line, and execute the proper action.+ - collect options from a configuration file and the command line, and execute the proper command. . .- Examples of using this library may be found in the "Examples" directory in the package tarball.+ Examples of using this library may be found in the Examples directory in the package tarball. . . It provides functionality similar to the cmdargs package. Main differences: . - console-program does not use unsafePerformIO, and tries to give a more haskellish, referentially transparent interface; .- - it allows a full tree of \"modes\", instead of a list, so a command can have subcommands;+ - it allows a full tree of commands, instead of a list, so a command can have subcommands; . - it parses a configuration file, in addition to the command line arguments. Category: System
src/System/Console/Argument.hs view
@@ -1,6 +1,12 @@+-- | This module contains functions to create option descriptions, together+-- with their argument types. module System.Console.Argument (- Type (Type,parser,name,defaultValue)+ -- * Option descriptions+ Option+ , option++ , Type (Type,parser,name,defaultValue) -- * Argument types , optional@@ -10,11 +16,7 @@ , file , device , natural- , integer- - -- * Option descriptions- , Option- , option+ , integer ) where
src/System/Console/Command.hs view
@@ -1,19 +1,16 @@ -- |--- A \"mode\" or \"command\" provides a mode of operation of your program.+-- A 'Command' provides a mode of operation of your program. -- This allows a single program to provide many different pieces of -- functionality. The first argument to the program (or the first few, if it -- has subcommands) determines which command should be executed.--- (@darcs@ and @cabal@ are examples of programs that make heavy use of modes.)+-- (@darcs@ and @cabal@ are examples of programs with this behaviour.) -- -- An 'Action' represents an IO action, together with information about--- applicable option and non-option arguments.--- --- A command can have also non-option arguments (plain arguments). These also--- have types. Create such commands using the function 'System.Console.Action.withArgument'.+-- applicable options and non-option arguments. module System.Console.Command ( Commands,Tree.Tree(Tree.Node)- , Command+ , Command(Command,name,description,action) , Action , io@@ -24,14 +21,14 @@ import System.Console.Internal (- Command(Command)+ Command(Command,name,description,action) , Action(Action,run,options,nonOptions) , Option(Option) , Identifier ) import qualified System.Console.Argument as Argument -import qualified Data.Map as Map+import qualified Data.Map as Map import qualified Data.Tree as Tree import System.Exit (exitFailure)
src/System/Console/Internal.hs view
@@ -28,15 +28,13 @@ -- | A @Command@ is an action, together with some descriptive information.--- The description, and lists of applicable options and non-options are--- used only to show usage information for the command. data Command = Command {+ -- | This determines which command is executed. name :: String- -- ^ This determines which command is executed, depending on the command line.+ -- | For usage info. , description :: String- -- ^ For usage info.+ -- | The actual action performed by this command. , action :: Action- -- ^ The actual action performed by this command. }
src/System/Console/Program.hs view
@@ -1,5 +1,5 @@ -- | This module contains functions to build a console program, that parses--- the command line (and a configuration file), divides it into modes/commands,+-- the command line (and a configuration file), divides it into commands, -- options and non-options, and executes the corresponding action from a tree -- of available commands. -- @@ -76,8 +76,10 @@ Nothing -> ([],root,x : xs) Just cs -> let (xs',c,rest) = select cs xs in (x : xs',c,rest) --- | Load the configuration file (if present), and run the action given on the command line.--- You may use this function, with appropriate arguments, as your @main@ function.+-- | Load the configuration file (if present), and run the command given on+-- the command line.+-- +-- You may use this function, applied to your tree of available commands, as your @main@ function. -- -- Settings in the configuration file override the default configuration; -- settings on the command line override both.