add visibility flag for status command

This commit is contained in:
gutmet 2022-11-21 20:42:00 +01:00
parent 86cf57780e
commit 9aee1f50f4
3 changed files with 26 additions and 11 deletions

2
go.mod
View File

@ -3,6 +3,6 @@ module git.gutmet.org/swill.git
go 1.16 go 1.16
require ( 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 git.gutmet.org/goutil.git v0.0.0-20201108182825-c19893df11f9
) )

4
go.sum
View File

@ -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-20221121192555-9585b1ce2e3b h1:hrafneYyLpduomEizAU5FmfVCdwNz077iXm6h9IkQBM=
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/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 h1:XVD037Slgdl/CxcCWVtN6V+LzYl6QrTQ0upVIVpy6VE=
git.gutmet.org/goutil.git v0.0.0-20201108182825-c19893df11f9/go.mod h1:iMgpxo9FxmbnUiQu5ugpjdtVZmh2rA9nySCr/GHkA64= 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= git.gutmet.org/linkheader.git v0.0.0-20221120205136-a51e89fd8486 h1:7F1dwJvIgvHNvglosyIE7SA49BwG6b8DFkvD8NtHMD8=

View File

@ -113,7 +113,7 @@ func (d *data) uploadVideo(i int) []mastodon.ID {
return uploadAll([]string{vid}) 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{ toot := &mastodon.Toot{
Status: msg, Status: msg,
MediaIDs: mediaIDs, MediaIDs: mediaIDs,
@ -121,12 +121,15 @@ func setStatus(msg string, mediaIDs []mastodon.ID, previous *mastodon.Status) *m
if previous != nil { if previous != nil {
toot.InReplyToID = previous.ID toot.InReplyToID = previous.ID
} }
if f.visibility != "" {
toot.Visibility = f.visibility
}
status, err := mastodon.PostStatus(toot) status, err := mastodon.PostStatus(toot)
optLogFatal("setStatus", err) optLogFatal("setStatus", err)
return status return status
} }
func (d *data) push(previous *mastodon.Status) []*mastodon.Status { func (d *data) push(f statusFlags, previous *mastodon.Status) []*mastodon.Status {
empty := false empty := false
i, g, v := 0, 0, 0 i, g, v := 0, 0, 0
statuses := []*mastodon.Status{} statuses := []*mastodon.Status{}
@ -155,7 +158,7 @@ func (d *data) push(previous *mastodon.Status) []*mastodon.Status {
empty = false empty = false
} }
if !empty { if !empty {
t := setStatus(status, mediaIDs, previous) t := setStatus(f, status, mediaIDs, previous)
statuses = append(statuses, t) statuses = append(statuses, t)
previous = t previous = t
i++ i++
@ -240,9 +243,9 @@ func splitArguments(args []string) data {
return d return d
} }
func updateStatus(args []string) []*mastodon.Status { func updateStatus(f statusFlags, args []string) []*mastodon.Status {
d := splitArguments(args) d := splitArguments(args)
return d.push(nil) return d.push(f, nil)
} }
func PrintStatuses(statuses []*mastodon.Status) { 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 ...]") checkUsage(args, 1, -1, "status STATUS [FILE1 FILE2 ...]")
statuses := updateStatus(args) statuses := updateStatus(f, args)
PrintStatuses(statuses) PrintStatuses(statuses)
return nil 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 { func userTimeline(args []string) error {
checkUsage(args, 1, 1, "timeline USER") checkUsage(args, 1, 1, "timeline USER")
user := args[0] user := args[0]
@ -313,7 +328,7 @@ func main() {
}() }()
initializeMastodon() initializeMastodon()
commands := []goutil.Command{ 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.NewCommandWithFlags("timeline", wrapCommand(userTimeline), "get timeline of a specific user"),
} }
_ = goutil.Execute(commands) _ = goutil.Execute(commands)