make "git annex help options" work outside a git repo
Option parsing for commands that run outside git repos is still screwy, as there is no Annex monad and so the flags cannot be passed in. But, any remaining parameters can be, which is enough for this fix.
This commit is contained in:
parent
6edac746f0
commit
fa3045aa8b
9 changed files with 31 additions and 24 deletions
11
CmdLine.hs
11
CmdLine.hs
|
@ -32,16 +32,13 @@ import Annex.Environment
|
||||||
import Command
|
import Command
|
||||||
import Types.Messages
|
import Types.Messages
|
||||||
|
|
||||||
type Params = [String]
|
|
||||||
type Flags = [Annex ()]
|
|
||||||
|
|
||||||
{- Runs the passed command line. -}
|
{- Runs the passed command line. -}
|
||||||
dispatch :: Bool -> Params -> [Command] -> [Option] -> [(String, String)] -> String -> IO Git.Repo -> IO ()
|
dispatch :: Bool -> CmdParams -> [Command] -> [Option] -> [(String, String)] -> String -> IO Git.Repo -> IO ()
|
||||||
dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do
|
dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do
|
||||||
setupConsole
|
setupConsole
|
||||||
r <- E.try getgitrepo :: IO (Either E.SomeException Git.Repo)
|
r <- E.try getgitrepo :: IO (Either E.SomeException Git.Repo)
|
||||||
case r of
|
case r of
|
||||||
Left e -> fromMaybe (throw e) (cmdnorepo cmd)
|
Left e -> maybe (throw e) (\a -> a params) (cmdnorepo cmd)
|
||||||
Right g -> do
|
Right g -> do
|
||||||
state <- Annex.new g
|
state <- Annex.new g
|
||||||
(actions, state') <- Annex.run state $ do
|
(actions, state') <- Annex.run state $ do
|
||||||
|
@ -66,7 +63,7 @@ dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do
|
||||||
{- Parses command line params far enough to find the Command to run, and
|
{- Parses command line params far enough to find the Command to run, and
|
||||||
- returns the remaining params.
|
- returns the remaining params.
|
||||||
- Does fuzzy matching if necessary, which may result in multiple Commands. -}
|
- Does fuzzy matching if necessary, which may result in multiple Commands. -}
|
||||||
findCmd :: Bool -> Params -> [Command] -> (String -> String) -> (Bool, [Command], String, Params)
|
findCmd :: Bool -> CmdParams -> [Command] -> (String -> String) -> (Bool, [Command], String, CmdParams)
|
||||||
findCmd fuzzyok argv cmds err
|
findCmd fuzzyok argv cmds err
|
||||||
| isNothing name = error $ err "missing command"
|
| isNothing name = error $ err "missing command"
|
||||||
| not (null exactcmds) = (False, exactcmds, fromJust name, args)
|
| not (null exactcmds) = (False, exactcmds, fromJust name, args)
|
||||||
|
@ -85,7 +82,7 @@ findCmd fuzzyok argv cmds err
|
||||||
|
|
||||||
{- Parses command line options, and returns actions to run to configure flags
|
{- Parses command line options, and returns actions to run to configure flags
|
||||||
- and the remaining parameters for the command. -}
|
- and the remaining parameters for the command. -}
|
||||||
getOptCmd :: Params -> Command -> [Option] -> (Flags, Params)
|
getOptCmd :: CmdParams -> Command -> [Option] -> ([Annex ()], CmdParams)
|
||||||
getOptCmd argv cmd commonoptions = check $
|
getOptCmd argv cmd commonoptions = check $
|
||||||
getOpt Permute (commonoptions ++ cmdoptions cmd) argv
|
getOpt Permute (commonoptions ++ cmdoptions cmd) argv
|
||||||
where
|
where
|
||||||
|
|
|
@ -55,7 +55,7 @@ noMessages c = c { cmdnomessages = True }
|
||||||
|
|
||||||
{- Adds a fallback action to a command, that will be run if it's used
|
{- Adds a fallback action to a command, that will be run if it's used
|
||||||
- outside a git repository. -}
|
- outside a git repository. -}
|
||||||
noRepo :: IO () -> Command -> Command
|
noRepo :: (CmdParams -> IO ()) -> Command -> Command
|
||||||
noRepo a c = c { cmdnorepo = Just a }
|
noRepo a c = c { cmdnorepo = Just a }
|
||||||
|
|
||||||
{- Adds options to a command. -}
|
{- Adds options to a command. -}
|
||||||
|
|
|
@ -55,8 +55,8 @@ start foreground stopdaemon autostart startdelay
|
||||||
|
|
||||||
{- Run outside a git repository. Check to see if any parameter is
|
{- Run outside a git repository. Check to see if any parameter is
|
||||||
- --autostart and enter autostart mode. -}
|
- --autostart and enter autostart mode. -}
|
||||||
checkAutoStart :: IO ()
|
checkAutoStart :: CmdParams -> IO ()
|
||||||
checkAutoStart = ifM (elem "--autostart" <$> getArgs)
|
checkAutoStart _ = ifM (elem "--autostart" <$> getArgs)
|
||||||
( autoStart Nothing
|
( autoStart Nothing
|
||||||
, error "Not in a git repository."
|
, error "Not in a git repository."
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,20 +23,24 @@ import GitAnnex.Options
|
||||||
import System.Console.GetOpt
|
import System.Console.GetOpt
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [noCommit $ noRepo showGeneralHelp $ dontCheck repoExists $
|
def = [noCommit $ noRepo startNoRepo $ dontCheck repoExists $
|
||||||
command "help" paramNothing seek SectionQuery "display help"]
|
command "help" paramNothing seek SectionQuery "display help"]
|
||||||
|
|
||||||
seek :: [CommandSeek]
|
seek :: [CommandSeek]
|
||||||
seek = [withWords start]
|
seek = [withWords start]
|
||||||
|
|
||||||
start :: [String] -> CommandStart
|
start :: [String] -> CommandStart
|
||||||
start ["options"] = do
|
start params = do
|
||||||
liftIO showCommonOptions
|
liftIO $ start' params
|
||||||
stop
|
|
||||||
start _ = do
|
|
||||||
liftIO showGeneralHelp
|
|
||||||
stop
|
stop
|
||||||
|
|
||||||
|
startNoRepo :: CmdParams -> IO ()
|
||||||
|
startNoRepo = start'
|
||||||
|
|
||||||
|
start' :: [String] -> IO ()
|
||||||
|
start' ["options"] = showCommonOptions
|
||||||
|
start' _ = showGeneralHelp
|
||||||
|
|
||||||
showCommonOptions :: IO ()
|
showCommonOptions :: IO ()
|
||||||
showCommonOptions = putStrLn $ usageInfo "Common options:" options
|
showCommonOptions = putStrLn $ usageInfo "Common options:" options
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,6 @@ module Command.Upgrade where
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import Upgrade
|
import Upgrade
|
||||||
import Annex.Version
|
|
||||||
import Config
|
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [dontCheck repoExists $ -- because an old version may not seem to exist
|
def = [dontCheck repoExists $ -- because an old version may not seem to exist
|
||||||
|
|
|
@ -18,7 +18,7 @@ import qualified Remote
|
||||||
import qualified Backend
|
import qualified Backend
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [noCommit $ noRepo showPackageVersion $ dontCheck repoExists $
|
def = [noCommit $ noRepo startNoRepo $ dontCheck repoExists $
|
||||||
command "version" paramNothing seek SectionQuery "show version info"]
|
command "version" paramNothing seek SectionQuery "show version info"]
|
||||||
|
|
||||||
seek :: [CommandSeek]
|
seek :: [CommandSeek]
|
||||||
|
@ -37,6 +37,9 @@ start = do
|
||||||
unwords upgradableVersions
|
unwords upgradableVersions
|
||||||
stop
|
stop
|
||||||
|
|
||||||
|
startNoRepo :: CmdParams -> IO ()
|
||||||
|
startNoRepo _ = showPackageVersion
|
||||||
|
|
||||||
showPackageVersion :: IO ()
|
showPackageVersion :: IO ()
|
||||||
showPackageVersion = do
|
showPackageVersion = do
|
||||||
info "git-annex version" SysConfig.packageversion
|
info "git-annex version" SysConfig.packageversion
|
||||||
|
|
|
@ -82,7 +82,7 @@ start' allowauto listenhost = do
|
||||||
else openBrowser browser htmlshim url origout origerr
|
else openBrowser browser htmlshim url origout origerr
|
||||||
)
|
)
|
||||||
auto
|
auto
|
||||||
| allowauto = liftIO startNoRepo
|
| allowauto = liftIO $ startNoRepo []
|
||||||
| otherwise = do
|
| otherwise = do
|
||||||
d <- liftIO getCurrentDirectory
|
d <- liftIO getCurrentDirectory
|
||||||
error $ "no git repository in " ++ d
|
error $ "no git repository in " ++ d
|
||||||
|
@ -93,8 +93,8 @@ start' allowauto listenhost = do
|
||||||
|
|
||||||
{- When run without a repo, start the first available listed repository in
|
{- When run without a repo, start the first available listed repository in
|
||||||
- the autostart file. If not, it's our first time being run! -}
|
- the autostart file. If not, it's our first time being run! -}
|
||||||
startNoRepo :: IO ()
|
startNoRepo :: CmdParams -> IO ()
|
||||||
startNoRepo = do
|
startNoRepo _ = do
|
||||||
-- FIXME should be able to reuse regular getopt, but
|
-- FIXME should be able to reuse regular getopt, but
|
||||||
-- it currently runs in the Annex monad.
|
-- it currently runs in the Annex monad.
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
|
|
|
@ -12,7 +12,7 @@ import Command
|
||||||
import Assistant.XMPP.Git
|
import Assistant.XMPP.Git
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [noCommit $ noRepo xmppGitRelay $ dontCheck repoExists $
|
def = [noCommit $ noRepo startNoRepo $ dontCheck repoExists $
|
||||||
command "xmppgit" paramNothing seek
|
command "xmppgit" paramNothing seek
|
||||||
SectionPlumbing "git to XMPP relay"]
|
SectionPlumbing "git to XMPP relay"]
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ start _ = do
|
||||||
liftIO xmppGitRelay
|
liftIO xmppGitRelay
|
||||||
stop
|
stop
|
||||||
|
|
||||||
|
startNoRepo :: CmdParams -> IO ()
|
||||||
|
startNoRepo _ = xmppGitRelay
|
||||||
|
|
||||||
{- A basic implementation of the git-remote-helpers protocol. -}
|
{- A basic implementation of the git-remote-helpers protocol. -}
|
||||||
gitRemoteHelper :: IO ()
|
gitRemoteHelper :: IO ()
|
||||||
gitRemoteHelper = do
|
gitRemoteHelper = do
|
||||||
|
|
|
@ -36,7 +36,7 @@ type CommandCleanup = Annex Bool
|
||||||
{- A command is defined by specifying these things. -}
|
{- A command is defined by specifying these things. -}
|
||||||
data Command = Command
|
data Command = Command
|
||||||
{ cmdoptions :: [Option] -- command-specific options
|
{ cmdoptions :: [Option] -- command-specific options
|
||||||
, cmdnorepo :: Maybe (IO ()) -- an action to run when not in a repo
|
, cmdnorepo :: Maybe (CmdParams -> IO ()) -- an action to run when not in a repo
|
||||||
, cmdcheck :: [CommandCheck] -- check stage
|
, cmdcheck :: [CommandCheck] -- check stage
|
||||||
, cmdnocommit :: Bool -- don't commit journalled state changes
|
, cmdnocommit :: Bool -- don't commit journalled state changes
|
||||||
, cmdnomessages :: Bool -- don't output normal messages
|
, cmdnomessages :: Bool -- don't output normal messages
|
||||||
|
@ -47,6 +47,8 @@ data Command = Command
|
||||||
, cmddesc :: String -- description of command for usage
|
, cmddesc :: String -- description of command for usage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CmdParams = [String]
|
||||||
|
|
||||||
{- CommandCheck functions can be compared using their unique id. -}
|
{- CommandCheck functions can be compared using their unique id. -}
|
||||||
instance Eq CommandCheck where
|
instance Eq CommandCheck where
|
||||||
a == b = idCheck a == idCheck b
|
a == b = idCheck a == idCheck b
|
||||||
|
|
Loading…
Reference in a new issue