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.
This commit is contained in:
Joey Hess 2024-06-30 12:39:18 -04:00
parent 3d646703ee
commit 0033e6c0a6
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
13 changed files with 33 additions and 14 deletions

View file

@ -12,6 +12,8 @@ git-annex (10.20240532) UNRELEASED; urgency=medium
complaining about missing tree objects. complaining about missing tree objects.
* Tab completion of options like --from now includes special remotes, * Tab completion of options like --from now includes special remotes,
as well as proxied remotes and clusters. as well as proxied remotes and clusters.
* Tab completion of many commands like info and trust now includes
remotes.
* P2P protocol version 2. * P2P protocol version 2.
* Fix Windows build with Win32 2.13.4+ * Fix Windows build with Win32 2.13.4+
Thanks, Oleg Tolmatcev Thanks, Oleg Tolmatcev

View file

@ -1,6 +1,6 @@
{- git-annex command-line option parsing {- git-annex command-line option parsing
- -
- Copyright 2010-2023 Joey Hess <id@joeyh.name> - Copyright 2010-2024 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - Licensed under the GNU AGPL version 3 or higher.
-} -}
@ -109,9 +109,12 @@ gitAnnexCommonOptions = commonOptions ++
{- Parser that accepts all non-option params. -} {- Parser that accepts all non-option params. -}
cmdParams :: CmdParamsDesc -> Parser CmdParams 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 ( metavar paramdesc
<> action "file" <> completers
) )
parseAutoOption :: Parser Bool parseAutoOption :: Parser Bool
@ -597,3 +600,7 @@ completeRemotes' g input = do
completeBackends :: HasCompleter f => Mod f a completeBackends :: HasCompleter f => Mod f a
completeBackends = completeWith $ completeBackends = completeWith $
map (decodeBS . formatKeyVariety . Backend.backendVariety) Backend.builtinList map (decodeBS . formatKeyVariety . Backend.backendVariety) Backend.builtinList
completeFiles :: HasCompleter f => Mod f a
completeFiles = action "file"

View file

@ -40,6 +40,10 @@ command name section desc paramdesc mkparser =
withParams :: (CmdParams -> v) -> CmdParamsDesc -> Parser v withParams :: (CmdParams -> v) -> CmdParamsDesc -> Parser v
withParams mkseek paramdesc = mkseek <$> cmdParams paramdesc 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, {- Uses the supplied option parser, which yields a deferred parse,
- and calls finishParse on the result before passing it to the - and calls finishParse on the result before passing it to the
- CommandSeek constructor. -} - CommandSeek constructor. -}

View file

