KScript docs
EN

Install and editors

Switching versions

Introduction

Sometimes one computer needs more than one version of KScript. An older project may be written for the release it started on, a library may need testing against the last few releases, or you may want to try a new release and go back if something breaks. kscript version keeps each version you ask for side by side, and the kscript on your PATH runs the right one for each command. Nothing is replaced, so switching back is instant and works offline.

To see which version runs where you are, and what chose it:

Shell
kscript version
Text
KScript 0.55.0
  Chosen by ........................................ the installed kscript
  Runs from ......................... /home/joan/.kscript/bin/kscript
  Installed kscript ......... 0.55.0 (/home/joan/.kscript/bin/kscript)

kscript --version still prints just the number (0.55.0), for scripts that read it.

Switching this computer

kscript version use picks the version every folder on this computer runs, unless a project asks for another. A version that isn't on the computer yet is downloaded first, and checked against its release's SHA256SUMS, the same way kscript update checks one:

CommandWhat it does
kscript version use 0.50.0Every command now runs KScript 0.50.0.
kscript --version0.50.0.
kscript version use latestBack to the newest release.
kscript --version0.55.0.

The second use asks GitHub nothing when the version is already here, so switching between versions you have works without a network.

Pinning a project

A project can say which version it is written for, so everyone who works on it, and its CI, runs the same one. kscript version pin writes it into the project's kscript.json and gets that version ready:

Shell
cd shop
kscript version pin 0.50   # the newest 0.50.x: 0.50.2 today
JSON
{
  "name": "shop",
  "kscript": "0.50"   // kscript version pin wrote this line
}

From then on, any kscript command in the project or a folder inside it runs KScript 0.50.2, and a kscript that doesn't have it yet downloads it the first time. The setting is described with the rest of kscript.json.

Pin a series, such as 0.50, to take bug-fix releases as they come out, and an exact release, such as 0.50.2, to never move until you say so. kscript version pin latest writes the newest release as an exact version ("0.55.0"), so the project doesn't move by itself when the next one comes out.

To stop pinning the project, so it runs the computer's version again:

CommandWhat it does
kscript version unpinTakes "kscript" out of kscript.json, and leaves its other settings and comments alone.

One command with another version

KSCRIPT_USE runs a command with a version without changing anything else. It wins over the project and the computer, which makes it the way to test a project against several releases in CI:

Shell
KSCRIPT_USE=0.49.0 kscript test   # this run only: kscript.json and the default stay as they are
YAML
# .github/workflows/test.yml: run the tests on the last three releases
strategy:
  matrix:
    kscript: ["0.53", "0.54", "0.55"]
steps:
  - run: curl -fsSL https://raw.githubusercontent.com/kylepantall/kscript/master/install.sh | sh
  - run: kscript test
    env:
      KSCRIPT_USE: ${{ matrix.kscript }}

Which version runs

The kscript on your PATH picks the version for each command, from the first of these that names one:

Asked for by Example Set with
KSCRIPT_USE KSCRIPT_USE=0.49.0 your shell or CI
the nearest kscript.json with a "kscript" setting "kscript": "0.50" kscript version pin
this computer's default 0.51.0 kscript version use
nothing: the installed kscript runs 0.55.0 the install script or kscript update

Each of them can name an exact release (0.50.2), a series (0.50, its newest release) or latest. For a series, a version already on the computer is used before asking GitHub: if you have 0.50.1 and the project says 0.50, it runs 0.50.1 until you run kscript version install 0.50 to get a newer one.

kscript version and kscript update always run with the installed kscript, whatever a project asks for, because they manage the versions themselves.

Listing and removing versions

kscript version list shows the versions on this computer, and which one runs where you are:

Shell
kscript version list
Text
  0.55.0 ............................................ the installed kscript
  0.51.0 ............................. runs here, this computer's default
  0.50.2 ........................................................

--available lists every release there is, newest first, and marks the ones you have:

Shell
kscript version list --available

kscript version install downloads a version without switching to it, such as before going offline, and kscript version remove deletes one you no longer need:

CommandWhat it does
kscript version install 0.50Keep the newest 0.50.x, ready to use.
kscript version remove 0.50.0Delete 0.50.0: name the exact version.

The computer's default can't be removed until you switch to another version, so the next command always has a version to run.

Where versions are kept

Each version lives in a folder of its own beside the installed kscript, with the libraries desktop windows need:

System Installed kscript Kept versions
Linux and macOS ~/.kscript/bin/kscript ~/.kscript/versions/0.50.2/kscript
Windows %LOCALAPPDATA%\Programs\kscript\kscript.exe %LOCALAPPDATA%\Programs\kscript\versions\0.50.2\kscript.exe

The default from kscript version use is the file versions/default. Deleting the versions folder removes every kept version and the default, and leaves the installed kscript as it was.