UNPKG

clivo

Version:
144 lines (108 loc) 2.91 kB
# Clivo > **DISCLAIMER**: This project is not production ready. All versions below 1.0.0 should be considered unstable Simple CLI tools library ## Installation ### npm ```bash npm install clivo ``` ## Usage ### Parsing CLI arguments You can assign one or multiple variables to an option in any fashion: ```javascript 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`: ```javascript 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: ```javascript 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" }, ]); ``` ```javascript import { promptText } from "clivo"; const text = await promptText("Enter some text:"); ``` ```javascript import { promptNumber } from "clivo"; const number = await promptNumber("Enter a number:"); ``` ```javascript 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); ``` ```javascript 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`](CONTRIBUTING.md). Current maintainers: - Timur Moziev ([@TimurRin](https://github.com/TimurRin)) ## License Visit [`LICENSE`](LICENSE). ## Anca This repository is a part of [Anca](https://github.com/cinnabar-forge/anca) standardization project. Parts of the files and code are generated by Anca.