Skip to content

Commit

Permalink
Move deprecated CreateAlbums option normalization to config package
Browse files Browse the repository at this point in the history
Signed-off-by: pacoorozco <[email protected]>
  • Loading branch information
pacoorozco committed Oct 23, 2023
1 parent a8f4e33 commit 9367625
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
10 changes: 1 addition & 9 deletions internal/cli/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ func (cmd *PushCmd) Run(cobraCmd *cobra.Command, args []string) error {
}

// launch all folder upload jobs
for _, config := range cli.Config.Jobs {

// TODO: CreateAlbums is maintained to ensure backwards compatibility.
//nolint:staticcheck // I want to use deprecated method.
if config.Album == "" && config.CreateAlbums != "" && config.CreateAlbums != "Off" {
//nolint:staticcheck // I want to use deprecated method.
config.Album = "auto:" + config.CreateAlbums
}

for _, config := range cli.Config.GetJobs() {
sourceFolder := config.SourceFolder

filterFiles, err := filter.Compile(config.IncludePatterns, config.ExcludePatterns)
Expand Down
14 changes: 13 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ func (c Config) validateJobs(fs afero.Fs) error {
return nil
}

// GetJobs returns the configured Jobs without deprecated options.
func (c Config) GetJobs() []FolderUploadJob {
jobs := c.Jobs

// TODO: Translate the deprecated CreateAlbums into the Albums option for backwards compatibility
for _, j := range jobs {
if j.Album == "" && j.CreateAlbums != "" && j.CreateAlbums != "Off" {
j.Album = "auto:" + j.CreateAlbums
}

Check warning on line 164 in internal/config/config.go

View check run for this annotation

Codecov / codecov/patch

internal/config/config.go#L157-L164

Added lines #L157 - L164 were not covered by tests
}
return jobs

Check warning on line 166 in internal/config/config.go

View check run for this annotation

Codecov / codecov/patch

internal/config/config.go#L166

Added line #L166 was not covered by tests
}

func (c Config) validateSecretsBackendType() error {
switch c.SecretsBackendType {
case "auto", "secret-service", "keychain", "kwallet", "file":
Expand Down Expand Up @@ -249,7 +262,6 @@ func defaultSettings() Config {
{
SourceFolder: "YOUR_FOLDER_PATH",
Album: "",
CreateAlbums: "folderName",
DeleteAfterUpload: false,
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/config/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type FolderUploadJob struct {
// will be selected)
// "auto:" : Followed either "folderPath" or "folderName" will use an autogenerated album name based on the
// object's folder path or object's folder name.
Album string `json:"Album"`
Album string `json:"Album,omitempty"`

// CreateAlbums is the parameter to create albums on Google Photos.
//
Expand Down

0 comments on commit 9367625

Please sign in to comment.