aboutsummaryrefslogtreecommitdiff
path: root/Types/Command.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-08 12:33:27 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-08 13:36:25 -0400
commite73914b7950ce9d26a3882472c7ab27260ff87f9 (patch)
tree33d4a11106a005eadfe317505ea2786e83cf5bc8 /Types/Command.hs
parent8ce422d8ab390e105d70f049c30d81c14d3b64b4 (diff)
started converting to use optparse-applicative
This is a work in progress. It compiles and is able to do basic command dispatch, including git autocorrection, while using optparse-applicative for the core commandline parsing. * Many commands are temporarily disabled before conversion. * Options are not wired in yet. * cmdnorepo actions don't work yet. Also, removed the [Command] list, which was only used in one place.
Diffstat (limited to 'Types/Command.hs')
-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. -}