From 727b0c43ac3f7ac171167e10958fb06fb7e45f3a Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Tue, 25 Jun 2024 11:47:29 +0100 Subject: [PATCH] fix: don't load config for init or version --- cmd/enbas/main.go | 100 +++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/cmd/enbas/main.go b/cmd/enbas/main.go index 3858f4e..d8107e4 100644 --- a/cmd/enbas/main.go +++ b/cmd/enbas/main.go @@ -71,121 +71,131 @@ func run() error { command := flag.Arg(0) args := flag.Args()[1:] - config, err := config.NewConfigFromFile(configDir) - if err != nil { - printer := printer.NewPrinter(*noColor, "", 80) - printer.PrintFailure("unable to load the configuration: " + err.Error() + ".") + var ( + enbasConfig *config.Config + enbasPrinter *printer.Printer + err error + ) - return err + if command == executor.CommandInit || command == executor.CommandVersion { + enbasPrinter = printer.NewPrinter(*noColor, "", 0) + } else { + enbasConfig, err = config.NewConfigFromFile(configDir) + if err != nil { + enbasPrinter = printer.NewPrinter(*noColor, "", 0) + enbasPrinter.PrintFailure("unable to load the configuration: " + err.Error() + ".") + + return err + } + + enbasPrinter = printer.NewPrinter(*noColor, enbasConfig.Integrations.Pager, enbasConfig.LineWrapMaxWidth) } - printer := printer.NewPrinter(*noColor, config.Integrations.Pager, config.LineWrapMaxWidth) - executorMap := map[string]executor.Executor{ executor.CommandAccept: executor.NewAcceptOrRejectExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandAccept, executor.CommandSummaryLookup(executor.CommandAccept), ), executor.CommandAdd: executor.NewAddExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandAdd, executor.CommandSummaryLookup(executor.CommandAdd), ), executor.CommandBlock: executor.NewBlockOrUnblockExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandBlock, executor.CommandSummaryLookup(executor.CommandBlock), ), executor.CommandCreate: executor.NewCreateExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandCreate, executor.CommandSummaryLookup(executor.CommandCreate), ), executor.CommandDelete: executor.NewDeleteExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandDelete, executor.CommandSummaryLookup(executor.CommandDelete), ), executor.CommandEdit: executor.NewEditExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandEdit, executor.CommandSummaryLookup(executor.CommandEdit), ), executor.CommandFollow: executor.NewFollowOrUnfollowExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandFollow, executor.CommandSummaryLookup(executor.CommandFollow), ), executor.CommandInit: executor.NewInitExecutor( - printer, + enbasPrinter, configDir, executor.CommandInit, executor.CommandSummaryLookup(executor.CommandInit), ), executor.CommandLogin: executor.NewLoginExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandLogin, executor.CommandSummaryLookup(executor.CommandLogin), ), executor.CommandMute: executor.NewMuteOrUnmuteExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandMute, executor.CommandSummaryLookup(executor.CommandMute), ), executor.CommandReject: executor.NewAcceptOrRejectExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandReject, executor.CommandSummaryLookup(executor.CommandReject), ), executor.CommandRemove: executor.NewRemoveExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandRemove, executor.CommandSummaryLookup(executor.CommandRemove), ), executor.CommandSwitch: executor.NewSwitchExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandSwitch, executor.CommandSummaryLookup(executor.CommandSwitch), ), executor.CommandUnfollow: executor.NewFollowOrUnfollowExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandUnfollow, executor.CommandSummaryLookup(executor.CommandUnfollow), ), executor.CommandUnmute: executor.NewMuteOrUnmuteExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandUnmute, executor.CommandSummaryLookup(executor.CommandUnmute), ), executor.CommandUnblock: executor.NewBlockOrUnblockExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandUnblock, executor.CommandSummaryLookup(executor.CommandUnblock), ), executor.CommandShow: executor.NewShowExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandShow, executor.CommandSummaryLookup(executor.CommandShow), ), executor.CommandVersion: executor.NewVersionExecutor( - printer, + enbasPrinter, executor.CommandVersion, executor.CommandSummaryLookup(executor.CommandVersion), binaryVersion, @@ -194,8 +204,8 @@ func run() error { gitCommit, ), executor.CommandWhoami: executor.NewWhoAmIExecutor( - printer, - config, + enbasPrinter, + enbasConfig, executor.CommandWhoami, executor.CommandSummaryLookup(executor.CommandWhoami), ), @@ -205,14 +215,14 @@ func run() error { if !ok { err := executor.UnknownCommandError{Command: command} - printer.PrintFailure(err.Error() + ".") + enbasPrinter.PrintFailure(err.Error() + ".") flag.Usage() return err } if err := executor.Execute(exe, args); err != nil { - printer.PrintFailure("(" + command + ") " + err.Error() + ".") + enbasPrinter.PrintFailure("(" + command + ") " + err.Error() + ".") return err }