1.0.5 • Published 1 year ago

tsicli v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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 TypeNote
stringString
string[]String List (separated by comma ,)
numberNumber
number[]Number List (separated by comma ,)
booleanBoolean (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,
  },
});
1.0.5

1 year ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago