Example #1
0
func (this *Dispatcher) Dispatch(request *io.Request, response *io.Response) Interactor {
	_, hasHelpParam := request.GetUniversalParamString("h")
	if hasHelpParam {
		return this.locator.GetInteractorByName("help")
	}

	interator := this.locator.GetInteractorByName(request.InteractorName)
	if interator == nil {
		return this.locator.GetInteractorByName("help")
	}
	return interator
}
func (this *OptionsApplier) Apply(request *io.Request, response *io.Response) {
	var ok bool
	_, ok = request.GetUniversalParamString("v")
	if ok {
		response.SetVerbose(true)
	}

	_, ok = request.GetUniversalParamString("n")
	if ok {
		response.SetVerbose(false)
	}
}
func (this ParamInteractor) GetParam(paramName string, request *io.Request) ParamValue {
	registeredParam := this.GetRegisteredParamByName(paramName)
	if &registeredParam == nil {
		return registeredParam
	}
	paramValue, ok := request.GetInteractorParamString(paramName)
	if ok {
		registeredParam.Value = paramValue
	} else {
		registeredParam.Value = registeredParam.DefaultValue
	}
	return registeredParam
}
Example #4
0
func (this HelpShower) Execute(request *io.Request, response *io.Response) {
	var helpData help.Container
	if request.InteractorNameEmpty() {
		helpData = help.CreateGeneralHelpContainer(*this.locator)
		response.AddError(errors.New("No interactor name provided"))
	} else {
		interactor := this.locator.GetInteractorByName(request.InteractorName)
		if &interactor == nil {
			response.AddErrorMessage("Cannot show help for an unknown interactor " + request.InteractorName)
			return
		}
		helpData = help.CreateInteractorHelpContainer(interactor)
	}

	helpResponseCreator := &help.HelpResponseCreator{}
	helpResponseCreator.CreateHelpResponse(helpData)
}
func (this ParamInteractor) Validate(request *io.Request) error {
	missingRequiredParams := []string{}
	if len(this.Params) > 0 {
		for _, param := range this.Params {
			if !param.IsRequired {
				continue
			}
			_, found := request.GetInteractorParamString(param.ParamName)
			if !found {
				missingRequiredParams = append(missingRequiredParams, param.ParamName)
			}
		}
	}

	if len(missingRequiredParams) > 0 {
		return errors.New("Missing required interactor param(s): " + strings.Join(missingRequiredParams, ","))
	}

	if this.ValidatorCallback != nil {
		return this.ValidatorCallback(request)
	}

	return nil
}
Example #6
0
func (this *Validator) isInteractorEmpty(request *io.Request) bool {
	_, hasHelpOption := request.GetUniversalParamString("h")
	return !hasHelpOption && request.InteractorNameEmpty()
}