diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-09-14 13:19:04 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-09-14 13:19:04 -0400 |
commit | d8bc62fed9ae2e85235fde7a6cba5f522daf6014 (patch) | |
tree | e4060fe221ab3dcb6ab2223e031987df6bfb7dbe | |
parent | e323354b4ca2a44baae8223b9dd47aaab234a56a (diff) |
Improve bash completion, so it completes names of remotes and backends in appropriate places.
Not necessarily everywhere, but a lot of the most often used places.
Re the use of .Internal, see
https://github.com/pcapriotti/optparse-applicative/issues/155
-rw-r--r-- | CmdLine/GitAnnex/Options.hs | 25 | ||||
-rw-r--r-- | Command/Drop.hs | 1 | ||||
-rw-r--r-- | Command/Fsck.hs | 1 | ||||
-rw-r--r-- | Command/Sync.hs | 5 | ||||
-rw-r--r-- | debian/changelog | 2 |
5 files changed, 32 insertions, 2 deletions
diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index b9c0fe7b7..2651b92e4 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -8,9 +8,11 @@ module CmdLine.GitAnnex.Options where import Options.Applicative +import Options.Applicative.Builder.Internal import Common.Annex import qualified Git.Config +import qualified Git.Construct import Git.Types import Types.TrustLevel import Types.NumCopies @@ -26,6 +28,8 @@ import qualified Limit.Wanted import CmdLine.Option import CmdLine.Usage import CmdLine.GlobalSetter +import qualified Backend +import qualified Types.Backend as Backend -- Global options that are accepted by all git-annex sub-commands, -- although not always used. @@ -40,16 +44,19 @@ gitAnnexGlobalOptions = commonGlobalOptions ++ ( long "trust" <> metavar paramRemote <> help "override trust setting" <> hidden + <> completeRemotes ) , globalSetter (Remote.forceTrust SemiTrusted) $ strOption ( long "semitrust" <> metavar paramRemote <> help "override trust setting back to default" <> hidden + <> completeRemotes ) , globalSetter (Remote.forceTrust UnTrusted) $ strOption ( long "untrust" <> metavar paramRemote <> help "override trust setting to untrusted" <> hidden + <> completeRemotes ) , globalSetter setgitconfig $ strOption ( long "config" <> short 'c' <> metavar "NAME=VALUE" @@ -98,7 +105,9 @@ parseAutoOption = switch ) parseRemoteOption :: Parser RemoteName -> Parser (DeferredParse Remote) -parseRemoteOption p = DeferredParse . (fromJust <$$> Remote.byNameWithUUID) . Just <$> p +parseRemoteOption p = DeferredParse + . (fromJust <$$> Remote.byNameWithUUID) + . Just <$> p data FromToOptions = FromRemote (DeferredParse Remote) @@ -117,12 +126,14 @@ parseFromOption :: Parser (DeferredParse Remote) parseFromOption = parseRemoteOption $ strOption ( long "from" <> short 'f' <> metavar paramRemote <> help "source remote" + <> completeRemotes ) parseToOption :: Parser (DeferredParse Remote) parseToOption = parseRemoteOption $ strOption ( long "to" <> short 't' <> metavar paramRemote <> help "destination remote" + <> completeRemotes ) -- Options for acting on keys, rather than work tree files. @@ -179,6 +190,7 @@ nonWorkTreeMatchingOptions' = ( long "in" <> short 'i' <> metavar paramRemote <> help "match files present in a remote" <> hidden + <> completeRemotes ) , globalSetter Limit.addCopies $ strOption ( long "copies" <> short 'C' <> metavar paramRemote @@ -199,6 +211,7 @@ nonWorkTreeMatchingOptions' = ( long "inbackend" <> short 'B' <> metavar paramName <> help "match files using a key-value backend" <> hidden + <> completeBackends ) , globalSetter Limit.addInAllGroup $ strOption ( long "inallgroup" <> metavar paramGroup @@ -299,3 +312,13 @@ parseDaemonOptions = DaemonOptions ( long "stop" <> help "stop daemon" ) +completeRemotes :: HasCompleter f => Mod f a +completeRemotes = completer $ mkCompleter $ \input -> do + r <- maybe (pure Nothing) (Just <$$> Git.Config.read) + =<< Git.Construct.fromCwd + return $ filter (input `isPrefixOf`) + (maybe [] (mapMaybe remoteName . remotes) r) + + +completeBackends :: HasCompleter f => Mod f a +completeBackends = completeWith (map Backend.name Backend.list) diff --git a/Command/Drop.hs b/Command/Drop.hs index feb89b70e..b23f81758 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -46,6 +46,7 @@ parseDropFromOption :: Parser (DeferredParse Remote) parseDropFromOption = parseRemoteOption $ strOption ( long "from" <> short 'f' <> metavar paramRemote <> help "drop content from a remote" + <> completeRemotes ) seek :: DropOptions -> CommandSeek diff --git a/Command/Fsck.hs b/Command/Fsck.hs index a522f5349..656ceb644 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -67,6 +67,7 @@ optParser desc = FsckOptions <*> optional (parseRemoteOption $ strOption ( long "from" <> short 'f' <> metavar paramRemote <> help "check remote" + <> completeRemotes )) <*> optional parseincremental <*> optional (parseKeyOptions False) diff --git a/Command/Sync.hs b/Command/Sync.hs index 4e6bf11d7..19a984300 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -70,7 +70,10 @@ data SyncOptions = SyncOptions optParser :: CmdParamsDesc -> Parser SyncOptions optParser desc = SyncOptions - <$> cmdParams desc + <$> (many $ argument str + ( metavar desc + <> completeRemotes + )) <*> invertableSwitch "commit" True ( help "avoid git commit" ) diff --git a/debian/changelog b/debian/changelog index 92b6b16ab..3368da953 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,8 @@ git-annex (5.20150825) UNRELEASED; urgency=medium --no-content options to specify the (current) default behavior. * annex.hardlink extended to also try to use hard links when copying from the repository to a remote. + * Improve bash completion, so it completes names of remotes and backends + in appropriate places. -- Joey Hess <id@joeyh.name> Tue, 01 Sep 2015 14:46:18 -0700 |