diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-19 22:46:05 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-19 22:46:05 +0200 |
| commit | 836d21a7c43f4ce84dfa1ada0552989be4a43ca9 (patch) | |
| tree | fe6dc637c2c916e10b1beff31d687edf0f994503 /internal/entry | |
| parent | 1550fbf9c2b0602c4675f25cd92e389593894e58 (diff) | |
use of platform aliases
Diffstat (limited to 'internal/entry')
| -rw-r--r-- | internal/entry/entry.go | 7 | ||||
| -rw-r--r-- | internal/entry/sharetags.go | 4 | ||||
| -rw-r--r-- | internal/entry/sharetags_test.go | 11 |
3 files changed, 15 insertions, 7 deletions
diff --git a/internal/entry/entry.go b/internal/entry/entry.go index d289e83..e71f25b 100644 --- a/internal/entry/entry.go +++ b/internal/entry/entry.go @@ -11,6 +11,7 @@ import ( "codeberg.org/snonux/gos/internal/config" "codeberg.org/snonux/gos/internal/oi" + "codeberg.org/snonux/gos/internal/platforms" "codeberg.org/snonux/gos/internal/prompt" "codeberg.org/snonux/gos/internal/timestamp" ) @@ -155,10 +156,10 @@ func (en Entry) HasTag(tag string) bool { // Valid tags are: share:foo[,...] // whereas foo can be a supported plutform such as linkedin, mastodon, etc. // foo can also be prefixed with - to exclude it. See unit tests for examples. -func (en Entry) PlatformExcluded(args config.Args, platform string) (bool, error) { +func (en Entry) PlatformExcluded(args config.Args, platform platforms.Platform) (bool, error) { s, err := newShareTags(args, en.tags) - return slices.Contains(s.excludes, strings.ToLower(platform)) || - !slices.Contains(s.includes, strings.ToLower(platform)), err + return slices.Contains(s.excludes, platform.String()) || + !slices.Contains(s.includes, platform.String()), err } func (en Entry) Edit() error { diff --git a/internal/entry/sharetags.go b/internal/entry/sharetags.go index c0b855a..666a3d4 100644 --- a/internal/entry/sharetags.go +++ b/internal/entry/sharetags.go @@ -30,10 +30,10 @@ func newShareTags(args config.Args, tags map[string]struct{}) (shareTags, error) if len(s.includes) == 0 { for platform := range args.Platforms { - if slices.Contains(s.excludes, strings.ToLower(platform)) { + if slices.Contains(s.excludes, platform.String()) { continue } - s.includes = append(s.includes, strings.ToLower(platform)) + s.includes = append(s.includes, platform.String()) } } diff --git a/internal/entry/sharetags_test.go b/internal/entry/sharetags_test.go index 60589f5..7b1d742 100644 --- a/internal/entry/sharetags_test.go +++ b/internal/entry/sharetags_test.go @@ -6,10 +6,14 @@ import ( "testing" "codeberg.org/snonux/gos/internal/config" + "codeberg.org/snonux/gos/internal/platforms" ) func TestShareTagsPositive(t *testing.T) { - args := config.Args{Platforms: map[string]int{"mastodon": 100, "linkedin": 100}} + args := config.Args{Platforms: map[platforms.Platform]int{ + platforms.Platform("mastodon"): 100, + platforms.Platform("linkedin"): 100, + }} testTable := map[string]shareTags{ "./foo/bar.without.tags.txt.20240101-010101.queued": { includes: []string{"mastodon", "linkedin"}, @@ -53,7 +57,10 @@ func TestShareTagsPositive(t *testing.T) { } } func TestShareTagsNegative(t *testing.T) { - args := config.Args{Platforms: map[string]int{"mastodon": 100, "linkedin": 100}} + args := config.Args{Platforms: map[platforms.Platform]int{ + platforms.Platform("mastodon"): 100, + platforms.Platform("linkedin"): 100, + }} testTable := map[string]shareTags{ "./foo/bar.without.tags.txt.20240101-010101.queued": { includes: []string{"linkedin"}, |