@ -22,7 +22,7 @@ cmd = withAnnexOptions [jsonOptions] $
data DeadOptions = DeadRemotes [RemoteName] | DeadKeys [Key] data DeadOptions = DeadRemotes [RemoteName] | DeadKeys [Key]
optParser :: CmdParamsDesc -> Parser DeadOptions optParser :: CmdParamsDesc -> Parser DeadOptions
optParser desc = (DeadRemotes <$> cmdParams desc) optParser desc = (DeadRemotes <$> cmdParamsWithCompleter desc completeRemotes)
<|> (DeadKeys <$> many (option (str >>= parseKey) <|> (DeadKeys <$> many (option (str >>= parseKey)
( long "key" <> metavar paramKey ( long "key" <> metavar paramKey
<> help "keys whose content has been irretrievably lost" <> help "keys whose content has been irretrievably lost"

View file

@ -14,8 +14,8 @@ import Logs.UUID
cmd :: Command cmd :: Command
cmd = command "describe" SectionSetup cmd = command "describe" SectionSetup
"change description of a repository" "change description of a repository"
(paramPair paramRemote paramDesc) (paramPair paramRepository paramDesc)
(withParams seek) (withParams' seek completeRemotes)
seek :: CmdParams -> CommandSeek seek :: CmdParams -> CommandSeek
seek = withWords (commandAction . start) seek = withWords (commandAction . start)

View file

@ -20,7 +20,7 @@ import qualified Data.Map as M
cmd :: Command cmd :: Command
cmd = noMessages $ command "group" SectionSetup "add a repository to a group" cmd = noMessages $ command "group" SectionSetup "add a repository to a group"
(paramPair paramRemote paramDesc) (seek <$$> optParser) (paramPair paramRepository paramDesc) (seek <$$> optParser)
data GroupOptions = GroupOptions data GroupOptions = GroupOptions
{ cmdparams :: CmdParams { cmdparams :: CmdParams
@ -29,7 +29,7 @@ data GroupOptions = GroupOptions
optParser :: CmdParamsDesc -> Parser GroupOptions optParser :: CmdParamsDesc -> Parser GroupOptions
optParser desc = GroupOptions optParser desc = GroupOptions
<$> cmdParams desc <$> cmdParamsWithCompleter desc completeRemotes
<*> switch <*> switch
( long "list" ( long "list"
<> help "list all currently defined groups" <> help "list all currently defined groups"

View file

@ -116,7 +116,7 @@ data InfoOptions = InfoOptions
optParser :: CmdParamsDesc -> Parser InfoOptions optParser :: CmdParamsDesc -> Parser InfoOptions
optParser desc = InfoOptions optParser desc = InfoOptions
<$> cmdParams desc <$> cmdParamsWithCompleter desc (completeFiles <> completeRemotes)
<*> switch <*> switch
( long "bytes" ( long "bytes"
<> help "display file sizes in bytes" <> help "display file sizes in bytes"

View file

@ -15,7 +15,8 @@ cmd :: Command
cmd = withAnnexOptions [jsonOptions] $ cmd = withAnnexOptions [jsonOptions] $
command "semitrust" SectionSetup command "semitrust" SectionSetup
"return repository to default trust level" "return repository to default trust level"
(paramRepeating paramRepository) (withParams seek) (paramRepeating paramRepository)
(withParams' seek completeRemotes)
seek :: CmdParams -> CommandSeek seek :: CmdParams -> CommandSeek
seek = trustCommand "semitrust" SemiTrusted seek = trustCommand "semitrust" SemiTrusted

View file

@ -19,7 +19,8 @@ import qualified Data.Set as S
cmd :: Command cmd :: Command
cmd = withAnnexOptions [jsonOptions] $ cmd = withAnnexOptions [jsonOptions] $
command "trust" SectionSetup "trust a repository" command "trust" SectionSetup "trust a repository"
(paramRepeating paramRepository) (withParams seek) (paramRepeating paramRepository)
(withParams' seek completeRemotes)
seek :: CmdParams -> CommandSeek seek :: CmdParams -> CommandSeek
seek = trustCommand "trust" Trusted seek = trustCommand "trust" Trusted

View file

@ -16,7 +16,8 @@ import qualified Data.Set as S
cmd :: Command cmd :: Command
cmd = command "ungroup" SectionSetup "remove a repository from a group" 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 :: CmdParams -> CommandSeek
seek = withWords (commandAction . start) seek = withWords (commandAction . start)

View file

@ -14,7 +14,8 @@ import Command.Trust (trustCommand)
cmd :: Command cmd :: Command
cmd = withAnnexOptions [jsonOptions] $ cmd = withAnnexOptions [jsonOptions] $
command "untrust" SectionSetup "do not trust a repository" command "untrust" SectionSetup "do not trust a repository"
(paramRepeating paramRepository) (withParams seek) (paramRepeating paramRepository)
(withParams' seek completeRemotes)
seek :: CmdParams -> CommandSeek seek :: CmdParams -> CommandSeek
seek = trustCommand "untrust" UnTrusted seek = trustCommand "untrust" UnTrusted

View file

@ -56,6 +56,7 @@ optParser :: CmdParamsDesc -> Parser UnusedOptions
optParser _ = UnusedOptions optParser _ = UnusedOptions
<$> optional (strOption <$> optional (strOption
( long "from" <> short 'f' <> metavar paramRemote ( long "from" <> short 'f' <> metavar paramRemote
<> completeRemotes
<> help "remote to check for unused content" <> help "remote to check for unused content"
)) ))
<*> optional (option (eitherReader parseRefSpec) <*> optional (option (eitherReader parseRefSpec)

View file

@ -27,7 +27,8 @@ cmd'
-> (UUID -> PreferredContentExpression -> Annex ()) -> (UUID -> PreferredContentExpression -> Annex ())
-> Command -> Command
cmd' name desc getter setter = noMessages $ cmd' name desc getter setter = noMessages $
command name SectionSetup desc pdesc (withParams seek) command name SectionSetup desc pdesc
(withParams' seek completeRemotes)
where where
pdesc = paramPair paramRemote (paramOptional paramExpression) pdesc = paramPair paramRemote (paramOptional paramExpression)