fix: don't load config for init or version
This commit is contained in:
parent
f678273544
commit
727b0c43ac
1 changed files with 55 additions and 45 deletions
|
@ -71,121 +71,131 @@ func run() error {
|
|||
command := flag.Arg(0)
|
||||
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 {
|
||||
printer := printer.NewPrinter(*noColor, "", 80)
|
||||
printer.PrintFailure("unable to load the configuration: " + err.Error() + ".")
|
||||
enbasPrinter = printer.NewPrinter(*noColor, "", 0)
|
||||
enbasPrinter.PrintFailure("unable to load the configuration: " + err.Error() + ".")
|
||||
|
||||
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{
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue