diff --git a/go.mod b/go.mod index 79f5391..d877c03 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module git.gutmet.org/swill.git go 1.16 require ( - git.gutmet.org/go-mastodon.git v0.0.0-20221120215917-c814efc1642a + git.gutmet.org/go-mastodon.git v0.0.0-20221121192555-9585b1ce2e3b git.gutmet.org/goutil.git v0.0.0-20201108182825-c19893df11f9 ) diff --git a/go.sum b/go.sum index 7f588c2..aef9a28 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -git.gutmet.org/go-mastodon.git v0.0.0-20221120215917-c814efc1642a h1:p9lsBPekAW15B/UT8givO37I6x52bMn3vJ5t1dXH2G8= -git.gutmet.org/go-mastodon.git v0.0.0-20221120215917-c814efc1642a/go.mod h1:e/Z3dytr4MYC4rdOjbWEbWXS+zy1CWxjvplVGTE/eH8= +git.gutmet.org/go-mastodon.git v0.0.0-20221121192555-9585b1ce2e3b h1:hrafneYyLpduomEizAU5FmfVCdwNz077iXm6h9IkQBM= +git.gutmet.org/go-mastodon.git v0.0.0-20221121192555-9585b1ce2e3b/go.mod h1:e/Z3dytr4MYC4rdOjbWEbWXS+zy1CWxjvplVGTE/eH8= git.gutmet.org/goutil.git v0.0.0-20201108182825-c19893df11f9 h1:XVD037Slgdl/CxcCWVtN6V+LzYl6QrTQ0upVIVpy6VE= git.gutmet.org/goutil.git v0.0.0-20201108182825-c19893df11f9/go.mod h1:iMgpxo9FxmbnUiQu5ugpjdtVZmh2rA9nySCr/GHkA64= git.gutmet.org/linkheader.git v0.0.0-20221120205136-a51e89fd8486 h1:7F1dwJvIgvHNvglosyIE7SA49BwG6b8DFkvD8NtHMD8= diff --git a/swill.go b/swill.go index c88cf20..ce52d9b 100644 --- a/swill.go +++ b/swill.go @@ -113,7 +113,7 @@ func (d *data) uploadVideo(i int) []mastodon.ID { return uploadAll([]string{vid}) } -func setStatus(msg string, mediaIDs []mastodon.ID, previous *mastodon.Status) *mastodon.Status { +func setStatus(f statusFlags, msg string, mediaIDs []mastodon.ID, previous *mastodon.Status) *mastodon.Status { toot := &mastodon.Toot{ Status: msg, MediaIDs: mediaIDs, @@ -121,12 +121,15 @@ func setStatus(msg string, mediaIDs []mastodon.ID, previous *mastodon.Status) *m if previous != nil { toot.InReplyToID = previous.ID } + if f.visibility != "" { + toot.Visibility = f.visibility + } status, err := mastodon.PostStatus(toot) optLogFatal("setStatus", err) return status } -func (d *data) push(previous *mastodon.Status) []*mastodon.Status { +func (d *data) push(f statusFlags, previous *mastodon.Status) []*mastodon.Status { empty := false i, g, v := 0, 0, 0 statuses := []*mastodon.Status{} @@ -155,7 +158,7 @@ func (d *data) push(previous *mastodon.Status) []*mastodon.Status { empty = false } if !empty { - t := setStatus(status, mediaIDs, previous) + t := setStatus(f, status, mediaIDs, previous) statuses = append(statuses, t) previous = t i++ @@ -240,9 +243,9 @@ func splitArguments(args []string) data { return d } -func updateStatus(args []string) []*mastodon.Status { +func updateStatus(f statusFlags, args []string) []*mastodon.Status { d := splitArguments(args) - return d.push(nil) + return d.push(f, nil) } func PrintStatuses(statuses []*mastodon.Status) { @@ -257,13 +260,25 @@ func PrintStatuses(statuses []*mastodon.Status) { } } -func status(args []string) error { +type statusFlags struct { + visibility string +} + +func status(f statusFlags, args []string) error { checkUsage(args, 1, -1, "status STATUS [FILE1 FILE2 ...]") - statuses := updateStatus(args) + statuses := updateStatus(f, args) PrintStatuses(statuses) return nil } +func statusCommand() (goutil.CommandFlagsInit, goutil.CommandFunc) { + f := statusFlags{} + flagsInit := func(s *flag.FlagSet) { + s.StringVar(&f.visibility, "visibility", "", "public, unlisted, private or direct") + } + return flagsInit, func(args []string) error { return status(f, args) } +} + func userTimeline(args []string) error { checkUsage(args, 1, 1, "timeline USER") user := args[0] @@ -313,7 +328,7 @@ func main() { }() initializeMastodon() commands := []goutil.Command{ - goutil.NewCommandWithFlags("status", wrapCommand(status), "post a status with message and/or media"), + goutil.NewCommandWithFlags("status", wrapCommandFl(statusCommand), "post a status with message and/or media"), goutil.NewCommandWithFlags("timeline", wrapCommand(userTimeline), "get timeline of a specific user"), } _ = goutil.Execute(commands)