We welcome contributions for new generators to extend the functionality of the OpenFeature CLI. Below are the steps to contribute a new generator:
-
Fork the Repository: Start by forking the repository to your GitHub account.
-
Clone the Repository: Clone the forked repository to your local machine.
-
Create a New Branch: Create a new branch for your generator. Use a descriptive name for the branch, such as
feature/add-new-generator
. -
Add Your Generator: Add your generator in the appropriate directory under
/internal/generate/generators/
. For example, if you are adding a generator for Python, you might create a new directory/internal/generate/generators/python/
and add your files there. -
Implement the Generator: Implement the generator logic. Ensure that your generator follows the existing patterns and conventions used in the project. Refer to the existing generators like
/internal/generate/generators/golang
or/internal/generate/generators/react
for examples. -
Write Tests: Write tests for your generator to ensure it works as expected. Add your tests in the appropriate test directory, such as
/internal/generate/generators/python/
. Write tests for any commands you may add, too. Add your command tests in the appropriate test directory, such ascmd/generate_test.go
. -
Register the Generator: After implementing your generator, you need to register it in the CLI under the
generate
command. Follow these steps to register your generator:-
Create a New Command Directory: Create a new directory under
cmd/generate
with the name of your target language. For example, if you are adding a generator for Python, create a new directorycmd/generate/python/
. -
Add Command File: In the new directory, create a file named
python.go
(replacepython
with the name of your target language). This file will define the CLI command for your generator. -
Implement Command: Implement the command logic in the
python.go
file. Refer to the existing commands likecmd/generate/golang/golang.go
orcmd/generate/react/react.go
for examples. -
Register Command: Open the
cmd/generate/generate.go
file and register your new command as a subcommand. Add an import statement for your new command package and callRoot.AddCommand(python.Cmd)
(replacepython
with the name of your target language).
-
-
Update Documentation: Update the documentation to include information about your new generator. This may include updating the README.md and any other relevant documentation files. You can run
make generate-docs
to assist with documentation updates. -
Commit and Push: Commit your changes and push the new branch to your forked repository.
-
Create a Pull Request: Create a pull request from your new branch to the main repository. Provide a clear and detailed description of your changes, including the purpose of the new generator and any relevant information.
-
Address Feedback: Be responsive to feedback from the maintainers. Make any necessary changes and update your pull request as needed.
The TemplateData
struct is used to pass data to the templates.
The following functions are automatically included in the templates:
Converts a string to PascalCase
{{ "hello world" | ToPascal }} // HelloWorld
Converts a string to camelCase
{{ "hello world" | ToCamel }} // helloWorld
Converts a string to kebab-case
{{ "hello world" | ToKebab }} // hello-world
Converts a string to snake_case
{{ "hello world" | ToSnake }} // hello_world
Converts a string to SCREAMING_SNAKE_CASE
{{ "hello world" | ToScreamingSnake }} // HELLO_WORLD
Converts a string to UPPER CASE
{{ "hello world" | ToUpper }} // HELLO WORLD
Converts a string to lower case
{{ "HELLO WORLD" | ToLower }} // hello world
Converts a string to Title Case
{{ "hello world" | ToTitle }} // Hello World
Wraps a string in double quotes
{{ "hello world" | Quote }} // "hello world"
Wraps only strings in double quotes
{{ "hello world" | QuoteString }} // "hello world"
{{ 123 | QuoteString }} // 123
You can add custom template functions by passing a FuncMap
to the GenerateFile
function.