Skip to content

opencontrolplane-gen

opencontrolplane-gen is a code transformation tool to use together with go generate.

Commands

opencontrolplane-gen defines a Command interface to transform go source files line by line.

Commands are executed by a Runner which processes go source files in single pass fashion.

This requires Commands to be stateful in regards of their activation state and arguments.

Runner

A Runner takes an abitrary number of Commands to transform individual go source files.

When nesting Commands in source files, be aware of the order that Commands are defined in the Runner.

Installation

Use go install to get the latest version of opencontrolplane-gen:

go install github.com/openmcp-project/opencontrolplane-gen@latest

Usage

opencontrolplane-gen is expected to be used with go generate, see the following example source code file:

//go:generate opencontrolplane-gen
package testdata

// opencontrolplane-gen:replace TestReconciler=RECONCILER_NAME
type TestReconciler struct {
	namespace string
	//opencontrolplane-gen:if OPTIONAL_FIELDS=include
	conditionalName string
	// test nested command
	//opencontrolplane-gen:replace Replace=FIELD_NAME
	conditionalReplace int
	//opencontrolplane-gen:fi
}

// opencontrolplane-gen:replace TestReconciler=RECONCILER_NAME
func (r *TestReconciler) Reconciler() {
	//opencontrolplane-gen:replace name=FIELD_NAME namespace=FIELD_NAMESPACE
	var name, namespace string
	//opencontrolplane-gen:replace name=FIELD_NAME
	_ = name
	//opencontrolplane-gen:replace namespace=FIELD_NAMESPACE
	_ = namespace
}

opencontrolplane-gen allows in memory transformation via the DRY_RUN environment variable:

DRY_RUN=true go generate ./...

Pass values by defining the environment variables used in the command directives:

DRY_RUN=true RECONCILER_NAME=MyReconciler OPTIONAL_FIELDS=include go generate ./...

Inspect debug output:

DRY_RUN=true DEBUG=true OPTIONAL_FIELDS=include go generate ./...

Save changes to disk:

go generate ./...

Execution Options

Environment Variables:

  • DRY_RUN (bool): 1 or true result in the in-memory source code transformation being printed to stdout.
  • DEBUG (bool): 1 or true result in debug output being printed to stdout.

Support, Feedback, Contributing

This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.

Security / Disclosure

If you find any bug that may be a security problem, please follow our instructions at in our security policy on how to report it. Please do not create GitHub issues for security-related doubts or problems.

Code of Conduct

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.

Licensing

Copyright OpenControlPlane contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.


BMWK-EU funding logo

OpenControlPlane is part of ApeiroRA, an EU Important Project of Common European Interest (IPCEI-CIS).

Copyright Linux Foundation Europe. For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.

About

A code transformation tool for go generate

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages