Balena CLI Form Interpreter

5.0.1 · active · verified Wed Apr 22

resin-cli-form is a JavaScript/TypeScript library designed to interpret and execute declarative form definitions within command-line interfaces. It enables developers to construct interactive CLI forms with features like conditional questions using a `when` property, where subsequent questions are only presented if specific conditions based on prior answers are met. The current stable version is 5.0.1, released in February 2026. The project has undergone significant modernization in its recent major releases, notably switching from CoffeeScript to TypeScript, adopting ES Modules, and migrating to `async/await` in version 5.0.0. Its release cadence shows active development and maintenance, with major architectural shifts around 2025-2026. This library is a specialized tool for building structured, interactive CLI experiences, particularly within the Balena.io ecosystem, providing a robust abstraction for complex user input flows.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to run a declarative CLI form with conditional questions using `form.run`, including an example of the `when` property.

import { run } from 'resin-cli-form';

async function configureDevice() {
  try {
    const answers = await run([
      {
        message: 'Network Type',
        name: 'network',
        type: 'list',
        choices: ['ethernet', 'wifi']
      },
      {
        message: 'WiFi SSID',
        name: 'wifiSsid',
        type: 'input',
        when: { network: 'wifi' }
      },
      {
        message: 'WiFi Key',
        name: 'wifiKey',
        type: 'input',
        when: { network: 'wifi' }
      }
    ], {
      override: {
        // Example: pre-fill a value to skip the question
        // wifiSsid: process.env.DEFAULT_WIFI_SSID ?? ''
      }
    });
    console.log('Configuration complete. Answers:', answers);

    if (answers.network === 'wifi') {
      console.log(`Connecting to WiFi network: ${answers.wifiSsid} with key ${answers.wifiKey ? '*********' : '[no key provided]'}`);
    }

  } catch (error) {
    console.error('Form execution failed:', error);
  }
}

configureDevice();

view raw JSON →