From 0033e6c0a68a497c803da1e66f590587e006fa3f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 30 Jun 2024 12:39:18 -0400 Subject: [PATCH] Tab completion of many commands like info and trust now includes remotes Especially useful with proxied remotes and clusters, where the user may not be entirely familiar with the name and can learn by tab completion. --- CHANGELOG | 2 ++ CmdLine/GitAnnex/Options.hs | 13 ++++++++++--- Command.hs | 4 ++++ Command/Dead.hs | 2 +- Command/Describe.hs | 4 ++-- Command/Group.hs | 4 ++-- Command/Info.hs | 2 +- Command/Semitrust.hs | 3 ++- Command/Trust.hs | 3 ++- Command/Ungroup.hs | 3 ++- Command/Untrust.hs | 3 ++- Command/Unused.hs | 1 + Command/Wanted.hs | 3 ++- 13 files changed, 33 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 25db409b4d..2688cfd367 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,8 @@ git-annex (10.20240532) UNRELEASED; urgency=medium complaining about missing tree objects. * Tab completion of options like --from now includes special remotes, as well as proxied remotes and clusters. + * Tab completion of many commands like info and trust now includes + remotes. * P2P protocol version 2. * Fix Windows build with Win32 2.13.4+ Thanks, Oleg Tolmatcev diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index 80ed6c2575..7c1bd29d7a 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -1,6 +1,6 @@ {- git-annex command-line option parsing - - - Copyright 2010-2023 Joey Hess + - Copyright 2010-2024 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -109,9 +109,12 @@ gitAnnexCommonOptions = commonOptions ++ {- Parser that accepts all non-option params. -} cmdParams :: CmdParamsDesc -> Parser CmdParams -cmdParams paramdesc = many $ argument str +cmdParams paramdesc = cmdParamsWithCompleter paramdesc completeFiles + +cmdParamsWithCompleter :: String -> Mod ArgumentFields String -> Parser CmdParams +cmdParamsWithCompleter paramdesc completers = many $ argument str ( metavar paramdesc - <> action "file" + <> completers ) parseAutoOption :: Parser Bool @@ -597,3 +600,7 @@ completeRemotes' g input = do completeBackends :: HasCompleter f => Mod f a completeBackends = completeWith $ map (decodeBS . formatKeyVariety . Backend.backendVariety) Backend.builtinList + +completeFiles :: HasCompleter f => Mod f a +completeFiles = action "file" + diff --git a/Command.hs b/Command.hs index aa2fc5b447..ddbe9ae60a 100644 --- a/Command.hs +++ b/Command.hs @@ -40,6 +40,10 @@ command name section desc paramdesc mkparser = withParams :: (CmdParams -> v) -> CmdParamsDesc -> Parser v withParams mkseek paramdesc = mkseek <$> cmdParams paramdesc +withParams' :: (CmdParams -> v) -> Mod ArgumentFields String -> String -> Parser v +withParams' mkseek completers paramdesc = mkseek + <$> cmdParamsWithCompleter paramdesc completers + {- Uses the supplied option parser, which yields a deferred parse, - and calls finishParse on the result before passing it to the - CommandSeek constructor. -} diff --git a/Command/Dead.hs b/Command/Dead.hs index cc6462fe3d..07aa17a823 100644 --- a/Command/Dead.hs +++ b/Command/Dead.hs @@ -22,7 +22,7 @@ cmd = withAnnexOptions [jsonOptions] $ data DeadOptions = DeadRemotes [RemoteName] | DeadKeys [Key] optParser :: CmdParamsDesc -> Parser DeadOptions -optParser desc = (DeadRemotes <$> cmdParams desc) +optParser desc = (DeadRemotes <$> cmdParamsWithCompleter desc completeRemotes) <|> (DeadKeys <$> many (option (str >>= parseKey) ( long "key" <> metavar paramKey <> help "keys whose content has been irretrievably lost" diff --git a/Command/Describe.hs b/Command/Describe.hs index ab76fedd7b..9b49ef6c86 100644 --- a/Command/Describe.hs +++ b/Command/Describe.hs @@ -14,8 +14,8 @@ import Logs.UUID cmd :: Command cmd = command "describe" SectionSetup "change description of a repository" - (paramPair paramRemote paramDesc) - (withParams seek) + (paramPair paramRepository paramDesc) + (withParams' seek completeRemotes) seek :: CmdParams -> CommandSeek seek = withWords (commandAction . start) diff --git a/Command/Group.hs b/Command/Group.hs index e01539ff5f..70bce76e17 100644 --- a/Command/Group.hs +++ b/Command/Group.hs @@ -20,7 +20,7 @@ import qualified Data.Map as M cmd :: Command cmd = noMessages $ command "group" SectionSetup "add a repository to a group" - (paramPair paramRemote paramDesc) (seek <$$> optParser) + (paramPair paramRepository paramDesc) (seek <$$> optParser) data GroupOptions = GroupOptions { cmdparams :: CmdParams @@ -29,7 +29,7 @@ data GroupOptions = GroupOptions optParser :: CmdParamsDesc -> Parser GroupOptions optParser desc = GroupOptions - <$> cmdParams desc + <$> cmdParamsWithCompleter desc completeRemotes <*> switch ( long "list" <> help "list all currently defined groups" diff --git a/Command/Info.hs b/Command/Info.hs index 2c989a91be..41f3a29655 100644 --- a/Command/Info.hs +++ b/Command/Info.hs @@ -116,7 +116,7 @@ data InfoOptions = InfoOptions optParser :: CmdParamsDesc -> Parser InfoOptions optParser desc = InfoOptions - <$> cmdParams desc + <$> cmdParamsWithCompleter desc (completeFiles <> completeRemotes) <*> switch ( long "bytes" <> help "display file sizes in bytes" diff --git a/Command/Semitrust.hs b/Command/Semitrust.hs index 6ab318ee1b..ecb281b50a 100644 --- a/Command/Semitrust.hs +++ b/Command/Semitrust.hs @@ -15,7 +15,8 @@ cmd :: Command cmd = withAnnexOptions [jsonOptions] $ command "semitrust" SectionSetup "return repository to default trust level" - (paramRepeating paramRepository) (withParams seek) + (paramRepeating paramRepository) + (withParams' seek completeRemotes) seek :: CmdParams -> CommandSeek seek = trustCommand "semitrust" SemiTrusted diff --git a/Command/Trust.hs b/Command/Trust.hs index c113c60bf1..eadb4e781b 100644 --- a/Command/Trust.hs +++ b/Command/Trust.hs @@ -19,7 +19,8 @@ import qualified Data.Set as S cmd :: Command cmd = withAnnexOptions [jsonOptions] $ command "trust" SectionSetup "trust a repository" - (paramRepeating paramRepository) (withParams seek) + (paramRepeating paramRepository) + (withParams' seek completeRemotes) seek :: CmdParams -> CommandSeek seek = trustCommand "trust" Trusted diff --git a/Command/Ungroup.hs b/Command/Ungroup.hs index e929b21199..2672b443e1 100644 --- a/Command/Ungroup.hs +++ b/Command/Ungroup.hs @@ -16,7 +16,8 @@ import qualified Data.Set as S cmd :: Command cmd = command "ungroup" SectionSetup "remove a repository from a group" - (paramPair paramRemote paramDesc) (withParams seek) + (paramPair paramRemote paramDesc) + (withParams' seek completeRemotes) seek :: CmdParams -> CommandSeek seek = withWords (commandAction . start) diff --git a/Command/Untrust.hs b/Command/Untrust.hs index ccefbbfdfa..688503ac7b 100644 --- a/Command/Untrust.hs +++ b/Command/Untrust.hs @@ -14,7 +14,8 @@ import Command.Trust (trustCommand) cmd :: Command cmd = withAnnexOptions [jsonOptions] $ command "untrust" SectionSetup "do not trust a repository" - (paramRepeating paramRepository) (withParams seek) + (paramRepeating paramRepository) + (withParams' seek completeRemotes) seek :: CmdParams -> CommandSeek seek = trustCommand "untrust" UnTrusted diff --git a/Command/Unused.hs b/Command/Unused.hs index 75cf94a3e2..85913a5782 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -56,6 +56,7 @@ optParser :: CmdParamsDesc -> Parser UnusedOptions optParser _ = UnusedOptions <$> optional (strOption ( long "from" <> short 'f' <> metavar paramRemote + <> completeRemotes <> help "remote to check for unused content" )) <*> optional (option (eitherReader parseRefSpec) diff --git a/Command/Wanted.hs b/Command/Wanted.hs index 589eab842c..9aeb58735d 100644 --- a/Command/Wanted.hs +++ b/Command/Wanted.hs @@ -27,7 +27,8 @@ cmd' -> (UUID -> PreferredContentExpression -> Annex ()) -> Command cmd' name desc getter setter = noMessages $ - command name SectionSetup desc pdesc (withParams seek) + command name SectionSetup desc pdesc + (withParams' seek completeRemotes) where pdesc = paramPair paramRemote (paramOptional paramExpression) -- 2.39.5