Skip to content
This repository has been archived by the owner on Dec 18, 2020. It is now read-only.

Commit

Permalink
adds --verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
fredv committed Jul 15, 2015
1 parent 897fa27 commit c075423
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 94 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.phraseapp.yml
5 changes: 3 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const configName = ".phraseapp.yml"
const defaultDir = ".config/phraseapp"
const defaultDir = "./"

func ConfigDefaultCredentials() (*phraseapp.AuthCredentials, error) {
content, err := ConfigContent()
Expand Down Expand Up @@ -92,6 +92,7 @@ type credentialConf struct {
Phraseapp struct {
AccessToken string `yaml:"access_token"`
Host string `yaml:"host"`
Debug bool `yaml:"verbose"`
Username string
TFA bool
}
Expand All @@ -106,7 +107,7 @@ func parseCredentials(yml string) (*phraseapp.AuthCredentials, error) {
}

phrase := conf.Phraseapp
credentials := &phraseapp.AuthCredentials{Token: phrase.AccessToken, Username: phrase.Username, TFA: phrase.TFA, Host: phrase.Host}
credentials := &phraseapp.AuthCredentials{Token: phrase.AccessToken, Username: phrase.Username, TFA: phrase.TFA, Host: phrase.Host, Debug: phrase.Debug}

return credentials, nil
}
Expand Down
20 changes: 14 additions & 6 deletions pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type PullParams struct {
FormatOptions *map[string]interface{} `yaml:"format_options,omitempty"`
IncludeEmptyTranslations *bool `yaml:"include_empty_translations,omitempty"`
KeepNotranslateTags *bool `yaml:"keep_notranslate_tags,omitempty"`
TagId *string `yaml:"tag_id,omitempty"`
Tag *string `yaml:"tag,omitempty"`
}

func (t *Target) GetFormat() string {
Expand All @@ -45,6 +45,13 @@ func (t *Target) GetLocaleId() string {
return ""
}

func (t *Target) GetTag() string {
if t.Params != nil && t.Params.Tag != nil {
return *t.Params.Tag
}
return ""
}

func PullAll(targets Targets) error {
alreadySeen := []string{}
for _, target := range targets {
Expand All @@ -70,7 +77,8 @@ func (target *Target) Pull(alreadySeen []string) ([]string, error) {
return nil, err
}

localeToPathMapping, err := ExpandPathsWithLocale(p, target.GetLocaleId(), locales)
info := &LocaleFileNameInfo{LocaleId: target.GetLocaleId(), Tag: target.GetTag()}
localeToPathMapping, err := ExpandPathsWithLocale(p, locales, info)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -115,7 +123,7 @@ func downloadAndWriteToFile(target *Target, localePath *LocalePath) error {
if params != nil && params.LocaleId != "" {
localeId = params.LocaleId
} else {
localeId = localePath.LocaleId
localeId = localePath.Info.LocaleId
}

res, err := phraseapp.LocaleDownload(target.ProjectId, localeId, downloadParams)
Expand Down Expand Up @@ -171,9 +179,9 @@ func setDownloadParams(target *Target, localePath *LocalePath) *phraseapp.Locale
downloadParams.KeepNotranslateTags = keepNotranslateTags
}

tagId := params.TagId
if tagId != nil {
downloadParams.TagId = tagId
tag := params.Tag
if tag != nil {
downloadParams.Tag = tag
}

return downloadParams
Expand Down
20 changes: 18 additions & 2 deletions push.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type PushParams struct {
SkipUnverification *bool `yaml:"skip_unverification,omitempty"`
SkipUploadTags *bool `yaml:"skip_upload_tags,omitempty"`
Tags []string `yaml:"tags,omitempty"`
Tag *string `yaml:"tag,omitempty"`
UpdateTranslations *bool `yaml:"update_translations,omitempty"`
}

Expand All @@ -49,6 +50,13 @@ func (s *Source) GetLocaleId() string {
return ""
}

func (s *Source) GetTag() string {
if s.Params != nil && s.Params.Tag != nil {
return *s.Params.Tag
}
return ""
}

func PushAll(sources Sources) error {
alreadySeen := []string{}
for _, source := range sources {
Expand All @@ -74,7 +82,8 @@ func (source *Source) Push(alreadySeen []string) ([]string, error) {
return nil, err
}

localeToPathMapping, err := ExpandPathsWithLocale(p, source.GetLocaleId(), locales)
info := &LocaleFileNameInfo{LocaleId: source.GetLocaleId(), Tag: source.GetTag()}
localeToPathMapping, err := ExpandPathsWithLocale(p, locales, info)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -150,7 +159,7 @@ func setUploadParams(source *Source, localePath *LocalePath) (*phraseapp.LocaleF
uploadParams := new(phraseapp.LocaleFileImportParams)
uploadParams.File = localePath.Path
uploadParams.FileFormat = &source.FileFormat
remoteLocaleId := localePath.LocaleId
remoteLocaleId := localePath.Info.LocaleId

if remoteLocaleId != "" {
uploadParams.LocaleId = &remoteLocaleId
Expand Down Expand Up @@ -193,6 +202,13 @@ func setUploadParams(source *Source, localePath *LocalePath) (*phraseapp.LocaleF
}

tags := params.Tags
info := localePath.Info
if info != nil && info.Tag != "" {
if tags == nil {
tags = make([]string, 0)
}
tags = append(tags, info.Tag)
}
if tags != nil {
uploadParams.Tags = tags
}
Expand Down
Loading

0 comments on commit c075423

Please sign in to comment.