kpm

command module
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

Kpm: KCL Package Manager

English | 简体中文

Introduction | Installation | Quick start

Introduction

kpm is the KCL package manager. kpm downloads your KCL package's dependencies, compiles your KCL packages, makes packages, and uploads them to the kcl package registry.

Installation

Install KCL

kpm will call KCL compiler to compile the kcl program. Before using kpm, you need to ensure that KCL compiler is installed successfully.

For more information about how to install KCL.

Use the following command to ensure that you install KCL compiler successfully.

kcl -V

Install kpm

Go install

You can download kpm via go install.

go install kcl-lang.io/kpm@latest

If the command kpm can not be found after executing the above command, please refer to:

Download from GITHUB release page

You can also get kpm from the github release and set the kpm binary path to the environment variable PATH.

# KPM_INSTALLATION_PATH is the path of the `kpm` binary.
export PATH=$KPM_INSTALLATION_PATH:$PATH  

Use the following command to ensure that you install kpm successfully.

kpm --help

If you get the following output, you have successfully installed kpm and you can proceed to the following steps.

Quick Start

Init an empty kcl package

Create a new kcl package named my_package. And after we have created the package my_package, we need to go inside the package by cd my_package to complete the following operations.

kpm init my_package

kpm will create two kcl package configuration files: kcl.mod and kcl.mod.lock in the directory where you executed the command.

- my_package
      |- kcl.mod
      |- kcl.mod.lock
      |- # You can write your kcl program directly in this directory.

kcl.mod.lock is the file generated by kpm to fix the dependency version. Do not modify this file manually.

kpm initializes kcl.mod for an empty project as shown below:

[package]
name = "my_package"
edition = "0.0.1"
version = "0.0.1"

Add a dependency from Git Registry

You can then add a dependency to the current kcl package using the kpm add command

As shown below, taking the example of adding a package dependency named k8s, the version of the package is 1.27.

kpm add k8s:1.27

You can see that kpm adds the dependency you just added to kcl.mod.

[package]
name = "my_package"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
k8s = "1.27" # The dependency 'k8s' with version '1.27'

Write a kcl program that uses the content in k8s

Create the main.k file in the current package.

- my_package
      |- kcl.mod
      |- kcl.mod.lock
      |- main.k # Your KCL program.

And write the following into the main.k file.

# Import and use the contents of the external dependency 'k8s'.
import k8s.api.core.v1 as k8core

k8core.Pod {
    metadata.name = "web-app"
    spec.containers = [{
        name = "main-container"
        image = "nginx"
        ports = [{containerPort = 80}]
    }]
}

Use the kpm compile the kcl package

In the my_package directory, you can use kpm to compile the main.k file you just wrote.

kpm run

Supports OCI Registry

Beginning in kpm v0.2.0, you can use container registries with OCI support to store and share kcl packages.

For more information about OCI registry support.

Frequently Asked Questions (FAQ)

Q: I am using go install to install kpm, but I get the error command not found.
  • A: go install will install the binary file to $GOPATH/bin by default. You need to add $GOPATH/bin to the environment variable PATH.

Learn More

Documentation

Overview

kpm is a package management tool for kcl language.

Directories

Path Synopsis
pkg
api
cmd
env
git
oci
opt
test
e2e

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL