fix: don't load config for init or version

This commit is contained in:
Dan Anglin 2024-06-25 11:47:29 +01:00
parent f678273544
commit 727b0c43ac
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638

View file

@ -71,121 +71,131 @@ func run() error {
command := flag.Arg(0) command := flag.Arg(0)
args := flag.Args()[1:] args := flag.Args()[1:]
config, err := config.NewConfigFromFile(configDir) var (
enbasConfig *config.Config
enbasPrinter *printer.Printer
err error
)
if command == executor.CommandInit || command == executor.CommandVersion {
enbasPrinter = printer.NewPrinter(*noColor, "", 0)
} else {
enbasConfig, err = config.NewConfigFromFile(configDir)
if err != nil { if err != nil {
printer := printer.NewPrinter(*noColor, "", 80) enbasPrinter = printer.NewPrinter(*noColor, "", 0)
printer.PrintFailure("unable to load the configuration: " + err.Error() + ".") enbasPrinter.PrintFailure("unable to load the configuration: " + err.Error() + ".")
return err return err
} }
printer := printer.NewPrinter(*noColor, config.Integrations.Pager, config.LineWrapMaxWidth) enbasPrinter = printer.NewPrinter(*noColor, enbasConfig.Integrations.Pager, enbasConfig.LineWrapMaxWidth)
}
executorMap := map[string]executor.Executor{ executorMap := map[string]executor.Executor{
executor.CommandAccept: executor.NewAcceptOrRejectExecutor( executor.CommandAccept: executor.NewAcceptOrRejectExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandAccept, executor.CommandAccept,
executor.CommandSummaryLookup(executor.CommandAccept), executor.CommandSummaryLookup(executor.CommandAccept),
), ),
executor.CommandAdd: executor.NewAddExecutor( executor.CommandAdd: executor.NewAddExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandAdd, executor.CommandAdd,
executor.CommandSummaryLookup(executor.CommandAdd), executor.CommandSummaryLookup(executor.CommandAdd),
), ),
executor.CommandBlock: executor.NewBlockOrUnblockExecutor( executor.CommandBlock: executor.NewBlockOrUnblockExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandBlock, executor.CommandBlock,
executor.CommandSummaryLookup(executor.CommandBlock), executor.CommandSummaryLookup(executor.CommandBlock),
), ),
executor.CommandCreate: executor.NewCreateExecutor( executor.CommandCreate: executor.NewCreateExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandCreate, executor.CommandCreate,
executor.CommandSummaryLookup(executor.CommandCreate), executor.CommandSummaryLookup(executor.CommandCreate),
), ),
executor.CommandDelete: executor.NewDeleteExecutor( executor.CommandDelete: executor.NewDeleteExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandDelete, executor.CommandDelete,
executor.CommandSummaryLookup(executor.CommandDelete), executor.CommandSummaryLookup(executor.CommandDelete),
), ),
executor.CommandEdit: executor.NewEditExecutor( executor.CommandEdit: executor.NewEditExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandEdit, executor.CommandEdit,
executor.CommandSummaryLookup(executor.CommandEdit), executor.CommandSummaryLookup(executor.CommandEdit),
), ),
executor.CommandFollow: executor.NewFollowOrUnfollowExecutor( executor.CommandFollow: executor.NewFollowOrUnfollowExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandFollow, executor.CommandFollow,
executor.CommandSummaryLookup(executor.CommandFollow), executor.CommandSummaryLookup(executor.CommandFollow),
), ),
executor.CommandInit: executor.NewInitExecutor( executor.CommandInit: executor.NewInitExecutor(
printer, enbasPrinter,
configDir, configDir,
executor.CommandInit, executor.CommandInit,
executor.CommandSummaryLookup(executor.CommandInit), executor.CommandSummaryLookup(executor.CommandInit),
), ),
executor.CommandLogin: executor.NewLoginExecutor( executor.CommandLogin: executor.NewLoginExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandLogin, executor.CommandLogin,
executor.CommandSummaryLookup(executor.CommandLogin), executor.CommandSummaryLookup(executor.CommandLogin),
), ),
executor.CommandMute: executor.NewMuteOrUnmuteExecutor( executor.CommandMute: executor.NewMuteOrUnmuteExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandMute, executor.CommandMute,
executor.CommandSummaryLookup(executor.CommandMute), executor.CommandSummaryLookup(executor.CommandMute),
), ),
executor.CommandReject: executor.NewAcceptOrRejectExecutor( executor.CommandReject: executor.NewAcceptOrRejectExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandReject, executor.CommandReject,
executor.CommandSummaryLookup(executor.CommandReject), executor.CommandSummaryLookup(executor.CommandReject),
), ),
executor.CommandRemove: executor.NewRemoveExecutor( executor.CommandRemove: executor.NewRemoveExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandRemove, executor.CommandRemove,
executor.CommandSummaryLookup(executor.CommandRemove), executor.CommandSummaryLookup(executor.CommandRemove),
), ),
executor.CommandSwitch: executor.NewSwitchExecutor( executor.CommandSwitch: executor.NewSwitchExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandSwitch, executor.CommandSwitch,
executor.CommandSummaryLookup(executor.CommandSwitch), executor.CommandSummaryLookup(executor.CommandSwitch),
), ),
executor.CommandUnfollow: executor.NewFollowOrUnfollowExecutor( executor.CommandUnfollow: executor.NewFollowOrUnfollowExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandUnfollow, executor.CommandUnfollow,
executor.CommandSummaryLookup(executor.CommandUnfollow), executor.CommandSummaryLookup(executor.CommandUnfollow),
), ),
executor.CommandUnmute: executor.NewMuteOrUnmuteExecutor( executor.CommandUnmute: executor.NewMuteOrUnmuteExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandUnmute, executor.CommandUnmute,
executor.CommandSummaryLookup(executor.CommandUnmute), executor.CommandSummaryLookup(executor.CommandUnmute),
), ),
executor.CommandUnblock: executor.NewBlockOrUnblockExecutor( executor.CommandUnblock: executor.NewBlockOrUnblockExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandUnblock, executor.CommandUnblock,
executor.CommandSummaryLookup(executor.CommandUnblock), executor.CommandSummaryLookup(executor.CommandUnblock),
), ),
executor.CommandShow: executor.NewShowExecutor( executor.CommandShow: executor.NewShowExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandShow, executor.CommandShow,
executor.CommandSummaryLookup(executor.CommandShow), executor.CommandSummaryLookup(executor.CommandShow),
), ),
executor.CommandVersion: executor.NewVersionExecutor( executor.CommandVersion: executor.NewVersionExecutor(
printer, enbasPrinter,
executor.CommandVersion, executor.CommandVersion,
executor.CommandSummaryLookup(executor.CommandVersion), executor.CommandSummaryLookup(executor.CommandVersion),
binaryVersion, binaryVersion,
@ -194,8 +204,8 @@ func run() error {
gitCommit, gitCommit,
), ),
executor.CommandWhoami: executor.NewWhoAmIExecutor( executor.CommandWhoami: executor.NewWhoAmIExecutor(
printer, enbasPrinter,
config, enbasConfig,
executor.CommandWhoami, executor.CommandWhoami,
executor.CommandSummaryLookup(executor.CommandWhoami), executor.CommandSummaryLookup(executor.CommandWhoami),
), ),
@ -205,14 +215,14 @@ func run() error {
if !ok { if !ok {
err := executor.UnknownCommandError{Command: command} err := executor.UnknownCommandError{Command: command}
printer.PrintFailure(err.Error() + ".") enbasPrinter.PrintFailure(err.Error() + ".")
flag.Usage() flag.Usage()
return err return err
} }
if err := executor.Execute(exe, args); err != nil { if err := executor.Execute(exe, args); err != nil {
printer.PrintFailure("(" + command + ") " + err.Error() + ".") enbasPrinter.PrintFailure("(" + command + ") " + err.Error() + ".")
return err return err
} }