1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-01-03 05:35:43 +00:00

cat: add subcommand completion

This commit is contained in:
Michael Eischer 2024-07-28 12:21:30 +02:00
parent ebc15b8680
commit bb50d86e68

View file

@ -12,6 +12,8 @@ import (
"github.com/restic/restic/internal/restic"
)
var catAllowedCmds = []string{"config", "index", "snapshot", "key", "masterkey", "lock", "pack", "blob", "tree"}
var cmdCat = &cobra.Command{
Use: "cat [flags] [masterkey|config|pack ID|blob ID|snapshot ID|index ID|key ID|lock ID|tree snapshot:subfolder]",
Short: "Print internal objects to stdout",
@ -30,6 +32,7 @@ Exit status is 11 if the repository is already locked.
RunE: func(cmd *cobra.Command, args []string) error {
return runCat(cmd.Context(), globalOptions, args)
},
ValidArgs: catAllowedCmds,
}
func init() {
@ -37,21 +40,19 @@ func init() {
}
func validateCatArgs(args []string) error {
var allowedCmds = []string{"config", "index", "snapshot", "key", "masterkey", "lock", "pack", "blob", "tree"}
if len(args) < 1 {
return errors.Fatal("type not specified")
}
validType := false
for _, v := range allowedCmds {
for _, v := range catAllowedCmds {
if v == args[0] {
validType = true
break
}
}
if !validType {
return errors.Fatalf("invalid type %q, must be one of [%s]", args[0], strings.Join(allowedCmds, "|"))
return errors.Fatalf("invalid type %q, must be one of [%s]", args[0], strings.Join(catAllowedCmds, "|"))
}
if args[0] != "masterkey" && args[0] != "config" && len(args) != 2 {