func()

in plc4go/tools/plc4xbrowser/ui/commands.go [749:791]


func (c Command) Execute(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)
		}
	}()
	plc4xBrowserLog.Debug().
		Stringer("c", c).
		Str("commandText", commandText).
		Msg("%s executes %s")
	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) {
				plc4xBrowserLog.Debug().
					Stringer("c", c).
					Stringer("command", command).
					Msg("c delegates to sub command")
				return command.Execute(prepareForSubCommandForSubCommand)
			}
		}
		return errors.Errorf("%s not accepted by any subcommands of %s", commandText, c.Name)
	} else {
		if c.action == nil {
			return NotDirectlyExecutable
		}
		plc4xBrowserLog.Debug().
			Stringer("c", c).
			Str("commandText", commandText).
			Msg("c executes commandText directly")
		preparedForParameters := c.prepareForParameters(commandText)
		return c.action(c, preparedForParameters)
	}
}