feat: auto-detect encrypted files + CLI --password flag

- Storage.IsDataEncrypted() checks if hosts.json is encrypted
- TUI auto-detects encrypted files, prompts password automatically
- Root command: --password flag for all CLI commands
- newStorage() helper applies password flag to storage
- add/list/edit/delete commands now support encrypted storage
- passwordSetMsg loads hosts after password is set
This commit is contained in:
swanadiva
2026-06-25 14:34:41 +07:00
parent 94f2142d3d
commit 93957e3989
8 changed files with 67 additions and 22 deletions
+2 -3
View File
@@ -13,7 +13,6 @@ import (
"git.tukangketik.id/swanadiva/hostkeeper/internal/models"
"git.tukangketik.id/swanadiva/hostkeeper/pkg/config"
"git.tukangketik.id/swanadiva/hostkeeper/pkg/storage"
)
var (
@@ -155,7 +154,7 @@ func runAddHost(cmd *cobra.Command, args []string) error {
}
// Initialize storage
store, err := storage.NewJSONStorage(cfg.GetDataDir())
store, err := newStorage(cfg)
if err != nil {
return fmt.Errorf("failed to initialize storage: %w", err)
}
@@ -278,7 +277,7 @@ func addHostInteractive(cfg *config.Config) error {
}
// Initialize storage
store, err := storage.NewJSONStorage(cfg.GetDataDir())
store, err := newStorage(cfg)
if err != nil {
return fmt.Errorf("failed to initialize storage: %w", err)
}