Dan Anglin
42251f6df8
SUMMARY This commit adds configuration support to enbas. The configuration is stored as a JSON file in the user specified configuration directory. When using enbas for the first time, the user will first need to execute the new init command in order to generate the configuration. Once this has been generated the user can edit the settings to personalise their experience, login to their account and use enbas as normal. For now the configurable settings included in the configuration are as follows: - The path to the credentials file (by default this is set to a file in the same directory as the configuration file). - The path to the cache directory. - The character limit used for line wrapping. - The programs used for integrations such as paging, media viewing, opening URLs, etc. CHANGES - added the new config type. - added the new init executor for generating a new configuration file. - removed the following top level flags in favour of the new configration support. - cache-dir - pager - image-viewer - video-player - max-terminal-width - added a new error type for use when an unknown media attachment ID is specified. - updated the usage function for the executors to support a case where a flagsets has no flags. - update .golangci.yaml to disable some linters
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package executor
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
|
|
"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 DeleteExecutor struct {
|
|
*flag.FlagSet
|
|
|
|
printer *printer.Printer
|
|
config *config.Config
|
|
resourceType string
|
|
listID string
|
|
}
|
|
|
|
func NewDeleteExecutor(printer *printer.Printer, config *config.Config, name, summary string) *DeleteExecutor {
|
|
deleteExe := DeleteExecutor{
|
|
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
|
|
|
printer: printer,
|
|
config: config,
|
|
}
|
|
|
|
deleteExe.StringVar(&deleteExe.resourceType, flagType, "", "Specify the type of resource to delete")
|
|
deleteExe.StringVar(&deleteExe.listID, flagListID, "", "Specify the ID of the list to delete")
|
|
|
|
deleteExe.Usage = commandUsageFunc(name, summary, deleteExe.FlagSet)
|
|
|
|
return &deleteExe
|
|
}
|
|
|
|
func (d *DeleteExecutor) Execute() error {
|
|
if d.resourceType == "" {
|
|
return FlagNotSetError{flagText: flagType}
|
|
}
|
|
|
|
funcMap := map[string]func(*client.Client) error{
|
|
resourceList: d.deleteList,
|
|
}
|
|
|
|
doFunc, ok := funcMap[d.resourceType]
|
|
if !ok {
|
|
return UnsupportedTypeError{resourceType: d.resourceType}
|
|
}
|
|
|
|
gtsClient, err := client.NewClientFromFile(d.config.CredentialsFile)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to create the GoToSocial client: %w", err)
|
|
}
|
|
|
|
return doFunc(gtsClient)
|
|
}
|
|
|
|
func (d *DeleteExecutor) deleteList(gtsClient *client.Client) error {
|
|
if d.listID == "" {
|
|
return FlagNotSetError{flagText: flagListID}
|
|
}
|
|
|
|
if err := gtsClient.DeleteList(d.listID); err != nil {
|
|
return fmt.Errorf("unable to delete the list: %w", err)
|
|
}
|
|
|
|
d.printer.PrintSuccess("The list was successfully deleted.")
|
|
|
|
return nil
|
|
}
|