Skip to content

konstellation-io/kai-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 KAI servers.

Installation

From releases page

Go to release page and download the binary you prefer.

Homebrew

brew install konstellation-io/tap/kli

Scoop (Windows)

Scoop installation is made via a Konstellation owned bucket.

scoop bucket add konstellation-io https://github.com/konstellation-io/scoop-bucket.git
scoop install konstellation-io/kli

Installation script

Fetch the script and execute it locally.

$ curl -fsSL -o get_kli.sh https://raw.githubusercontent.com/konstellation-io/kai-kli/main/scripts/get-kli.sh
$ chmod 700 get_kli.sh
$ ./get_kli.sh

Use it with --help flag to get a list of options.

./get_kli.sh --help

Frameworks and libraries

Development

You can compile the binary with this command:

./scripts/generate_release.sh <version> <executable_name>

Then run any command:

./kli help

# Output: 
Use Konstellation API from the command line.

Usage:
  kli [command]

Available Commands:
  kai         Manage KAI
  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.kai.local                 
int    https://api.your-domain.com 

Setting Version variables

  1. You can set a Version variable as a key/value pair directly:
./kli kai 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 kai 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 kai 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 kai 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 we use the Nyx automatic semantic version tool.

In order to allow Nyx infer the next version to publish we use the Angular commit convention standard.

WARNING: If the above standard is not correctly followed Nyx won't be able to infer the next version and a new release won't be published.

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.