summaryrefslogtreecommitdiff
path: root/Types
diff options
context:
space:
mode:
Diffstat (limited to 'Types')
-rw-r--r--Types/Command.hs27
1 files changed, 16 insertions, 11 deletions
diff --git a/Types/Command.hs b/Types/Command.hs
index de6e78038..4ab722035 100644
--- a/Types/Command.hs
+++ b/Types/Command.hs
@@ -1,6 +1,6 @@
{- git-annex command data types
-
- - Copyright 2010-2011 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2015 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -8,28 +8,31 @@
module Types.Command where
import Data.Ord
+import Options.Applicative.Types (Parser)
import Types
{- A command runs in these stages.
-
- - a. The check stage runs checks, that error out if
+ - a. The parser stage parses the command line and generates a CommandSeek
+ - action. -}
+type CommandParser = Parser CommandSeek
+{- b. The check stage runs checks, that error out if
- anything prevents the command from running. -}
data CommandCheck = CommandCheck { idCheck :: Int, runCheck :: Annex () }
-{- b. The seek stage takes the parameters passed to the command,
- - looks through the repo to find the ones that are relevant
- - to that command (ie, new files to add), and runs commandAction
- - to handle all necessary actions. -}
-type CommandSeek = [String] -> Annex ()
-{- c. The start stage is run before anything is printed about the
+{- c. The seek stage is passed input from the parser, looks through
+ - the repo to find things to act on (ie, new files to add), and
+ - runs commandAction to handle all necessary actions. -}
+type CommandSeek = Annex ()
+{- d. The start stage is run before anything is printed about the
- command, is passed some input, and can early abort it
- if the input does not make sense. It should run quickly and
- should not modify Annex state. -}
type CommandStart = Annex (Maybe CommandPerform)
-{- d. The perform stage is run after a message is printed about the command
+{- e. The perform stage is run after a message is printed about the command
- being run, and it should be where the bulk of the work happens. -}
type CommandPerform = Annex (Maybe CommandCleanup)
-{- e. The cleanup stage is run only if the perform stage succeeds, and it
+{- f. The cleanup stage is run only if the perform stage succeeds, and it
- returns the overall success/fail of the command. -}
type CommandCleanup = Annex Bool
@@ -42,11 +45,13 @@ data Command = Command
, cmdnomessages :: Bool -- don't output normal messages
, cmdname :: String
, cmdparamdesc :: String -- description of params for usage
- , cmdseek :: CommandSeek
, cmdsection :: CommandSection
, cmddesc :: String -- description of command for usage
+ , cmdparser :: CommandParser -- command line parser
}
+{- Command-line parameters, after the command is selected and options
+ - are parsed. -}
type CmdParams = [String]
{- CommandCheck functions can be compared using their unique id. -}