@@ -21,15 +21,15 @@ func CreateShelf(cliCtx *cli.Context) error {
21
21
shelfName := cliCtx .Args ().First ()
22
22
23
23
if shelfName == "" {
24
- return errors .New ("Shelf name has to be given" )
24
+ return errors .New ("shelf name has to be given" )
25
25
}
26
26
27
27
shelfPath := path .Join (shelfDir , shelfName )
28
28
29
29
err = os .Mkdir (shelfPath , 0755 )
30
30
if err != nil {
31
31
if os .IsExist (err ) {
32
- return fmt .Errorf ("Shelf named: \" %s\" already exist" , shelfName )
32
+ return fmt .Errorf ("shelf named: \" %s\" already exist" , shelfName )
33
33
}
34
34
return err
35
35
}
@@ -69,19 +69,19 @@ func TrackFile(cliCtx *cli.Context) error {
69
69
70
70
shelfName := cliCtx .Args ().Get (0 )
71
71
if shelfName == "" {
72
- return errors .New ("Shelf name has to be given" )
72
+ return errors .New ("shelf name has to be given" )
73
73
}
74
74
75
75
filePath := cliCtx .Args ().Get (1 )
76
76
if filePath == "" {
77
- return errors .New ("File path to track can't be blank" )
77
+ return errors .New ("file path to track can't be blank" )
78
78
}
79
79
80
80
// Check if the given shelf exists
81
81
_ , err = os .Stat (path .Join (shelfDir , shelfName ))
82
82
if err != nil {
83
83
if os .IsNotExist (err ) {
84
- return fmt .Errorf ("Shelf named: %s doesn't exist" , shelfName )
84
+ return fmt .Errorf ("shelf named: %s doesn't exist" , shelfName )
85
85
}
86
86
return err
87
87
}
@@ -165,7 +165,7 @@ func CloneShelf(cliCtx *cli.Context) error {
165
165
166
166
url := cliCtx .Args ().First ()
167
167
if url == "" {
168
- return errors .New ("Git repo url for the shelf has to be provided" )
168
+ return errors .New ("git repo url for the shelf has to be provided" )
169
169
}
170
170
171
171
fmt .Printf ("[*] Cloning from %s\n " , url )
@@ -186,12 +186,12 @@ func SnapshotGitShelf(cliCtx *cli.Context) error {
186
186
}
187
187
shelfName := cliCtx .Args ().First ()
188
188
if shelfName == "" {
189
- return errors .New ("Shelf name can't be empty" )
189
+ return errors .New ("shelf name can't be empty" )
190
190
}
191
191
directory := path .Join (shelfDir , shelfName )
192
192
err = createGitSnapshot (directory )
193
193
if err != nil {
194
- return fmt .Errorf ("Error while creating a snapshot with git: %w" , err )
194
+ return fmt .Errorf ("error while creating a snapshot with git: %w" , err )
195
195
}
196
196
return nil
197
197
}
@@ -205,16 +205,16 @@ func SnapshotArchiveShelf(cliCtx *cli.Context) error {
205
205
shelfName := cliCtx .Args ().First ()
206
206
outputDir := cliCtx .String ("output" )
207
207
if shelfName == "" {
208
- return errors .New ("Shelf name can't be empty" )
208
+ return errors .New ("shelf name can't be empty" )
209
209
}
210
210
if outputDir == "" {
211
- return errors .New ("Output path can't be empty" )
211
+ return errors .New ("output path can't be empty" )
212
212
}
213
213
directory := path .Join (shelfDir , shelfName )
214
214
outputPath := path .Join (outputDir , fmt .Sprintf ("%s.tar.gz" , shelfName ))
215
215
err = createArchiveSnapshot (directory , outputPath )
216
216
if err != nil {
217
- return fmt .Errorf ("Error while creating a snapshot with archive: %w" , err )
217
+ return fmt .Errorf ("error while creating a snapshot with archive: %w" , err )
218
218
}
219
219
return nil
220
220
}
@@ -228,7 +228,7 @@ func RestoreShelf(cliCtx *cli.Context) error {
228
228
229
229
shelfName := cliCtx .Args ().First ()
230
230
if shelfName == "" {
231
- return errors .New ("Shelf name can't be empty" )
231
+ return errors .New ("shelf name can't be empty" )
232
232
}
233
233
234
234
shelfPath := path .Join (shelfDir , shelfName )
@@ -237,7 +237,7 @@ func RestoreShelf(cliCtx *cli.Context) error {
237
237
_ , err = os .Stat (shelfPath )
238
238
if err != nil {
239
239
if os .IsNotExist (err ) {
240
- return fmt .Errorf ("Shelf named: %s doesn't exist" , shelfName )
240
+ return fmt .Errorf ("shelf named: %s doesn't exist" , shelfName )
241
241
}
242
242
return err
243
243
}
@@ -313,3 +313,27 @@ func WhereShelf(cliCtx *cli.Context) error {
313
313
fmt .Println (shelfPath )
314
314
return nil
315
315
}
316
+
317
+ func GetListOfFilesInShelf (cliCtx * cli.Context ) error {
318
+ home , err := GetOrCreateShelvesDir ()
319
+ if err != nil {
320
+ return err
321
+ }
322
+ shelfName := cliCtx .Args ().First ()
323
+ if shelfName == "" {
324
+ return errors .New ("shelf name can't be empty" )
325
+ }
326
+
327
+ shelfPath := path .Join (home , shelfName )
328
+
329
+ db , _ , err := GetDB (shelfPath )
330
+ if err != nil {
331
+ return err
332
+ }
333
+ fmt .Printf ("List of files tracked in shelf %s are:\n " , shelfName )
334
+ links := db .GetLinks ()
335
+ for _ , v := range links {
336
+ fmt .Println (v )
337
+ }
338
+ return nil
339
+ }
0 commit comments