From 534c17ec2f04f837bb4c9604dad5edd72afdc987 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Thu, 14 Dec 2023 12:26:42 -0500 Subject: [PATCH] cmd/backup: add back-compat for root commands --- internal/cmd/backup.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/cmd/backup.go b/internal/cmd/backup.go index 31bc604d..bd87641b 100644 --- a/internal/cmd/backup.go +++ b/internal/cmd/backup.go @@ -26,8 +26,11 @@ import ( ) var backupCmd = &cobra.Command{ - Use: "backup ", + Use: "backup ", Short: "create, restore, and inspect Permissions System backups", + Args: cobra.ExactArgs(1), + // Create used to be on the root, so add it here for back-compat. + RunE: backupCreateCmdFunc, } func registerBackupCmd(rootCmd *cobra.Command) { @@ -43,6 +46,15 @@ func registerBackupCmd(rootCmd *cobra.Command) { backupRestoreCmd.Flags().String("prefix-filter", "", "include only schema and relationships with a given prefix") backupRestoreCmd.Flags().Bool("rewrite-legacy", false, "potentially modify the schema to exclude legacy/broken syntax") + // Restore used to be on the root, so add it there too, but hidden. + rootCmd.AddCommand(&cobra.Command{ + Use: "restore ", + Short: "Restore a permission system from a file", + Args: cobra.MaximumNArgs(1), + RunE: restoreCmdFunc, + Hidden: true, + }) + backupCmd.AddCommand(backupParseSchemaCmd) backupParseSchemaCmd.Flags().String("prefix-filter", "", "include only schema and relationships with a given prefix") backupParseSchemaCmd.Flags().Bool("rewrite-legacy", false, "potentially modify the schema to exclude legacy/broken syntax") @@ -59,6 +71,16 @@ var backupCreateCmd = &cobra.Command{ RunE: backupCreateCmdFunc, } +func registerLegacyBackupCommands(rootCmd *cobra.Command) { + rootCmd.AddCommand(&cobra.Command{ + Use: "backup ", + Short: "Backup a permission system to a file", + Args: cobra.ExactArgs(1), + RunE: backupCreateCmdFunc, + Hidden: true, + }) +} + func createBackupFile(filename string) (*os.File, error) { if filename == "-" { log.Trace().Str("filename", "- (stdout)").Send()