9
9
"strconv"
10
10
11
11
"github.com/OpenListTeam/OpenList/v4/internal/db"
12
+ "github.com/OpenListTeam/OpenList/v4/pkg/utils"
12
13
"github.com/charmbracelet/bubbles/table"
13
14
tea "github.com/charmbracelet/bubbletea"
14
15
"github.com/charmbracelet/lipgloss"
@@ -22,8 +23,8 @@ var storageCmd = &cobra.Command{
22
23
}
23
24
24
25
var disableStorageCmd = & cobra.Command {
25
- Use : "disable" ,
26
- Short : "Disable a storage" ,
26
+ Use : "disable [mount path] " ,
27
+ Short : "Disable a storage by mount path " ,
27
28
RunE : func (cmd * cobra.Command , args []string ) error {
28
29
if len (args ) < 1 {
29
30
return fmt .Errorf ("mount path is required" )
@@ -34,15 +35,48 @@ var disableStorageCmd = &cobra.Command{
34
35
storage , err := db .GetStorageByMountPath (mountPath )
35
36
if err != nil {
36
37
return fmt .Errorf ("failed to query storage: %+v" , err )
37
- } else {
38
- storage .Disabled = true
39
- err = db .UpdateStorage (storage )
40
- if err != nil {
41
- return fmt .Errorf ("failed to update storage: %+v" , err )
42
- } else {
43
- fmt .Printf ("Storage with mount path [%s] have been disabled\n " , mountPath )
38
+ }
39
+ storage .Disabled = true
40
+ err = db .UpdateStorage (storage )
41
+ if err != nil {
42
+ return fmt .Errorf ("failed to update storage: %+v" , err )
43
+ }
44
+ utils .Log .Infof ("Storage with mount path [%s] has been disabled from CLI" , mountPath )
45
+ fmt .Printf ("Storage with mount path [%s] has been disabled\n " , mountPath )
46
+ return nil
47
+ },
48
+ }
49
+
50
+ var deleteStorageCmd = & cobra.Command {
51
+ Use : "delete [id]" ,
52
+ Short : "Delete a storage by id" ,
53
+ RunE : func (cmd * cobra.Command , args []string ) error {
54
+ if len (args ) < 1 {
55
+ return fmt .Errorf ("id is required" )
56
+ }
57
+ id , err := strconv .Atoi (args [0 ])
58
+ if err != nil {
59
+ return fmt .Errorf ("id must be a number" )
60
+ }
61
+
62
+ if force , _ := cmd .Flags ().GetBool ("force" ); force {
63
+ fmt .Printf ("Are you sure you want to delete storage with id [%d]? [y/N]: " , id )
64
+ var confirm string
65
+ fmt .Scanln (& confirm )
66
+ if confirm != "y" && confirm != "Y" {
67
+ fmt .Println ("Delete operation cancelled." )
68
+ return nil
44
69
}
45
70
}
71
+
72
+ Init ()
73
+ defer Release ()
74
+ err = db .DeleteStorageById (uint (id ))
75
+ if err != nil {
76
+ return fmt .Errorf ("failed to delete storage by id: %+v" , err )
77
+ }
78
+ utils .Log .Infof ("Storage with id [%d] have been deleted from CLI" , id )
79
+ fmt .Printf ("Storage with id [%d] have been deleted\n " , id )
46
80
return nil
47
81
},
48
82
}
@@ -152,6 +186,8 @@ func init() {
152
186
storageCmd .AddCommand (disableStorageCmd )
153
187
storageCmd .AddCommand (listStorageCmd )
154
188
storageCmd .PersistentFlags ().IntVarP (& storageTableHeight , "height" , "H" , 10 , "Table height" )
189
+ storageCmd .AddCommand (deleteStorageCmd )
190
+ deleteStorageCmd .Flags ().BoolP ("force" , "f" , false , "Force delete without confirmation" )
155
191
// Here you will define your flags and configuration settings.
156
192
157
193
// Cobra supports Persistent Flags which will work for this command
0 commit comments