Skip to content

cinnabar-forge/clivo

Repository files navigation

Clivo

DISCLAIMER: This project is not production ready. All versions below 1.0.0 should be considered unstable

Simple CLI tools library

Installation

npm

npm install clivo

Usage

Parsing CLI arguments

You can assign one or multiple variables to an option in any fashion:

import { parseCli } from "clivo";

const result = parseCli({
  args: [
    "node",
    "index.js",
    "burger-earl",
    "-t",
    "--order=burger",
    "cola",
    "-o=fries",
    "-o",
    "salad",
  ], // sample process.argv input
  options: [
    { name: "order", letter: "o" },
    { name: "takeout", letter: "t" },
  ],
});
// result = { _: [ 'burger-earl' ], takeout: [ 'yes' ], order: [ 'burger', 'cola', 'fries', 'salad' ] }

Equal Sign Values Only

Alternatively, you can set values with equal sign only using equalSignValuesOnly:

import { parseCli } from "clivo";

const result = parseCli({
  args: [
    "node",
    "index.js",
    "-t",
    "--order=burger=cola=fries=salad",
    "burger-earl",
  ], // sample process.argv input
  equalSignValuesOnly: true,
  options: [
    { name: "order", letter: "o" },
    { name: "takeout", letter: "t" },
  ],
});
// result = { takeout: [ 'yes' ], order: [ 'burger', 'cola', 'fries', 'salad' ], _: [ 'burger-earl' ] }

Prompt

Prompt the user for input in various ways:

import { promptOptions } from "clivo";

const choice = await promptOptions("Choose an option:", [
  { name: "opt1", label: "Option 1" },
  { name: "opt2", label: "Option 2" },
  { name: "opt3", label: "Option 3" },
]);
import { promptText } from "clivo";

const text = await promptText("Enter some text:");
import { promptNumber } from "clivo";

const number = await promptNumber("Enter a number:");
import { promptWorkflow } from "clivo";

const workflow = [
  { type: "text", message: "Enter your name" },
  { type: "number", message: "Enter your age" },
  {
    type: "options",
    message: "Choose a color",
    choices: [
      { name: "red", label: "Red" },
      { name: "green", label: "Green" },
      { name: "blue", label: "Blue" },
    ],
  },
];

const results = await promptWorkflow("Start workflow", workflow);
import { promptMenu } from "clivo";

await promptMenu("Main Menu", [
  {
    action: async () => console.log("Projects selected"),
    label: "Projects",
  },
  {
    action: async () => console.log("Workspaces selected"),
    label: "Workspaces",
  },
]);

Contributing

Visit CONTRIBUTING.md.

Current maintainers:

License

Visit LICENSE.

Anca

This repository is a part of Anca standardization project. Parts of the files and code are generated by Anca.