mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-12 16:38:28 -04:00
7974887295
- settings.json/session.json now store only values that differ from spec defaults - Machine-specific state moves out of settings.json into session.json - Add dms backup create/restore: tar.gz of ~/.config/DankMaterialShell fixes #3027
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/backup"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var backupOutputPath string
|
|
|
|
var backupCmd = &cobra.Command{
|
|
Use: "backup",
|
|
Short: "Backup and restore DMS configuration",
|
|
}
|
|
|
|
var backupCreateCmd = &cobra.Command{
|
|
Use: "create",
|
|
Short: "Create a tar.gz backup of ~/.config/DankMaterialShell (settings, plugins, themes)",
|
|
Args: cobra.NoArgs,
|
|
Run: runBackupCreate,
|
|
}
|
|
|
|
var backupRestoreCmd = &cobra.Command{
|
|
Use: "restore <archive>",
|
|
Short: "Restore a DMS configuration backup; the current configuration is moved aside first",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: runBackupRestore,
|
|
}
|
|
|
|
func init() {
|
|
backupCreateCmd.Flags().StringVarP(&backupOutputPath, "output", "o", "", "Output archive path (default dms-backup-<timestamp>.tar.gz)")
|
|
backupCmd.AddCommand(backupCreateCmd, backupRestoreCmd)
|
|
rootCmd.AddCommand(backupCmd)
|
|
}
|
|
|
|
func runBackupCreate(cmd *cobra.Command, args []string) {
|
|
output := backupOutputPath
|
|
if output == "" {
|
|
output = backup.DefaultArchiveName()
|
|
}
|
|
|
|
if err := backup.Create(output); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Println(output)
|
|
}
|
|
|
|
func runBackupRestore(cmd *cobra.Command, args []string) {
|
|
previous, err := backup.Restore(args[0])
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if previous != "" {
|
|
fmt.Printf("Previous configuration moved to %s\n", previous)
|
|
}
|
|
fmt.Println("Restore complete. Restart the shell to apply.")
|
|
}
|