Skip to content

konstellation-io/kli

Repository files navigation

Kli

Build status Relase version License
Tests GitHub Release License
Component Coverage Bugs Maintainability Rating Go Report
KLI coverage bugs mr Go Report Card

This repo contains a CLI to access, query and manage KRE and KDL.

Frameworks and libraries

Development

You can compile the binary with this command:

go build -o kli cmd/main.go

Then run any command:

./kli help

# Output: 
Use Konstellation API from the command line.

Usage:
  kli [command]

Available Commands:
  kre         Manage KRE
  server      Manage servers for kli

Flags:
  -h, --help   help for kli

Use "kli [command] --help" for more information about a command.

Example:

./kli server ls

# Output
SERVER URL                                  
local* http://api.kre.local                 
int    https://api.your-domain.com 

Setting Version variables

  1. You can set a Version variable as a key/value pair directly:
./kli kre version config your-version --set SOME_VAR="any value"
# Output:
# [✔] Config updated for version 'your-version'.
  1. Add a value from an environment variable:
export SOME_VAR="any value"
./kli kre version config your-version --set-from-env SOME_VAR
# Output:
# [✔] Config updated for version 'your-version'.
  1. Add multiple variables from a file:
# variables.env file
SOME_VAR=12345
ANOTHER_VAR="some long string... "
./kli kre version config your-version --set-from-file variables.env
# Output:
# [✔] Config updated for version 'your-version'.

NOTE: godotenv library currently doesn't support multiline variables, as stated in PR #118 @godotenv. Use next example as a workaround.

  1. Add a file as value:
export SOME_VAR=$(cat any_file.txt) 
./kli kre version config your-version --set-from-env SOME_VAR
# Output:
# [✔] Config updated for version 'your-version'.

Testing

To create new tests install GoMock. Mocks used on tests are generated with mockgen, when you need a new mock, add the following:

//go:generate mockgen -source=${GOFILE} -destination=$PWD/mocks/${GOFILE} -package=mocks

To generate the mocks execute:

$ go generate ./...

Run tests

go test ./...

Linters

golangci-lint is a fast Go linters runner. It runs linters in parallel, uses caching, supports yaml config, has integrations with all major IDE and has dozens of linters included.

As you can see in the .golangci.yml config file of this repo, we enable more linters than the default and have more strict settings.

To run golangci-lint execute:

golangci-lint run

Versioning lifecycle

In the development lifecycle of KLI there are three main stages depend if we are going to add a new feature, release a new version with some features or apply a fix to a current release.

Alphas

In order to add new features just create a feature branch from master, and after merger the Pull Request a workflow will run the tests and if everything pass a new alpha tag will be created (like v0.0-alpha.0) and a new release will be generaged with this tag.

Releases

After some alpha versions we can create what we call a release, and to do that we have to run manual the Release Action. This workflow will create a new release branch and a new tag like v0.0.0. With this tag a new release will be generated.

Fixes

If we find out a bug in a release, we can apply a bugfix just creating a fix branch from the specific release branch, and createing a Pull Request to the same release branc. When the Pull Request is merged, after pass the tests, a new fix tag will be created just increasing the patch number of the version, and a new release will be build and released.

Release locally for debugging

A local release can be created for testing without creating anything official on the release page.

  • Make sure GoReleaser is installed
  • Run: goreleaser --skip-validate --skip-publish --rm-dist
  • Find the built binaries under dist/ folder.