Skip to content

Commit

Permalink
cmd/backup: add back-compat for root commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie committed Dec 14, 2023
1 parent 9a08a12 commit 534c17e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion internal/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import (
)

var backupCmd = &cobra.Command{
Use: "backup <subcommand>",
Use: "backup <filename>",
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) {
Expand All @@ -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 <filename>",
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")
Expand All @@ -59,6 +71,16 @@ var backupCreateCmd = &cobra.Command{
RunE: backupCreateCmdFunc,
}

func registerLegacyBackupCommands(rootCmd *cobra.Command) {

Check failure on line 74 in internal/cmd/backup.go

View workflow job for this annotation

GitHub Actions / Lint Go

`registerLegacyBackupCommands` is unused (deadcode)
rootCmd.AddCommand(&cobra.Command{
Use: "backup <filename>",
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()
Expand Down

0 comments on commit 534c17e

Please sign in to comment.