2024-06-02 07:53:13 +01:00
|
|
|
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2024-05-23 18:06:49 +01:00
|
|
|
package executor
|
|
|
|
|
2024-06-15 18:40:13 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
2024-05-23 18:06:49 +01:00
|
|
|
|
2024-06-10 18:59:01 +01:00
|
|
|
const (
|
2024-06-15 18:40:13 +01:00
|
|
|
flagAddPoll = "add-poll"
|
|
|
|
flagAccountName = "account-name"
|
2024-06-18 19:58:59 +01:00
|
|
|
flagAttachmentID = "attachment-id"
|
2024-06-15 18:40:13 +01:00
|
|
|
flagBrowser = "browser"
|
|
|
|
flagContentType = "content-type"
|
|
|
|
flagContent = "content"
|
|
|
|
flagEnableFederation = "enable-federation"
|
|
|
|
flagEnableLikes = "enable-likes"
|
|
|
|
flagEnableReplies = "enable-replies"
|
|
|
|
flagEnableReposts = "enable-reposts"
|
|
|
|
flagFrom = "from"
|
|
|
|
flagFromFile = "from-file"
|
|
|
|
flagFull = "full"
|
|
|
|
flagInstance = "instance"
|
|
|
|
flagLanguage = "language"
|
|
|
|
flagLimit = "limit"
|
|
|
|
flagListID = "list-id"
|
|
|
|
flagListTitle = "list-title"
|
|
|
|
flagListRepliesPolicy = "list-replies-policy"
|
|
|
|
flagMyAccount = "my-account"
|
2024-06-18 04:59:32 +01:00
|
|
|
flagMuteDuration = "mute-duration"
|
|
|
|
flagMuteNotifications = "mute-notifications"
|
2024-06-15 18:40:13 +01:00
|
|
|
flagNotify = "notify"
|
|
|
|
flagPollAllowsMultipleChoices = "poll-allows-multiple-choices"
|
|
|
|
flagPollExpiresIn = "poll-expires-in"
|
|
|
|
flagPollHidesVoteCounts = "poll-hides-vote-counts"
|
|
|
|
flagPollID = "poll-id"
|
|
|
|
flagPollOption = "poll-option"
|
|
|
|
flagSensitive = "sensitive"
|
|
|
|
flagSkipRelationship = "skip-relationship"
|
|
|
|
flagShowPreferences = "show-preferences"
|
|
|
|
flagShowReposts = "show-reposts"
|
|
|
|
flagSpoilerText = "spoiler-text"
|
|
|
|
flagStatusID = "status-id"
|
|
|
|
flagTag = "tag"
|
|
|
|
flagTimelineCategory = "timeline-category"
|
|
|
|
flagTo = "to"
|
|
|
|
flagType = "type"
|
|
|
|
flagVisibility = "visibility"
|
2024-07-03 13:21:32 +01:00
|
|
|
flagVote = "vote"
|
2024-06-10 18:59:01 +01:00
|
|
|
)
|
|
|
|
|
2024-06-15 18:40:13 +01:00
|
|
|
type MultiStringFlagValue []string
|
2024-05-23 18:06:49 +01:00
|
|
|
|
2024-06-15 18:40:13 +01:00
|
|
|
func (v *MultiStringFlagValue) String() string {
|
|
|
|
return strings.Join(*v, ", ")
|
2024-05-23 18:06:49 +01:00
|
|
|
}
|
|
|
|
|
2024-06-15 18:40:13 +01:00
|
|
|
func (v *MultiStringFlagValue) Set(value string) error {
|
2024-05-23 18:06:49 +01:00
|
|
|
if len(value) > 0 {
|
2024-06-15 18:40:13 +01:00
|
|
|
*v = append(*v, value)
|
2024-05-23 18:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-06-15 18:40:13 +01:00
|
|
|
type MultiIntFlagValue []int
|
|
|
|
|
|
|
|
func (v *MultiIntFlagValue) String() string {
|
|
|
|
value := "Choices: "
|
|
|
|
|
|
|
|
for ind, vote := range *v {
|
|
|
|
if ind == len(*v)-1 {
|
|
|
|
value += strconv.Itoa(vote)
|
|
|
|
} else {
|
|
|
|
value += strconv.Itoa(vote) + ", "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MultiIntFlagValue) Set(text string) error {
|
|
|
|
value, err := strconv.Atoi(text)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to parse the value to an integer: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
*v = append(*v, value)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type TimeDurationFlagValue struct {
|
|
|
|
Duration time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v TimeDurationFlagValue) String() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *TimeDurationFlagValue) Set(text string) error {
|
|
|
|
duration, err := time.ParseDuration(text)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to parse the value as time duration: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Duration = duration
|
|
|
|
|
|
|
|
return nil
|
2024-05-23 18:06:49 +01:00
|
|
|
}
|