Beispiel #1
0
func List(observer *rules.Observer, service string) error {
	if observer == nil {
		return errors.New("Observer is not created")
	}

	observer.Load()

	if service != "" {
		err := listService(observer, service)

		if err != nil {
			return err
		}
	} else {
		services := observer.GetServices()

		if len(services) == 0 {
			fmtc.Println("\n{y}No services and mocks are created{!}\n")
			return nil
		}

		for _, serviceName := range services {
			err := listService(observer, serviceName)

			if err != nil {
				return nil
			}
		}
	}

	fmt.Println("")

	return nil
}
Beispiel #2
0
func listService(observer *rules.Observer, service string) error {
	rulesNames := observer.GetServiceRulesNames(service)

	if len(rulesNames) == 0 {
		return fmt.Errorf("Service %s is not found", service)
	}

	fmtc.Printf(
		"\n{*r}%s{!} {s}(%s){!}\n", service,
		pluralize.Pluralize(len(rulesNames), "mock", "mocks"),
	)

	for _, ruleName := range rulesNames {
		rule := observer.GetRuleByName(service, ruleName)

		if rule == nil {
			continue
		}

		showRuleInfo(rule)
	}

	return nil
}