func buildSortedCondition()

in internal/commands/metrics/aggregation/sorted-condition.go [34:73]


func buildSortedCondition(ctx *cli.Context, parseScope bool) (*api.TopNCondition, *api.Duration, error) {
	start := ctx.String("start")
	end := ctx.String("end")
	step := ctx.Generic("step").(*model.StepEnumValue).Selected

	metricsName := ctx.String("name")
	var scope *api.Scope
	if parseScope {
		tmp := utils.ParseScopeInTop(metricsName)
		scope = &tmp
	}
	order := ctx.Generic("order").(*model.OrderEnumValue).Selected
	topN := 5
	parentServiceID := ctx.String("service-id")
	parentService, normal, err := interceptor.ParseServiceID(parentServiceID)
	if err != nil {
		return nil, nil, err
	}

	if ctx.NArg() > 0 {
		nn, err2 := strconv.Atoi(ctx.Args().First())
		if err2 != nil {
			return nil, nil, fmt.Errorf("the 1st argument must be a number: %v", err2)
		}
		topN = nn
	}

	return &api.TopNCondition{
			Name:          metricsName,
			ParentService: &parentService,
			Normal:        &normal,
			Scope:         scope,
			TopN:          topN,
			Order:         order,
		}, &api.Duration{
			Start: start,
			End:   end,
			Step:  step,
		}, nil
}