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.
This commit is contained in:
parent
4018e5f6f1
commit
a2ba701056
104 changed files with 435 additions and 370 deletions
|
@ -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. -}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue