-
-
Notifications
You must be signed in to change notification settings - Fork 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cli] Add filters for Export (#2596)
## Description Feature: Add support for selective export with filters for account, albums, and options to exclude hidden or shared files. Flags Added: --shared: Include shared albums in export (default: true). --hidden: Include hidden albums in export (default: true). --albums: Comma-separated list of album names to export. --emails: Comma-separated list of emails of the accounts that needs to be exported Behavior: By default, both hidden and shared albums are exported. ## Tests Tested locally
- Loading branch information
Showing
10 changed files
with
152 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/ente-io/cli/pkg/model" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// versionCmd represents the version command | ||
// exportCmd represents the export command | ||
var exportCmd = &cobra.Command{ | ||
Use: "export", | ||
Short: "Starts the export process", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ctrl.Export() | ||
// Retrieve flag values | ||
shared, _ := cmd.Flags().GetBool("shared") | ||
hidden, _ := cmd.Flags().GetBool("hidden") | ||
albums, _ := cmd.Flags().GetStringSlice("albums") | ||
emails, _ := cmd.Flags().GetStringSlice("emails") | ||
// Create Filters struct with flag values | ||
filters := model.Filter{ | ||
ExcludeShared: !shared, | ||
ExcludeHidden: !hidden, | ||
Albums: albums, | ||
Emails: emails, | ||
} | ||
// Call the Export function with the filters | ||
ctrl.Export(filters) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(exportCmd) | ||
|
||
// Add flags for Filters struct fields with default value true | ||
exportCmd.Flags().Bool("shared", true, "to exclude shared albums, pass --shared=false") | ||
exportCmd.Flags().Bool("hidden", true, "to exclude hidden albums, pass --hidden=false") | ||
exportCmd.Flags().StringSlice("albums", []string{}, "Comma-separated list of album names to export") | ||
exportCmd.Flags().StringSlice("emails", []string{}, "Comma-separated list of emails to export files shared with") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package export | ||
|
||
type Filters struct { | ||
// When true, none of the shared albums are exported | ||
ExcludeShared bool | ||
// When true, none of the shared files are exported | ||
ExcludeSharedFiles bool | ||
// When true, hidden albums are not exported | ||
ExcludeHidden bool | ||
// when album name is provided, only files in those albums are exported | ||
Albums []string | ||
// when email is provided, only files shared with that email are exported | ||
Emails []string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package model | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
) | ||
|
||
type Filter struct { | ||
// When true, none of the shared albums are exported | ||
ExcludeShared bool | ||
// When true, none of the shared files are exported | ||
ExcludeSharedFiles bool | ||
// When true, hidden albums are not exported | ||
ExcludeHidden bool | ||
// when album name is provided, only files in those albums are exported | ||
Albums []string | ||
// when email is provided, only files shared with that email are exported | ||
Emails []string | ||
} | ||
|
||
func (f Filter) SkipAccount(email string) bool { | ||
if len(f.Emails) == 0 { | ||
return false | ||
} | ||
for _, e := range f.Emails { | ||
if strings.ToLower(e) == strings.ToLower(strings.TrimSpace(email)) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func (f Filter) SkipAlbum(album RemoteAlbum, shouldLog bool) bool { | ||
if f.excludeByName(album) { | ||
if shouldLog { | ||
log.Printf("Skipping album %s as it's not part of album to export", album.AlbumName) | ||
} | ||
return true | ||
} | ||
if f.ExcludeShared && album.IsShared { | ||
if shouldLog { | ||
log.Printf("Skipping album %s as it's shared", album.AlbumName) | ||
} | ||
return true | ||
} | ||
if f.ExcludeHidden && album.IsHidden() { | ||
if shouldLog { | ||
log.Printf("Skipping album %s as it's hidden", album.AlbumName) | ||
} | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// excludeByName returns true if albums list is not empty and album name is not in the list | ||
func (f Filter) excludeByName(album RemoteAlbum) bool { | ||
if len(f.Albums) > 0 { | ||
for _, a := range f.Albums { | ||
if strings.ToLower(a) == strings.ToLower(strings.TrimSpace(album.AlbumName)) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters