Skip to content

cartanova-ai/tsicli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tsicli

TypeScirpt Interactive CLI Builder

Goal & Philisophy

tsicli can make it easy to manage complex arguments of CLI application.

tsicli is setup and operate through the following process.

  • Define types you can use in the arguments.
  • Define arguments.
  • Define runners matching with arguments you defined.
  • If input values can't fulfill the arguments, then tsicli provides autocomplete prompt (like fzf) .

Installation

# npm
$ npm install --save tsicli

# yarn
$ yarn add tsicli

Setup & Usage

import { tsicli } from "tsicli";

tsicli(process.argv, {
  /* Defining types */
  types: {
    "#name": "string",
    "#recordIds": "number[]",
    "#yesOrNo": "boolean",
  },
  /* Defining args */
  args: [
    ["practice", "name", "#name"],
    ["practice", "records", "#recordIds"],
    ["practice", "question", "#yesOrNo"],
    ["practice", "single"],
    ["action", "subAction1"],
    ["action", "subAction2"],
  ],
  /* Defining runners */
  runners: {
    practice_name,
    practice_records,
    practice_question,
    practice_single,
    action_subAction1,
    action_subAction2,
  },
});

Examples

no arguments

tsicli(process.argv, {
  /* Defining types */
  types: {},
  /* Defining args */
  args: [["practice", "single"]],
  /* Defining runners */
  runners: {
    practice_single,
  },
});

primitive arguments

tsicli(process.argv, {
  /* Defining types */
  types: {
    "#name": "string",
    "#recordIds": "number[]",
    "#yesOrNo": "boolean",
  },
  /* Defining args */
  args: [
    ["practice", "name", "#name"],
    ["practice", "records", "#recordIds"],
    ["practice", "question", "#yesOrNo"],
  ],
  /* Defining runners */
  runners: {
    practice_name,
    practice_records,
    practice_question,
  },
});
Primitive Type Note
string String
string[] String List (separated by comma ,)
number Number
number[] Number List (separated by comma ,)
boolean Boolean (it prompts y/n)

Customizing prompts

You can use PromptObj to type definition. For more details in PromptObj, you can find it prompts package document.

tsicli(process.argv, {
  /* Defining types */
  types: {
    "#smdId": {
      type: "autocomplete",
      name: "#smdId",
      message: "Please input #smdId",
      choices: [
        { title: "Brand", value: "Brand" },
        { title: "Category", value: "Category" },
        { title: "Product", value: "Product" },
      ],
    },
    "#recordIds": "number[]",
  },
  /* Defining args */
  args: [["fixture", "import", "#smdId", "#recordIds"]],
  /* Defining runners */
  runners: {
    fixture_import,
  },
});

About

TypeScirpt Interactive CLI Builder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published