in plc4go/tools/plc4xpcapanalyzer/ui/commands.go [674:715]
func (c Command) Execute(ctx context.Context, commandText string) (err error) {
defer func() {
if recoveredErr := recover(); recoveredErr != nil {
if log.Debug().Enabled() {
log.Error().
Str("stack", string(debug.Stack())).
Interface("err", err).
Msg("panic-ed")
}
err = errors.Errorf("panic occurred: %v.", recoveredErr)
}
}()
plc4xpcapanalyzerLog.Debug().
Stringer("c", c).Str("commandText", commandText).
Msg("c executes commandText")
if !c.acceptsCurrentText(commandText) {
return errors.Errorf("%s doesn't understand %s", c.Name, commandText)
}
if c.doesCommandTextTargetSubCommand(commandText) {
prepareForSubCommandForSubCommand := c.prepareForSubCommand(commandText)
for _, command := range c.subCommands {
if command.acceptsCurrentText(prepareForSubCommandForSubCommand) {
plc4xpcapanalyzerLog.Debug().
Stringer("c", c).
Str("commandText", commandText).
Msg("c delegates to sub command")
return command.Execute(ctx, prepareForSubCommandForSubCommand)
}
}
return errors.Errorf("%s not accepted by any subcommands of %s", commandText, c.Name)
} else {
if c.action == nil {
return NotDirectlyExecutable
}
plc4xpcapanalyzerLog.Debug().
Stringer("c", c).
Str("commandText", commandText).
Msg("c executes commandText directly")
preparedForParameters := c.prepareForParameters(commandText)
return c.action(ctx, c, preparedForParameters)
}
}