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
55 lines
1.1 KiB
Go
55 lines
1.1 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"
|
|
|
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
|
|
)
|
|
|
|
type VersionExecutor struct {
|
|
*flag.FlagSet
|
|
|
|
printer *printer.Printer
|
|
showFullVersion bool
|
|
binaryVersion string
|
|
buildTime string
|
|
goVersion string
|
|
gitCommit string
|
|
}
|
|
|
|
func NewVersionExecutor(
|
|
printer *printer.Printer,
|
|
name,
|
|
summary,
|
|
binaryVersion,
|
|
buildTime,
|
|
goVersion,
|
|
gitCommit string,
|
|
) *VersionExecutor {
|
|
command := VersionExecutor{
|
|
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
|
|
|
printer: printer,
|
|
binaryVersion: binaryVersion,
|
|
buildTime: buildTime,
|
|
goVersion: goVersion,
|
|
gitCommit: gitCommit,
|
|
showFullVersion: false,
|
|
}
|
|
|
|
command.BoolVar(&command.showFullVersion, flagFull, false, "prints the full build information")
|
|
|
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
|
|
|
return &command
|
|
}
|
|
|
|
func (v *VersionExecutor) Execute() error {
|
|
v.printer.PrintVersion(v.showFullVersion, v.binaryVersion, v.buildTime, v.goVersion, v.gitCommit)
|
|
|
|
return nil
|
|
}
|