Skip to content

Commit

Permalink
fix(CLI): crash when target/params section is empty #STRINGS-921 (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
jablan authored Nov 27, 2024
1 parent 25818b7 commit 03032c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clients/cli/cmd/internal/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (cmd *PullCommand) Run(config *phrase.Config) error {
target.Params.Branch = optional.NewString(cmd.Branch)
}

val, ok := localesCache[LocalesCacheKey{target.ProjectID, target.Params.Branch.Value()}]
val, ok := localesCache[LocalesCacheKey{target.ProjectID, target.GetBranch()}]
if !ok || len(val) == 0 {
if cmd.Branch != "" {
continue
Expand Down
9 changes: 8 additions & 1 deletion clients/cli/cmd/internal/pull_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Targets []*Target
func (targets Targets) GetAllLocalesCacheKeys() []LocalesCacheKey {
localesCacheKeys := []LocalesCacheKey{}
for _, target := range targets {
localesCacheKeys = append(localesCacheKeys, LocalesCacheKey{target.ProjectID, target.Params.Branch.Value()})
localesCacheKeys = append(localesCacheKeys, LocalesCacheKey{target.ProjectID, target.GetBranch()})
}
return localesCacheKeys
}
Expand All @@ -32,6 +32,13 @@ type Target struct {
RemoteLocales []*phrase.Locale
}

func (target *Target) GetBranch() string {
if target.Params != nil {
return target.Params.Branch.Value()
}
return ""
}

func (target *Target) CheckPreconditions() error {
if err := paths.Validate(target.File, target.FileFormat, ""); err != nil {
return err
Expand Down

0 comments on commit 03032c4

Please sign in to comment.