// MustGenerate acts just like Generate, but panics instead of returning errors.
192916
func MustGenerate() string {
	id, err := Generate()
	if err == nil {
		return id
	}
	panic(err)
}
829224
func (g *Generator) Generate() (_ []string, err error) {
	if g.API == nil {
		return nil, fmt.Errorf("missing API definition, make sure design is properly initialized")
	}

	go utils.Catch(nil, func() { g.Cleanup() })

	defer func() {
		if err != nil {
			g.Cleanup()
		}
	}()

	s := APISchema(g.API)
	js, err := s.JSON()
	if err != nil {
		return
	}

	g.OutDir = filepath.Join(g.OutDir, "schema")
	os.RemoveAll(g.OutDir)
	os.MkdirAll(g.OutDir, 0755)
	g.genfiles = append(g.genfiles, g.OutDir)
	schemaFile := filepath.Join(g.OutDir, "schema.json")
	if err = ioutil.WriteFile(schemaFile, js, 0644); err != nil {
		return
	}
	g.genfiles = append(g.genfiles, schemaFile)

	return g.genfiles, nil
}
557766
func (b *Base) MustTransformArray(entities interface{}) []map[string]interface{} {
	res, err := b.TransformArray(entities)
	if err != nil {
		panic(err)
	}
	return res
}
521096
func (g *NamespaceGeneratorV1) StructuredGenerate() (runtime.Object, error) {
	if err := g.validate(); err != nil {
		return nil, err
	}
	namespace := &v1.Namespace{}
	namespace.Name = g.Name
	return namespace, nil
}
1092315
func MustNewGenerator() *Generator {
	g, err := NewGenerator()
	if err != nil {
		panic(err)
	}
	return g
}
671212
func (ins *Insert) processGenerate(vcursor VCursor, bindVars map[string]*querypb.BindVariable) (insertID int64, err error) {
	if ins.Generate == nil {
		return 0, nil
	}

	// Scan input values to compute the number of values to generate, and
	// keep track of where they should be filled.
	resolved, err := ins.Generate.Values.ResolveList(bindVars)
	if err != nil {
		return 0, vterrors.Wrap(err, "processGenerate")
	}
	count := int64(0)
	for _, val := range resolved {
		if val.IsNull() {
			count++
		}
	}

	// If generation is needed, generate the requested number of values (as one call).
	if count != 0 {
		rss, _, err := vcursor.ResolveDestinations(ins.Generate.Keyspace.Name, nil, []key.Destination{key.DestinationAnyShard{}})
		if err != nil {
			return 0, vterrors.Wrap(err, "processGenerate")
		}
		if len(rss) != 1 {
			return 0, vterrors.Wrapf(err, "processGenerate len(rss)=%v", len(rss))
		}
		bindVars := map[string]*querypb.BindVariable{"n": sqltypes.Int64BindVariable(count)}
		qr, err := vcursor.ExecuteStandalone(ins.Generate.Query, bindVars, rss[0])
		if err != nil {
			return 0, err
		}
		// If no rows are returned, it's an internal error, and the code
		// must panic, which will be caught and reported.
		insertID, err = sqltypes.ToInt64(qr.Rows[0][0])
		if err != nil {
			return 0, err
		}
	}

	// Fill the holes where no value was supplied.
	cur := insertID
	for i, v := range resolved {
		if v.IsNull() {
			bindVars[SeqVarName+strconv.Itoa(i)] = sqltypes.Int64BindVariable(cur)
			cur++
		} else {
			bindVars[SeqVarName+strconv.Itoa(i)] = sqltypes.ValueBindVariable(v)
		}
	}
	return insertID, nil
}
355590
func (d *Decoder) MustDecode(v interface{}) {
	if d.err != nil {
		panic(d.err)
	}
	d.mustDecode(v)
}
1325362
func MustCompile(input string, options Options) *template.Template {
	t, err := Compile(input, options)
	if err != nil {
		panic(err)
	}
	return t
}
1022090
func (s *mustRunAs) Generate(pod *api.Pod, container *api.Container) (*int64, error) {
	return &s.opts.Ranges[0].Min, nil
}
891577
func (s ConfigMapGeneratorV1) StructuredGenerate() (runtime.Object, error) {
	if err := s.validate(); err != nil {
		return nil, err
	}
	configMap := &api.ConfigMap{}
	configMap.Name = s.Name
	configMap.Data = map[string]string{}
	if len(s.FileSources) > 0 {
		if err := handleConfigMapFromFileSources(configMap, s.FileSources); err != nil {
			return nil, err
		}
	}
	if len(s.LiteralSources) > 0 {
		if err := handleConfigMapFromLiteralSources(configMap, s.LiteralSources); err != nil {
			return nil, err
		}
	}
	return configMap, nil
}
170829
func (c *Client) SetGenerate(enable bool, numCPUs int) error {
	return c.SetGenerateAsync(enable, numCPUs).Receive()
}
40742
func (vr *validateRun) validateGenerated(ctx context.Context, path string) (*validateResult, error) {
	// -config-set flag must not be used in this mode, config sets are defined
	// on Starlark level.
	if vr.configSet != "" {
		return nil, base.NewCLIError("-config-set can't be used when validating Starlark-based configs")
	}

	meta := vr.DefaultMeta()
	output, err := base.GenerateConfigs(ctx, path, &meta, &vr.Meta)
	if err != nil {
		return nil, err
	}

	result := &validateResult{}

	if meta.ConfigDir != "-" {
		// Find files that are present on disk, but no longer in the output.
		tracked, err := lucicfg.FindTrackedFiles(meta.ConfigDir, meta.TrackedFiles)
		if err != nil {
			return result, err
		}
		for _, f := range tracked {
			if _, present := output.Data[f]; !present {
				result.Stale = append(result.Stale, f)
			}
		}
		// Find files that are newer in the output or do not exist on disk.
		changed, _ := output.Compare(meta.ConfigDir)
		result.Stale = append(result.Stale, changed...)
	}

	if len(result.Stale) != 0 {
		return result, fmt.Errorf(
			"following files on disk are out-of-date: %s.\n"+
				"  Run `lucicfg generate %q` to update them",
			strings.Join(result.Stale, ", "), path)
	}

	// Validate via LUCI Config RPC. This silently skips configs not belonging to
	// any config sets.
	result.Validation, err = base.ValidateOutput(
		ctx,
		output,
		vr.ConfigService,
		meta.ConfigServiceHost,
		meta.FailOnWarnings)
	return result, err
}
903842
func handleGetGenerate(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
	return s.cfg.CPUMiner.IsMining(), nil
}
1183509
func NewGenerator(options ...Option) *Generator {
	g := &Generator{}
	g.validator = codegen.NewValidator()

	for _, option := range options {
		option(g)
	}

	return g
}
320718
func MustCompile(rules string, variables map[string]interface{}) (r *Rules) {
	r, err := Compile(rules, variables)
	if err != nil {
		panic(err)
	}
	return
}
687110
func (g *Generator) Generate() (_ []string, err error) {
	if g.API == nil {
		return nil, fmt.Errorf("missing API definition, make sure design is properly initialized")
	}

	go utils.Catch(nil, func() { g.Cleanup() })

	defer func() {
		if err != nil {
			g.Cleanup()
		}
	}()

	if g.AppPkg == "" {
		g.AppPkg = "app"
	}
	g.smartenPkg()
	elems := strings.Split(g.AppPkg, "/")
	pkgName := elems[len(elems)-1]
	codegen.Reserved[pkgName] = true

	err = g.API.IterateResources(func(r *design.ResourceDefinition) error {
		var (
			filename string
			err      error
		)
		if g.Resource == "" || g.Resource == r.Name {
			filename, err = genmain.GenerateController(g.Force, g.Regen, g.AppPkg, g.OutDir, g.Pkg, r.Name, r)
		}

		if err != nil {
			return err
		}
		g.genfiles = append(g.genfiles, filename)

		return nil
	})
	if err != nil {
		return nil, err
	}

	return g.genfiles, err
}
385015
func (g *ServiceAccountGeneratorV1) StructuredGenerate() (runtime.Object, error) {
	if err := g.validate(); err != nil {
		return nil, err
	}
	serviceAccount := &v1.ServiceAccount{}
	serviceAccount.Name = g.Name
	return serviceAccount, nil
}