Compare commits
No commits in common. "2921d11be5969acc31a9655f0c84c43c6abf54d3" and "fe52a991db9f0ea823364bd80a3a257a2d8a062f" have entirely different histories.
2921d11be5
...
fe52a991db
22 changed files with 360 additions and 500 deletions
|
@ -36,11 +36,11 @@ func main() {
|
||||||
|
|
||||||
func generateExecutors(schema enbasCLISchema, output string) error {
|
func generateExecutors(schema enbasCLISchema, output string) error {
|
||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
"capitalise": capitalise,
|
"capitalise": capitalise,
|
||||||
"flagFieldName": flagFieldName,
|
"flagFieldName": flagFieldName,
|
||||||
"getFlagType": schema.Flags.getType,
|
"getFlagType": schema.Flags.getType,
|
||||||
"getFlagDescription": schema.Flags.getDescription,
|
"getFlagDescription": schema.Flags.getDescription,
|
||||||
"internalFlagValue": internalFlagValue,
|
"customFlagValueType": customFlagValueType,
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := template.Must(template.New("executor-template").Funcs(funcMap).Parse(executorsFileTemplate))
|
tmpl := template.Must(template.New("executor-template").Funcs(funcMap).Parse(executorsFileTemplate))
|
||||||
|
@ -109,15 +109,15 @@ func convertFlagToMixedCaps(value string) string {
|
||||||
return builder.String()
|
return builder.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func internalFlagValue(flagType string) bool {
|
func customFlagValueType(flagType string) bool {
|
||||||
internalFlagValues := map[string]struct{}{
|
customFlagValueTypes := map[string]struct{}{
|
||||||
"StringSliceValue": {},
|
"MultiStringFlagValue": {},
|
||||||
"IntSliceValue": {},
|
"MultiIntFlagValue": {},
|
||||||
"TimeDurationValue": {},
|
"TimeDurationFlagValue": {},
|
||||||
"BoolPtrValue": {},
|
"BoolPtrFlagValue": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, exists := internalFlagValues[flagType]
|
_, exists := customFlagValueTypes[flagType]
|
||||||
|
|
||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
var executorsFileTemplate = `/*
|
var executorsFileTemplate = `package executor
|
||||||
|
{{ print "" }}
|
||||||
|
/*
|
||||||
This file is generated by ./cmd/enbas-cli-generators
|
This file is generated by ./cmd/enbas-cli-generators
|
||||||
DO NOT EDIT.
|
DO NOT EDIT.
|
||||||
*/
|
*/
|
||||||
{{ print "" }}
|
|
||||||
package executor
|
|
||||||
{{ print "" }}
|
|
||||||
{{ print "" }}
|
|
||||||
import internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
|
|
||||||
{{ range $name, $command := . }}
|
{{ range $name, $command := . }}
|
||||||
{{- $struct_name := capitalise $name | printf "%sExecutor" -}}
|
{{- $struct_name := capitalise $name | printf "%sExecutor" -}}
|
||||||
{{- $new_executor_function_name := capitalise $name | printf "New%sExecutor" -}}
|
{{- $new_executor_function_name := capitalise $name | printf "New%sExecutor" -}}
|
||||||
|
@ -23,14 +20,8 @@ type {{ $struct_name }} struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- range $flag := $command.Flags -}}
|
{{- range $flag := $command.Flags -}}
|
||||||
{{- $flag_type := getFlagType $flag.Flag -}}
|
|
||||||
{{- if internalFlagValue $flag_type -}}
|
|
||||||
{{ print "" }}
|
{{ print "" }}
|
||||||
{{ flagFieldName $flag }} internalFlag.{{ $flag_type }}
|
{{ flagFieldName $flag }} {{ getFlagType $flag.Flag }}
|
||||||
{{- else -}}
|
|
||||||
{{ print "" }}
|
|
||||||
{{ flagFieldName $flag }} {{ $flag_type }}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- range $field := $command.AdditionalFields -}}
|
{{- range $field := $command.AdditionalFields -}}
|
||||||
{{ print "" }}
|
{{ print "" }}
|
||||||
|
@ -62,9 +53,9 @@ func {{ $new_executor_function_name }}(
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- range $flag := $command.Flags -}}
|
{{- range $flag := $command.Flags -}}
|
||||||
{{- $flag_type := getFlagType $flag.Flag -}}
|
{{- $flag_type := getFlagType $flag.Flag -}}
|
||||||
{{- if internalFlagValue $flag_type -}}
|
{{- if customFlagValueType $flag_type -}}
|
||||||
{{ print "" }}
|
{{ print "" }}
|
||||||
{{ flagFieldName $flag }}: internalFlag.New{{ $flag_type }}(),
|
{{ flagFieldName $flag }}: New{{ $flag_type }}(),
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- range $field := $command.AdditionalFields -}}
|
{{- range $field := $command.AdditionalFields -}}
|
||||||
|
@ -87,7 +78,7 @@ func {{ $new_executor_function_name }}(
|
||||||
{{- else if eq $flag_type "int" -}}
|
{{- else if eq $flag_type "int" -}}
|
||||||
{{ print "" }}
|
{{ print "" }}
|
||||||
exe.IntVar(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ $flag.Default }}, {{ getFlagDescription $flag.Flag | printf "%q" }})
|
exe.IntVar(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ $flag.Default }}, {{ getFlagDescription $flag.Flag | printf "%q" }})
|
||||||
{{- else if internalFlagValue $flag_type -}}
|
{{- else if customFlagValueType $flag_type -}}
|
||||||
{{ print "" }}
|
{{ print "" }}
|
||||||
exe.Var(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ getFlagDescription $flag.Flag | printf "%q" }})
|
exe.Var(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ getFlagDescription $flag.Flag | printf "%q" }})
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
|
@ -2,11 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/executor"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/executor"
|
||||||
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,12 +26,22 @@ func main() {
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
var (
|
var (
|
||||||
configDir string
|
configDir string
|
||||||
noColorFlag internalFlag.BoolPtrValue
|
noColor *bool
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.StringVar(&configDir, "config-dir", "", "Specify your config directory")
|
flag.StringVar(&configDir, "config-dir", "", "Specify your config directory")
|
||||||
flag.Var(&noColorFlag, "no-color", "Disable ANSI colour output when displaying text on screen")
|
flag.BoolFunc("no-color", "Disable ANSI colour output when displaying text on screen", func(value string) error {
|
||||||
|
boolVal, err := strconv.ParseBool(value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to parse %q as a boolean: %w", value, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
noColor = new(bool)
|
||||||
|
*noColor = boolVal
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
flag.Usage = usageFunc(executor.CommandSummaryMap())
|
flag.Usage = usageFunc(executor.CommandSummaryMap())
|
||||||
|
|
||||||
|
@ -42,12 +53,15 @@ func run() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var noColor bool
|
// If NoColor is still unspecified,
|
||||||
|
// check to see if the NO_COLOR environment variable is set
|
||||||
if noColorFlag.Value != nil {
|
if noColor == nil {
|
||||||
noColor = *noColorFlag.Value
|
noColor = new(bool)
|
||||||
} else if os.Getenv("NO_COLOR") != "" {
|
if os.Getenv("NO_COLOR") != "" {
|
||||||
noColor = true
|
*noColor = true
|
||||||
|
} else {
|
||||||
|
*noColor = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
command := flag.Arg(0)
|
command := flag.Arg(0)
|
||||||
|
@ -61,21 +75,17 @@ func run() error {
|
||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
case executor.CommandInit, executor.CommandVersion:
|
case executor.CommandInit, executor.CommandVersion:
|
||||||
enbasPrinter = printer.NewPrinter(noColor, "", 0)
|
enbasPrinter = printer.NewPrinter(*noColor, "", 0)
|
||||||
default:
|
default:
|
||||||
enbasConfig, err = config.NewConfigFromFile(configDir)
|
enbasConfig, err = config.NewConfigFromFile(configDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
enbasPrinter = printer.NewPrinter(noColor, "", 0)
|
enbasPrinter = printer.NewPrinter(*noColor, "", 0)
|
||||||
enbasPrinter.PrintFailure("unable to load the configuration: " + err.Error() + ".")
|
enbasPrinter.PrintFailure("unable to load the configuration: " + err.Error() + ".")
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
enbasPrinter = printer.NewPrinter(
|
enbasPrinter = printer.NewPrinter(*noColor, enbasConfig.Integrations.Pager, enbasConfig.LineWrapMaxWidth)
|
||||||
noColor,
|
|
||||||
enbasConfig.Integrations.Pager,
|
|
||||||
enbasConfig.LineWrapMaxWidth,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
executorMap := map[string]executor.Executor{
|
executorMap := map[string]executor.Executor{
|
||||||
|
@ -86,6 +96,8 @@ func run() error {
|
||||||
executor.CommandAdd: executor.NewAddExecutor(
|
executor.CommandAdd: executor.NewAddExecutor(
|
||||||
enbasPrinter,
|
enbasPrinter,
|
||||||
enbasConfig,
|
enbasConfig,
|
||||||
|
executor.CommandAdd,
|
||||||
|
executor.CommandSummaryLookup(executor.CommandAdd),
|
||||||
),
|
),
|
||||||
executor.CommandBlock: executor.NewBlockExecutor(
|
executor.CommandBlock: executor.NewBlockExecutor(
|
||||||
enbasPrinter,
|
enbasPrinter,
|
||||||
|
@ -126,6 +138,8 @@ func run() error {
|
||||||
executor.CommandRemove: executor.NewRemoveExecutor(
|
executor.CommandRemove: executor.NewRemoveExecutor(
|
||||||
enbasPrinter,
|
enbasPrinter,
|
||||||
enbasConfig,
|
enbasConfig,
|
||||||
|
executor.CommandRemove,
|
||||||
|
executor.CommandSummaryLookup(executor.CommandRemove),
|
||||||
),
|
),
|
||||||
executor.CommandSwitch: executor.NewSwitchExecutor(
|
executor.CommandSwitch: executor.NewSwitchExecutor(
|
||||||
enbasPrinter,
|
enbasPrinter,
|
||||||
|
|
|
@ -25,15 +25,7 @@ func (a *AcceptExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AcceptExecutor) acceptFollowRequest(gtsClient *client.Client) error {
|
func (a *AcceptExecutor) acceptFollowRequest(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, a.accountName, a.config.CredentialsFile)
|
||||||
if !a.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, a.accountName[0], a.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,54 @@ package executor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type AddExecutor struct {
|
||||||
|
*flag.FlagSet
|
||||||
|
|
||||||
|
printer *printer.Printer
|
||||||
|
config *config.Config
|
||||||
|
resourceType string
|
||||||
|
toResourceType string
|
||||||
|
listID string
|
||||||
|
statusID string
|
||||||
|
pollID string
|
||||||
|
choices MultiIntFlagValue
|
||||||
|
accountNames MultiStringFlagValue
|
||||||
|
content string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAddExecutor(printer *printer.Printer, config *config.Config, name, summary string) *AddExecutor {
|
||||||
|
emptyArr := make([]string, 0, 3)
|
||||||
|
|
||||||
|
addExe := AddExecutor{
|
||||||
|
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
||||||
|
|
||||||
|
printer: printer,
|
||||||
|
config: config,
|
||||||
|
accountNames: MultiStringFlagValue(emptyArr),
|
||||||
|
}
|
||||||
|
|
||||||
|
addExe.StringVar(&addExe.resourceType, flagType, "", "Specify the resource type to add (e.g. account, note)")
|
||||||
|
addExe.StringVar(&addExe.toResourceType, flagTo, "", "Specify the target resource type to add to (e.g. list, account, etc)")
|
||||||
|
addExe.StringVar(&addExe.listID, flagListID, "", "The ID of the list")
|
||||||
|
addExe.StringVar(&addExe.statusID, flagStatusID, "", "The ID of the status")
|
||||||
|
addExe.StringVar(&addExe.content, flagContent, "", "The content of the resource")
|
||||||
|
addExe.StringVar(&addExe.pollID, flagPollID, "", "The ID of the poll")
|
||||||
|
addExe.Var(&addExe.accountNames, flagAccountName, "The name of the account")
|
||||||
|
addExe.Var(&addExe.choices, flagVote, "Add a vote to an option in a poll")
|
||||||
|
|
||||||
|
addExe.Usage = commandUsageFunc(name, summary, addExe.FlagSet)
|
||||||
|
|
||||||
|
return &addExe
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AddExecutor) Execute() error {
|
func (a *AddExecutor) Execute() error {
|
||||||
if a.toResourceType == "" {
|
if a.toResourceType == "" {
|
||||||
return FlagNotSetError{flagText: flagTo}
|
return FlagNotSetError{flagText: flagTo}
|
||||||
|
@ -54,7 +97,7 @@ func (a *AddExecutor) addAccountsToList(gtsClient *client.Client) error {
|
||||||
return FlagNotSetError{flagText: flagListID}
|
return FlagNotSetError{flagText: flagListID}
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.accountNames.Empty() {
|
if len(a.accountNames) == 0 {
|
||||||
return NoAccountSpecifiedError{}
|
return NoAccountSpecifiedError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,12 +147,8 @@ func (a *AddExecutor) addToAccount(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AddExecutor) addNoteToAccount(gtsClient *client.Client) error {
|
func (a *AddExecutor) addNoteToAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
if len(a.accountNames) != 1 {
|
||||||
if !a.accountNames.ExpectedLength(expectedNumAccountNames) {
|
return fmt.Errorf("unexpected number of accounts specified: want 1, got %d", len(a.accountNames))
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, a.accountNames[0], a.config.CredentialsFile)
|
accountID, err := getAccountID(gtsClient, false, a.accountNames[0], a.config.CredentialsFile)
|
||||||
|
@ -226,7 +265,7 @@ func (a *AddExecutor) addToPoll(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AddExecutor) addVoteToPoll(gtsClient *client.Client) error {
|
func (a *AddExecutor) addVoteToPoll(gtsClient *client.Client) error {
|
||||||
if a.votes.Empty() {
|
if len(a.choices) == 0 {
|
||||||
return errors.New("please use --" + flagVote + " to make a choice in this poll")
|
return errors.New("please use --" + flagVote + " to make a choice in this poll")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,11 +278,11 @@ func (a *AddExecutor) addVoteToPoll(gtsClient *client.Client) error {
|
||||||
return PollClosedError{}
|
return PollClosedError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !poll.Multiple && !a.votes.ExpectedLength(1) {
|
if !poll.Multiple && len(a.choices) > 1 {
|
||||||
return MultipleChoiceError{}
|
return MultipleChoiceError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gtsClient.VoteInPoll(a.pollID, []int(a.votes)); err != nil {
|
if err := gtsClient.VoteInPoll(a.pollID, []int(a.choices)); err != nil {
|
||||||
return fmt.Errorf("unable to add your vote(s) to the poll: %w", err)
|
return fmt.Errorf("unable to add your vote(s) to the poll: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,15 +25,11 @@ func (b *BlockExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlockExecutor) blockAccount(gtsClient *client.Client) error {
|
func (b *BlockExecutor) blockAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
if b.accountName == "" {
|
||||||
if !b.accountName.ExpectedLength(expectedNumAccountNames) {
|
return FlagNotSetError{flagText: flagAccountName}
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, b.accountName[0], b.config.CredentialsFile)
|
accountID, err := getAccountID(gtsClient, false, b.accountName, b.config.CredentialsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,23 @@
|
||||||
/*
|
|
||||||
This file is generated by ./cmd/enbas-cli-generators
|
|
||||||
DO NOT EDIT.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package executor
|
package executor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is generated by ./cmd/enbas-cli-generators
|
||||||
|
DO NOT EDIT.
|
||||||
|
*/
|
||||||
|
|
||||||
// AcceptExecutor is the executor for the accept command.
|
// AcceptExecutor is the executor for the accept command.
|
||||||
type AcceptExecutor struct {
|
type AcceptExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
resourceType string
|
resourceType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,67 +26,25 @@ func NewAcceptExecutor(
|
||||||
config *config.Config,
|
config *config.Config,
|
||||||
) *AcceptExecutor {
|
) *AcceptExecutor {
|
||||||
exe := AcceptExecutor{
|
exe := AcceptExecutor{
|
||||||
FlagSet: flag.NewFlagSet("accept", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("accept", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("accept", "Accepts a request (e.g. a follow request)", exe.FlagSet)
|
exe.Usage = commandUsageFunc("accept", "Accepts a request (e.g. a follow request)", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
||||||
|
|
||||||
return &exe
|
return &exe
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddExecutor is the executor for the add command.
|
|
||||||
type AddExecutor struct {
|
|
||||||
*flag.FlagSet
|
|
||||||
printer *printer.Printer
|
|
||||||
config *config.Config
|
|
||||||
accountNames internalFlag.StringSliceValue
|
|
||||||
content string
|
|
||||||
listID string
|
|
||||||
pollID string
|
|
||||||
statusID string
|
|
||||||
toResourceType string
|
|
||||||
resourceType string
|
|
||||||
votes internalFlag.IntSliceValue
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAddExecutor(
|
|
||||||
printer *printer.Printer,
|
|
||||||
config *config.Config,
|
|
||||||
) *AddExecutor {
|
|
||||||
exe := AddExecutor{
|
|
||||||
FlagSet: flag.NewFlagSet("add", flag.ExitOnError),
|
|
||||||
printer: printer,
|
|
||||||
config: config,
|
|
||||||
accountNames: internalFlag.NewStringSliceValue(),
|
|
||||||
votes: internalFlag.NewIntSliceValue(),
|
|
||||||
}
|
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("add", "Add a resource to another resource", exe.FlagSet)
|
|
||||||
|
|
||||||
exe.Var(&exe.accountNames, "account-name", "The name of the account")
|
|
||||||
exe.StringVar(&exe.content, "content", "", "The content of the created resource")
|
|
||||||
exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question")
|
|
||||||
exe.StringVar(&exe.pollID, "poll-id", "", "The ID of the poll")
|
|
||||||
exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status")
|
|
||||||
exe.StringVar(&exe.toResourceType, "to", "", "TBC")
|
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
|
||||||
exe.Var(&exe.votes, "vote", "Add a vote to an option in a poll")
|
|
||||||
|
|
||||||
return &exe
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockExecutor is the executor for the block command.
|
// BlockExecutor is the executor for the block command.
|
||||||
type BlockExecutor struct {
|
type BlockExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
resourceType string
|
resourceType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,15 +53,14 @@ func NewBlockExecutor(
|
||||||
config *config.Config,
|
config *config.Config,
|
||||||
) *BlockExecutor {
|
) *BlockExecutor {
|
||||||
exe := BlockExecutor{
|
exe := BlockExecutor{
|
||||||
FlagSet: flag.NewFlagSet("block", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("block", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("block", "Blocks a resource (e.g. an account)", exe.FlagSet)
|
exe.Usage = commandUsageFunc("block", "Blocks a resource (e.g. an account)", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
||||||
|
|
||||||
return &exe
|
return &exe
|
||||||
|
@ -128,10 +84,10 @@ type CreateExecutor struct {
|
||||||
listRepliesPolicy string
|
listRepliesPolicy string
|
||||||
listTitle string
|
listTitle string
|
||||||
pollAllowsMultipleChoices bool
|
pollAllowsMultipleChoices bool
|
||||||
pollExpiresIn internalFlag.TimeDurationValue
|
pollExpiresIn TimeDurationFlagValue
|
||||||
pollHidesVoteCounts bool
|
pollHidesVoteCounts bool
|
||||||
pollOptions internalFlag.StringSliceValue
|
pollOptions MultiStringFlagValue
|
||||||
sensitive internalFlag.BoolPtrValue
|
sensitive BoolPtrFlagValue
|
||||||
spoilerText string
|
spoilerText string
|
||||||
resourceType string
|
resourceType string
|
||||||
visibility string
|
visibility string
|
||||||
|
@ -145,9 +101,9 @@ func NewCreateExecutor(
|
||||||
FlagSet: flag.NewFlagSet("create", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("create", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
pollExpiresIn: internalFlag.NewTimeDurationValue(),
|
pollExpiresIn: NewTimeDurationFlagValue(),
|
||||||
pollOptions: internalFlag.NewStringSliceValue(),
|
pollOptions: NewMultiStringFlagValue(),
|
||||||
sensitive: internalFlag.NewBoolPtrValue(),
|
sensitive: NewBoolPtrFlagValue(),
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("create", "Creates a specific resource", exe.FlagSet)
|
exe.Usage = commandUsageFunc("create", "Creates a specific resource", exe.FlagSet)
|
||||||
|
@ -239,7 +195,7 @@ type FollowExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
notify bool
|
notify bool
|
||||||
showReposts bool
|
showReposts bool
|
||||||
resourceType string
|
resourceType string
|
||||||
|
@ -250,15 +206,14 @@ func NewFollowExecutor(
|
||||||
config *config.Config,
|
config *config.Config,
|
||||||
) *FollowExecutor {
|
) *FollowExecutor {
|
||||||
exe := FollowExecutor{
|
exe := FollowExecutor{
|
||||||
FlagSet: flag.NewFlagSet("follow", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("follow", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("follow", "Follow a resource (e.g. an account)", exe.FlagSet)
|
exe.Usage = commandUsageFunc("follow", "Follow a resource (e.g. an account)", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.BoolVar(&exe.notify, "notify", false, "Get notifications from statuses from the account you want to follow")
|
exe.BoolVar(&exe.notify, "notify", false, "Get notifications from statuses from the account you want to follow")
|
||||||
exe.BoolVar(&exe.showReposts, "show-reposts", true, "Show reposts from the account you want to follow")
|
exe.BoolVar(&exe.showReposts, "show-reposts", true, "Show reposts from the account you want to follow")
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
||||||
|
@ -318,8 +273,8 @@ type MuteExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
muteDuration internalFlag.TimeDurationValue
|
muteDuration TimeDurationFlagValue
|
||||||
muteNotifications bool
|
muteNotifications bool
|
||||||
resourceType string
|
resourceType string
|
||||||
}
|
}
|
||||||
|
@ -332,13 +287,12 @@ func NewMuteExecutor(
|
||||||
FlagSet: flag.NewFlagSet("mute", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("mute", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
muteDuration: NewTimeDurationFlagValue(),
|
||||||
muteDuration: internalFlag.NewTimeDurationValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("mute", "Mutes a specific resource (e.g. an account)", exe.FlagSet)
|
exe.Usage = commandUsageFunc("mute", "Mutes a specific resource (e.g. an account)", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.Var(&exe.muteDuration, "mute-duration", "Specify how long the mute should last for. To mute indefinitely, set this to 0s")
|
exe.Var(&exe.muteDuration, "mute-duration", "Specify how long the mute should last for. To mute indefinitely, set this to 0s")
|
||||||
exe.BoolVar(&exe.muteNotifications, "mute-notifications", false, "Set to true to mute notifications as well as posts")
|
exe.BoolVar(&exe.muteNotifications, "mute-notifications", false, "Set to true to mute notifications as well as posts")
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
||||||
|
@ -351,7 +305,7 @@ type RejectExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
resourceType string
|
resourceType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,49 +314,14 @@ func NewRejectExecutor(
|
||||||
config *config.Config,
|
config *config.Config,
|
||||||
) *RejectExecutor {
|
) *RejectExecutor {
|
||||||
exe := RejectExecutor{
|
exe := RejectExecutor{
|
||||||
FlagSet: flag.NewFlagSet("reject", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("reject", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("reject", "Rejects a request (e.g. a follow request)", exe.FlagSet)
|
exe.Usage = commandUsageFunc("reject", "Rejects a request (e.g. a follow request)", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
|
||||||
|
|
||||||
return &exe
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveExecutor is the executor for the remove command.
|
|
||||||
type RemoveExecutor struct {
|
|
||||||
*flag.FlagSet
|
|
||||||
printer *printer.Printer
|
|
||||||
config *config.Config
|
|
||||||
accountNames internalFlag.StringSliceValue
|
|
||||||
fromResourceType string
|
|
||||||
listID string
|
|
||||||
statusID string
|
|
||||||
resourceType string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRemoveExecutor(
|
|
||||||
printer *printer.Printer,
|
|
||||||
config *config.Config,
|
|
||||||
) *RemoveExecutor {
|
|
||||||
exe := RemoveExecutor{
|
|
||||||
FlagSet: flag.NewFlagSet("remove", flag.ExitOnError),
|
|
||||||
printer: printer,
|
|
||||||
config: config,
|
|
||||||
accountNames: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("remove", "", exe.FlagSet)
|
|
||||||
|
|
||||||
exe.Var(&exe.accountNames, "account-name", "The name of the account")
|
|
||||||
exe.StringVar(&exe.fromResourceType, "from", "", "Specify the resource type to action the target resource from")
|
|
||||||
exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question")
|
|
||||||
exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status")
|
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
||||||
|
|
||||||
return &exe
|
return &exe
|
||||||
|
@ -413,10 +332,10 @@ type ShowExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
getAllImages bool
|
getAllImages bool
|
||||||
getAllVideos bool
|
getAllVideos bool
|
||||||
attachmentIDs internalFlag.StringSliceValue
|
attachmentIDs MultiStringFlagValue
|
||||||
showInBrowser bool
|
showInBrowser bool
|
||||||
excludeBoosts bool
|
excludeBoosts bool
|
||||||
excludeReplies bool
|
excludeReplies bool
|
||||||
|
@ -445,13 +364,12 @@ func NewShowExecutor(
|
||||||
FlagSet: flag.NewFlagSet("show", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("show", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
attachmentIDs: NewMultiStringFlagValue(),
|
||||||
attachmentIDs: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("show", "Shows details about a specified resource", exe.FlagSet)
|
exe.Usage = commandUsageFunc("show", "Shows details about a specified resource", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.BoolVar(&exe.getAllImages, "all-images", false, "Set to true to show all images from a status")
|
exe.BoolVar(&exe.getAllImages, "all-images", false, "Set to true to show all images from a status")
|
||||||
exe.BoolVar(&exe.getAllVideos, "all-videos", false, "Set to true to show all videos from a status")
|
exe.BoolVar(&exe.getAllVideos, "all-videos", false, "Set to true to show all videos from a status")
|
||||||
exe.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment")
|
exe.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment")
|
||||||
|
@ -482,7 +400,7 @@ type SwitchExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
to string
|
to string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,15 +409,14 @@ func NewSwitchExecutor(
|
||||||
config *config.Config,
|
config *config.Config,
|
||||||
) *SwitchExecutor {
|
) *SwitchExecutor {
|
||||||
exe := SwitchExecutor{
|
exe := SwitchExecutor{
|
||||||
FlagSet: flag.NewFlagSet("switch", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("switch", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("switch", "Performs a switch operation (e.g. switching between logged in accounts)", exe.FlagSet)
|
exe.Usage = commandUsageFunc("switch", "Performs a switch operation (e.g. switching between logged in accounts)", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.StringVar(&exe.to, "to", "", "TBC")
|
exe.StringVar(&exe.to, "to", "", "TBC")
|
||||||
|
|
||||||
return &exe
|
return &exe
|
||||||
|
@ -510,7 +427,7 @@ type UnblockExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
resourceType string
|
resourceType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,15 +436,14 @@ func NewUnblockExecutor(
|
||||||
config *config.Config,
|
config *config.Config,
|
||||||
) *UnblockExecutor {
|
) *UnblockExecutor {
|
||||||
exe := UnblockExecutor{
|
exe := UnblockExecutor{
|
||||||
FlagSet: flag.NewFlagSet("unblock", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("unblock", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("unblock", "Unblocks a resource (e.g. an account)", exe.FlagSet)
|
exe.Usage = commandUsageFunc("unblock", "Unblocks a resource (e.g. an account)", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
||||||
|
|
||||||
return &exe
|
return &exe
|
||||||
|
@ -538,7 +454,7 @@ type UnfollowExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
resourceType string
|
resourceType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,15 +463,14 @@ func NewUnfollowExecutor(
|
||||||
config *config.Config,
|
config *config.Config,
|
||||||
) *UnfollowExecutor {
|
) *UnfollowExecutor {
|
||||||
exe := UnfollowExecutor{
|
exe := UnfollowExecutor{
|
||||||
FlagSet: flag.NewFlagSet("unfollow", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("unfollow", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("unfollow", "Unfollow a resource (e.g. an account)", exe.FlagSet)
|
exe.Usage = commandUsageFunc("unfollow", "Unfollow a resource (e.g. an account)", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
||||||
|
|
||||||
return &exe
|
return &exe
|
||||||
|
@ -566,7 +481,7 @@ type UnmuteExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
printer *printer.Printer
|
printer *printer.Printer
|
||||||
config *config.Config
|
config *config.Config
|
||||||
accountName internalFlag.StringSliceValue
|
accountName string
|
||||||
resourceType string
|
resourceType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,15 +490,14 @@ func NewUnmuteExecutor(
|
||||||
config *config.Config,
|
config *config.Config,
|
||||||
) *UnmuteExecutor {
|
) *UnmuteExecutor {
|
||||||
exe := UnmuteExecutor{
|
exe := UnmuteExecutor{
|
||||||
FlagSet: flag.NewFlagSet("unmute", flag.ExitOnError),
|
FlagSet: flag.NewFlagSet("unmute", flag.ExitOnError),
|
||||||
printer: printer,
|
printer: printer,
|
||||||
config: config,
|
config: config,
|
||||||
accountName: internalFlag.NewStringSliceValue(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.Usage = commandUsageFunc("unmute", "Umutes a specific resource (e.g. an account)", exe.FlagSet)
|
exe.Usage = commandUsageFunc("unmute", "Umutes a specific resource (e.g. an account)", exe.FlagSet)
|
||||||
|
|
||||||
exe.Var(&exe.accountName, "account-name", "The name of the account")
|
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
|
||||||
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
|
||||||
|
|
||||||
return &exe
|
return &exe
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
package executor
|
package executor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
flagAccountName = "account-name"
|
||||||
flagAttachmentID = "attachment-id"
|
flagAttachmentID = "attachment-id"
|
||||||
flagContent = "content"
|
flagContent = "content"
|
||||||
flagFrom = "from"
|
flagFrom = "from"
|
||||||
|
@ -16,3 +24,111 @@ const (
|
||||||
flagType = "type"
|
flagType = "type"
|
||||||
flagVote = "vote"
|
flagVote = "vote"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type MultiStringFlagValue []string
|
||||||
|
|
||||||
|
func NewMultiStringFlagValue() MultiStringFlagValue {
|
||||||
|
arr := make([]string, 0, 3)
|
||||||
|
|
||||||
|
return MultiStringFlagValue(arr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v MultiStringFlagValue) String() string {
|
||||||
|
return strings.Join(v, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *MultiStringFlagValue) Set(value string) error {
|
||||||
|
if len(value) > 0 {
|
||||||
|
*v = append(*v, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type MultiIntFlagValue []int
|
||||||
|
|
||||||
|
func NewMultiIntFlagValue() MultiIntFlagValue {
|
||||||
|
arr := make([]int, 0, 3)
|
||||||
|
|
||||||
|
return MultiIntFlagValue(arr)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 NewTimeDurationFlagValue() TimeDurationFlagValue {
|
||||||
|
return TimeDurationFlagValue{
|
||||||
|
Duration: 0 * time.Second,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v TimeDurationFlagValue) String() string {
|
||||||
|
return "Time duration: " + v.Duration.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
type BoolPtrFlagValue struct {
|
||||||
|
Value *bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBoolPtrFlagValue() BoolPtrFlagValue {
|
||||||
|
return BoolPtrFlagValue{
|
||||||
|
Value: nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b BoolPtrFlagValue) String() string {
|
||||||
|
if b.Value == nil {
|
||||||
|
return "NOT SET"
|
||||||
|
}
|
||||||
|
|
||||||
|
return strconv.FormatBool(*b.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BoolPtrFlagValue) Set(value string) error {
|
||||||
|
boolVar, err := strconv.ParseBool(value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to parse %q as a boolean value: %w", value, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Value = new(bool)
|
||||||
|
*b.Value = boolVar
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -25,11 +25,7 @@ func (f *FollowExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FollowExecutor) followAccount(gtsClient *client.Client) error {
|
func (f *FollowExecutor) followAccount(gtsClient *client.Client) error {
|
||||||
if !f.accountName.ExpectedLength(1) {
|
accountID, err := getAccountID(gtsClient, false, f.accountName, f.config.CredentialsFile)
|
||||||
return fmt.Errorf("found an unexpected number of %s flags: expected %d", "--account-name", 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, f.accountName[0], f.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,11 @@ func (m *MuteExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MuteExecutor) muteAccount(gtsClient *client.Client) error {
|
func (m *MuteExecutor) muteAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
if m.accountName == "" {
|
||||||
if !m.accountName.ExpectedLength(expectedNumAccountNames) {
|
return FlagNotSetError{flagText: flagAccountName}
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, m.accountName[0], m.config.CredentialsFile)
|
accountID, err := getAccountID(gtsClient, false, m.accountName, m.config.CredentialsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,7 @@ func (r *RejectExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RejectExecutor) rejectFollowRequest(gtsClient *client.Client) error {
|
func (r *RejectExecutor) rejectFollowRequest(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, r.accountName, r.config.CredentialsFile)
|
||||||
if !r.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, r.accountName[0], r.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,48 @@
|
||||||
package executor
|
package executor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RemoveExecutor struct {
|
||||||
|
*flag.FlagSet
|
||||||
|
|
||||||
|
printer *printer.Printer
|
||||||
|
config *config.Config
|
||||||
|
resourceType string
|
||||||
|
fromResourceType string
|
||||||
|
listID string
|
||||||
|
statusID string
|
||||||
|
accountNames MultiStringFlagValue
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRemoveExecutor(printer *printer.Printer, config *config.Config, name, summary string) *RemoveExecutor {
|
||||||
|
emptyArr := make([]string, 0, 3)
|
||||||
|
|
||||||
|
removeExe := RemoveExecutor{
|
||||||
|
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
||||||
|
|
||||||
|
printer: printer,
|
||||||
|
config: config,
|
||||||
|
accountNames: MultiStringFlagValue(emptyArr),
|
||||||
|
}
|
||||||
|
|
||||||
|
removeExe.StringVar(&removeExe.resourceType, flagType, "", "Specify the resource type to remove (e.g. account, note)")
|
||||||
|
removeExe.StringVar(&removeExe.fromResourceType, flagFrom, "", "Specify the resource type to remove from (e.g. list, account, etc)")
|
||||||
|
removeExe.StringVar(&removeExe.listID, flagListID, "", "The ID of the list to remove from")
|
||||||
|
removeExe.StringVar(&removeExe.statusID, flagStatusID, "", "The ID of the status")
|
||||||
|
removeExe.Var(&removeExe.accountNames, flagAccountName, "The name of the account to remove from the resource")
|
||||||
|
|
||||||
|
removeExe.Usage = commandUsageFunc(name, summary, removeExe.FlagSet)
|
||||||
|
|
||||||
|
return &removeExe
|
||||||
|
}
|
||||||
|
|
||||||
func (r *RemoveExecutor) Execute() error {
|
func (r *RemoveExecutor) Execute() error {
|
||||||
if r.fromResourceType == "" {
|
if r.fromResourceType == "" {
|
||||||
return FlagNotSetError{flagText: flagFrom}
|
return FlagNotSetError{flagText: flagFrom}
|
||||||
|
@ -52,7 +89,7 @@ func (r *RemoveExecutor) removeAccountsFromList(gtsClient *client.Client) error
|
||||||
return FlagNotSetError{flagText: flagListID}
|
return FlagNotSetError{flagText: flagListID}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.accountNames.Empty() {
|
if len(r.accountNames) == 0 {
|
||||||
return NoAccountSpecifiedError{}
|
return NoAccountSpecifiedError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,12 +130,8 @@ func (r *RemoveExecutor) removeFromAccount(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RemoveExecutor) removeNoteFromAccount(gtsClient *client.Client) error {
|
func (r *RemoveExecutor) removeNoteFromAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
if len(r.accountNames) != 1 {
|
||||||
if !r.accountNames.ExpectedLength(expectedNumAccountNames) {
|
return fmt.Errorf("unexpected number of accounts specified: want 1, got %d", len(r.accountNames))
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, r.accountNames[0], r.config.CredentialsFile)
|
accountID, err := getAccountID(gtsClient, false, r.accountNames[0], r.config.CredentialsFile)
|
||||||
|
|
|
@ -70,14 +70,11 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
||||||
return fmt.Errorf("received an error while getting the account details: %w", err)
|
return fmt.Errorf("received an error while getting the account details: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
expectedNumAccountNames := 1
|
if s.accountName == "" {
|
||||||
if !s.accountName.ExpectedLength(expectedNumAccountNames) {
|
return FlagNotSetError{flagText: flagAccountName}
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
account, err = getAccount(gtsClient, s.accountName[0])
|
|
||||||
|
account, err = getAccount(gtsClient, s.accountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account details: %w", err)
|
return fmt.Errorf("received an error while getting the account details: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -272,15 +269,7 @@ func (s *ShowExecutor) showFollowers(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShowExecutor) showFollowersFromAccount(gtsClient *client.Client) error {
|
func (s *ShowExecutor) showFollowersFromAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
||||||
if !s.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName[0], s.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -320,15 +309,7 @@ func (s *ShowExecutor) showFollowing(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShowExecutor) showFollowingFromAccount(gtsClient *client.Client) error {
|
func (s *ShowExecutor) showFollowingFromAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
||||||
if !s.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName[0], s.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,19 +20,15 @@ func (s *SwitchExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SwitchExecutor) switchToAccount() error {
|
func (s *SwitchExecutor) switchToAccount() error {
|
||||||
expectedNumAccountNames := 1
|
if s.accountName == "" {
|
||||||
if !s.accountName.ExpectedLength(expectedNumAccountNames) {
|
return NoAccountSpecifiedError{}
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.UpdateCurrentAccount(s.accountName[0], s.config.CredentialsFile); err != nil {
|
if err := config.UpdateCurrentAccount(s.accountName, s.config.CredentialsFile); err != nil {
|
||||||
return fmt.Errorf("unable to switch account to the account: %w", err)
|
return fmt.Errorf("unable to switch account to the account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.printer.PrintSuccess("The current account is now set to '" + s.accountName[0] + "'.")
|
s.printer.PrintSuccess("The current account is now set to '" + s.accountName + "'.")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,11 @@ func (b *UnblockExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *UnblockExecutor) unblockAccount(gtsClient *client.Client) error {
|
func (b *UnblockExecutor) unblockAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
if b.accountName == "" {
|
||||||
if !b.accountName.ExpectedLength(expectedNumAccountNames) {
|
return FlagNotSetError{flagText: flagAccountName}
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, b.accountName[0], b.config.CredentialsFile)
|
accountID, err := getAccountID(gtsClient, false, b.accountName, b.config.CredentialsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,7 @@ func (f *UnfollowExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *UnfollowExecutor) unfollowAccount(gtsClient *client.Client) error {
|
func (f *UnfollowExecutor) unfollowAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, f.accountName, f.config.CredentialsFile)
|
||||||
if !f.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, f.accountName[0], f.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,11 @@ func (m *UnmuteExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UnmuteExecutor) unmuteAccount(gtsClient *client.Client) error {
|
func (m *UnmuteExecutor) unmuteAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
if m.accountName == "" {
|
||||||
if !m.accountName.ExpectedLength(expectedNumAccountNames) {
|
return FlagNotSetError{flagText: flagAccountName}
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, m.accountName[0], m.config.CredentialsFile)
|
accountID, err := getAccountID(gtsClient, false, m.accountName, m.config.CredentialsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package flag
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BoolPtrValue struct {
|
|
||||||
Value *bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBoolPtrValue() BoolPtrValue {
|
|
||||||
return BoolPtrValue{
|
|
||||||
Value: nil,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b BoolPtrValue) String() string {
|
|
||||||
if b.Value == nil {
|
|
||||||
return "NOT SET"
|
|
||||||
}
|
|
||||||
|
|
||||||
return strconv.FormatBool(*b.Value)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *BoolPtrValue) Set(value string) error {
|
|
||||||
boolVar, err := strconv.ParseBool(value)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to parse %q as a boolean value: %w", value, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
b.Value = new(bool)
|
|
||||||
*b.Value = boolVar
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package flag
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IntSliceValue []int
|
|
||||||
|
|
||||||
func NewIntSliceValue() IntSliceValue {
|
|
||||||
arr := make([]int, 0, 3)
|
|
||||||
|
|
||||||
return IntSliceValue(arr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v IntSliceValue) String() string {
|
|
||||||
var builder strings.Builder
|
|
||||||
|
|
||||||
for ind, value := range v {
|
|
||||||
if ind == len(v)-1 {
|
|
||||||
builder.WriteString(strconv.Itoa(value))
|
|
||||||
} else {
|
|
||||||
builder.WriteString(strconv.Itoa(value))
|
|
||||||
builder.WriteString(", ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *IntSliceValue) 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
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v IntSliceValue) Empty() bool {
|
|
||||||
return len(v) == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v IntSliceValue) ExpectedLength(expectedLength int) bool {
|
|
||||||
return len(v) == expectedLength
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package flag
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
type StringSliceValue []string
|
|
||||||
|
|
||||||
func NewStringSliceValue() StringSliceValue {
|
|
||||||
arr := make([]string, 0, 3)
|
|
||||||
|
|
||||||
return StringSliceValue(arr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v StringSliceValue) String() string {
|
|
||||||
return strings.Join(v, ", ")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *StringSliceValue) Set(value string) error {
|
|
||||||
if len(value) > 0 {
|
|
||||||
*v = append(*v, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v StringSliceValue) Empty() bool {
|
|
||||||
return len(v) == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v StringSliceValue) ExpectedLength(expectedLength int) bool {
|
|
||||||
return len(v) == expectedLength
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package flag
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TimeDurationValue struct {
|
|
||||||
Duration time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTimeDurationValue() TimeDurationValue {
|
|
||||||
return TimeDurationValue{
|
|
||||||
Duration: 0 * time.Second,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v TimeDurationValue) String() string {
|
|
||||||
return v.Duration.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *TimeDurationValue) 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
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"flags": {
|
"flags": {
|
||||||
"account-name": {
|
"account-name": {
|
||||||
"type": "StringSliceValue",
|
"type": "string",
|
||||||
"description": "The name of the account"
|
"description": "The name of the account"
|
||||||
},
|
},
|
||||||
"all-images": {
|
"all-images": {
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
"description": "Set to true to show all videos from a status"
|
"description": "Set to true to show all videos from a status"
|
||||||
},
|
},
|
||||||
"attachment-id": {
|
"attachment-id": {
|
||||||
"type": "StringSliceValue",
|
"type": "MultiStringFlagValue",
|
||||||
"description": "The ID of the media attachment"
|
"description": "The ID of the media attachment"
|
||||||
},
|
},
|
||||||
"add-poll": {
|
"add-poll": {
|
||||||
|
@ -97,7 +97,7 @@
|
||||||
"description": "The replies policy of the list"
|
"description": "The replies policy of the list"
|
||||||
},
|
},
|
||||||
"mute-duration": {
|
"mute-duration": {
|
||||||
"type": "TimeDurationValue",
|
"type": "TimeDurationFlagValue",
|
||||||
"description": "Specify how long the mute should last for. To mute indefinitely, set this to 0s"
|
"description": "Specify how long the mute should last for. To mute indefinitely, set this to 0s"
|
||||||
},
|
},
|
||||||
"mute-notifications": {
|
"mute-notifications": {
|
||||||
|
@ -129,7 +129,7 @@
|
||||||
"description": "Set to true to allow viewers to make multiple choices in the poll"
|
"description": "Set to true to allow viewers to make multiple choices in the poll"
|
||||||
},
|
},
|
||||||
"poll-expires-in": {
|
"poll-expires-in": {
|
||||||
"type": "TimeDurationValue",
|
"type": "TimeDurationFlagValue",
|
||||||
"description": "The duration in which the poll is open for"
|
"description": "The duration in which the poll is open for"
|
||||||
},
|
},
|
||||||
"poll-hides-vote-counts": {
|
"poll-hides-vote-counts": {
|
||||||
|
@ -141,11 +141,11 @@
|
||||||
"description": "The ID of the poll"
|
"description": "The ID of the poll"
|
||||||
},
|
},
|
||||||
"poll-option": {
|
"poll-option": {
|
||||||
"type": "StringSliceValue",
|
"type": "MultiStringFlagValue",
|
||||||
"description": "A poll option. Use this multiple times to set multiple options"
|
"description": "A poll option. Use this multiple times to set multiple options"
|
||||||
},
|
},
|
||||||
"sensitive": {
|
"sensitive": {
|
||||||
"type": "BoolPtrValue",
|
"type": "BoolPtrFlagValue",
|
||||||
"description": "Set to true if the status should be marked as sensitive"
|
"description": "Set to true if the status should be marked as sensitive"
|
||||||
},
|
},
|
||||||
"show-preferences": {
|
"show-preferences": {
|
||||||
|
@ -180,21 +180,17 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The timeline category"
|
"description": "The timeline category"
|
||||||
},
|
},
|
||||||
"to": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "TBC"
|
|
||||||
},
|
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The type of resource you want to action on (e.g. account, status)"
|
"description": "The type of resource you want to action on (e.g. account, status)"
|
||||||
},
|
},
|
||||||
|
"to": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "TBC"
|
||||||
|
},
|
||||||
"visibility": {
|
"visibility": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The visibility of the posted status"
|
"description": "The visibility of the posted status"
|
||||||
},
|
|
||||||
"vote": {
|
|
||||||
"type": "IntSliceValue",
|
|
||||||
"description": "Add a vote to an option in a poll"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -202,33 +198,17 @@
|
||||||
"accept": {
|
"accept": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
||||||
],
|
],
|
||||||
"summary": "Accepts a request (e.g. a follow request)",
|
"summary": "Accepts a request (e.g. a follow request)",
|
||||||
"useConfig": true,
|
"useConfig": true,
|
||||||
"usePrinter": true
|
"usePrinter": true
|
||||||
},
|
},
|
||||||
"add": {
|
|
||||||
"additionalFields": [],
|
|
||||||
"flags": [
|
|
||||||
{ "flag": "account-name", "fieldName": "accountNames" },
|
|
||||||
{ "flag": "content", "default": "" },
|
|
||||||
{ "flag": "list-id", "fieldName": "listID", "default": "" },
|
|
||||||
{ "flag": "poll-id", "fieldName": "pollID", "default": "" },
|
|
||||||
{ "flag": "status-id", "fieldName": "statusID", "default": "" },
|
|
||||||
{ "flag": "to", "fieldName": "toResourceType", "default": "" },
|
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" },
|
|
||||||
{ "flag": "vote", "fieldName": "votes" }
|
|
||||||
],
|
|
||||||
"summary": "Add a resource to another resource",
|
|
||||||
"useConfig": true,
|
|
||||||
"usePrinter": true
|
|
||||||
},
|
|
||||||
"block": {
|
"block": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
||||||
],
|
],
|
||||||
"summary": "Blocks a resource (e.g. an account)",
|
"summary": "Blocks a resource (e.g. an account)",
|
||||||
|
@ -288,7 +268,7 @@
|
||||||
"follow": {
|
"follow": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "notify", "default": "false" },
|
{ "flag": "notify", "default": "false" },
|
||||||
{ "flag": "show-reposts", "default": "true" },
|
{ "flag": "show-reposts", "default": "true" },
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
||||||
|
@ -318,7 +298,7 @@
|
||||||
"mute": {
|
"mute": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "mute-duration" },
|
{ "flag": "mute-duration" },
|
||||||
{ "flag": "mute-notifications", "default": "false" },
|
{ "flag": "mute-notifications", "default": "false" },
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
||||||
|
@ -330,30 +310,17 @@
|
||||||
"reject": {
|
"reject": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
||||||
],
|
],
|
||||||
"summary": "Rejects a request (e.g. a follow request)",
|
"summary": "Rejects a request (e.g. a follow request)",
|
||||||
"useConfig": true,
|
"useConfig": true,
|
||||||
"usePrinter": true
|
"usePrinter": true
|
||||||
},
|
},
|
||||||
"remove": {
|
|
||||||
"additionalFields": [],
|
|
||||||
"flags": [
|
|
||||||
{ "flag": "account-name", "fieldName": "accountNames" },
|
|
||||||
{ "flag": "from", "fieldName": "fromResourceType", "default": "" },
|
|
||||||
{ "flag": "list-id", "fieldName": "listID", "default": "" },
|
|
||||||
{ "flag": "status-id", "fieldName": "statusID", "default": "" },
|
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
|
||||||
],
|
|
||||||
"summary": "",
|
|
||||||
"useConfig": true,
|
|
||||||
"usePrinter": true
|
|
||||||
},
|
|
||||||
"show": {
|
"show": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "all-images", "fieldName": "getAllImages", "default": "false" },
|
{ "flag": "all-images", "fieldName": "getAllImages", "default": "false" },
|
||||||
{ "flag": "all-videos", "fieldName": "getAllVideos", "default": "false" },
|
{ "flag": "all-videos", "fieldName": "getAllVideos", "default": "false" },
|
||||||
{ "flag": "attachment-id", "fieldName": "attachmentIDs" },
|
{ "flag": "attachment-id", "fieldName": "attachmentIDs" },
|
||||||
|
@ -383,7 +350,7 @@
|
||||||
"switch": {
|
"switch": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "to", "default": "" }
|
{ "flag": "to", "default": "" }
|
||||||
],
|
],
|
||||||
"summary": "Performs a switch operation (e.g. switching between logged in accounts)",
|
"summary": "Performs a switch operation (e.g. switching between logged in accounts)",
|
||||||
|
@ -393,7 +360,7 @@
|
||||||
"unblock": {
|
"unblock": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
||||||
],
|
],
|
||||||
"summary": "Unblocks a resource (e.g. an account)",
|
"summary": "Unblocks a resource (e.g. an account)",
|
||||||
|
@ -403,7 +370,7 @@
|
||||||
"unfollow": {
|
"unfollow": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
||||||
],
|
],
|
||||||
"summary": "Unfollow a resource (e.g. an account)",
|
"summary": "Unfollow a resource (e.g. an account)",
|
||||||
|
@ -413,7 +380,7 @@
|
||||||
"unmute": {
|
"unmute": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "account-name" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
||||||
],
|
],
|
||||||
"summary": "Umutes a specific resource (e.g. an account)",
|
"summary": "Umutes a specific resource (e.g. an account)",
|
||||||
|
|
Loading…
Reference in a new issue