let optparse-applicative handle the usage display when run w/o command or bad command

Still generating the list of commands myself, to get it sorted into
sections and with short synopses.
This commit is contained in:
Joey Hess 2015-07-09 11:49:52 -04:00
parent 6204dcbd7b
commit 8a9d2a6e9d
5 changed files with 42 additions and 30 deletions

View file

@ -19,6 +19,7 @@ import qualified Command.Add
import qualified Command.Unannex
import qualified Command.Fsck
{-
import qualified Command.Help
import qualified Command.Drop
import qualified Command.Move
import qualified Command.Copy
@ -97,7 +98,6 @@ import qualified Command.Proxy
import qualified Command.DiffDriver
import qualified Command.Undo
import qualified Command.Version
import qualified Command.Help
#ifdef WITH_ASSISTANT
import qualified Command.Watch
import qualified Command.Assistant
@ -124,6 +124,7 @@ cmds =
[ Command.Add.cmd
, Command.Fsck.cmd
{-
, Command.Help.cmd
, Command.Get.cmd
, Command.Drop.cmd
, Command.Move.cmd
@ -204,7 +205,6 @@ cmds =
, Command.DiffDriver.cmd
, Command.Undo.cmd
, Command.Version.cmd
, Command.Help.cmd
#ifdef WITH_ASSISTANT
, Command.Watch.cmd
, Command.Assistant.cmd
@ -224,9 +224,6 @@ cmds =
-}
]
header :: String
header = "git-annex command [option ...]"
run :: [String] -> IO ()
run args = do
#ifdef WITH_EKG
@ -234,7 +231,9 @@ run args = do
#endif
go envmodes
where
go [] = dispatch True args cmds gitAnnexOptions [] header Git.CurrentRepo.get
go [] = dispatch True args cmds gitAnnexOptions [] Git.CurrentRepo.get
"git-annex"
"manage files with git, without checking their contents in"
go ((v, a):rest) = maybe (go rest) a =<< getEnv v
envmodes =
[ (sshOptionsEnv, runSshOptions args)

View file

@ -101,7 +101,9 @@ builtin cmd dir params = do
let (params', fieldparams, opts) = partitionParams params
rsyncopts = ("RsyncOptions", unwords opts)
fields = rsyncopts : filter checkField (parseFields fieldparams)
dispatch False (cmd : params') cmds options fields header mkrepo
dispatch False (cmd : params') cmds options fields mkrepo
"git-annex-shell"
"Restricted login shell for git-annex only SSH access"
where
mkrepo = do
r <- Git.Construct.repoAbsPath dir >>= Git.Construct.fromAbsPath

View file

@ -13,9 +13,12 @@ import Types.Command
usageMessage :: String -> String
usageMessage s = "Usage: " ++ s
{- Usage message with lists of commands by section. -}
usage :: String -> [Command] -> String
usage header cmds = unlines $ usageMessage header : concatMap go [minBound..]
usage header cmds = unlines $ usageMessage header : commandList cmds
{- Commands listed by section, with breif usage and description. -}
commandList :: [Command] -> [String]
commandList cmds = concatMap go [minBound..]
where
go section
| null cs = []
@ -39,6 +42,7 @@ usage header cmds = unlines $ usageMessage header : concatMap go [minBound..]
longest f = foldl max 0 $ map (length . f) cmds
scmds = sort cmds
{- Descriptions of params used in usage messages. -}
paramPaths :: String
paramPaths = paramRepeating paramPath -- most often used