dscom
TypeScript icon, indicating that this package has built-in type declarations

1.0.51 • Public • Published

⛯ Divine Star Commander ⛯


GitHub top language GitHub repo size npm own loads GitHub latest release GitHub latest version GitHub last commit GitHub commit actiivty GitHub followers GitHub stars GitHub watchers

What Is It?

A tool for making command line tools with TypeScript or Javascript using Node.Js. It handles command line args, user input, help screen, colored messages, progress bars, and so on.

Why?

To make an easy chainable way to create a CLI fast. This provides a complete package for basic or advanced command line tools with many customizable options. The aim is to create an enjoyable and understadnable syntax that allows for efficent creation of command line user interfaces so developers can focus more on developing their applications.

How To Start

Start a new node project and install typescript and dscom .

  npm init
  npm i --save-dev typescript @types/node
  npm i --save dscom

Make sure to set the type to module in the package.json file also.

In your typescript config file set the types and target to be.

{
    "target": "ESNext", 
    "module": "ESNext", 
    "moduleResolution": "node", 
    "types": ["node", "dscom"]
}

And then you can simply require the dsCom object and define it as DSCommander.

See the code bellow to get started quickly. It shows the program setting up input params, logging some text, and then asking for the user's input and displaying their input.

Starter Code

import * as readline from 'node:readline';
import {DSCommander} from "../../dist/index.js";
const dsCom = new DSCommander(readline);
(async () => {
    //Add params to the program
    dsCom
    .addParam({
        flag: "a",
        name: "auto",
        desc: "Auto parse",
        type: "string[]",
        required: false,
        valueNeeded: true,
    })
    .addParam({
        flag: "b",
        name: "batch",
        desc: "Batch parse",
        type: "boolean",
        required: false,
        valueNeeded: true,
    })
    .addParam({
        flag: "c",
        name: "cache",
        desc: "Cache",
        type: "boolean",
        required: false,
        valueNeeded: true,
    });
    //Get the params input
    (await dsCom.initProgramInput()).$ENABLESHOW //enable use of show functions
        .defineSleepTime(100)
        //Check if they are set
        .ifParamIsset("a", (value: any, args: any) => {
            dsCom.showSleep(value, "Info");
        })
        .ifParamIsset("b", (value: any, args: any) => {
            dsCom.showSleep(value, "Info");
        })
        .ifParamIsset("c", (value: any, args: any) => {
            dsCom.showSleep(value, "Info");
        })
        .newScreen()
        .RAW.show(dsCom.getParam("a"))
        .show(dsCom.getParam("b"))
        .show(dsCom.getParam("c"))
        .sleep(1000)
        //Start a new screen
        .splashScreen()
        .BLINK.showSleep("BLINK")
        .INFO.showSleep("Some Info.")
        .GOOD.showSleep("Everything is fine.")
        .ERROR.showSleep("Everything is not fine.")
        .WARNING.showSleep("Something may be wrong.")
        .sleep(500)
        .CLEAR
        //Show message in boxes
        .BOX_IN.BOX_DASHED_HEAVY_4.BTAC.BR.G.show([
            "Divine Star Software",
            "Presents",
            "Divine Star Commander",
            "The Ultimate Command Line Interface",
            "Creation Tool",
        ])
        .sleep(500)
        .BOX_END.BOX_IN.BOX_TEXT_ALIGN_RIGHT.BR.B.show([
            "Divine Star Software",
            "Presents",
            "Divine Star Commander",
            "The Ultimate Command Line Interface",
            "Creation Tool",
        ])
        .BOX_END.sleep(500)
        //Add a progress and service bar
        .newProgressBar("test");
    await dsCom.incrementProgressBar("test", 100);
    dsCom.newServiceBar("test");
    (await dsCom.asyncSleep(3000))
        .destroyServiceBar("test")
        .newScreen()
        .showSleep("All good.", "Raw")
        .newScreen()
        //Get users input
        .show("Starting user input", "Info")
        .ask("enter name", "name", "string")
        .ask("enter num", "num", "number");
    (await dsCom.startPrompt())
        .showSleep(dsCom.getInput("name"), "Info")
        .restartPrompt()
        .ask("enter email", "email", "email")
        .ask("enter password", "pass", "password")
        .fail(true, "Password is not correct.", 3, () => {
            process.exit(0);
        })
        .ask("enter comment", "comment", "string");
    (await dsCom.startPrompt()).ifInputIsset("comment", (value: any) => {
        dsCom.INFO.show(value);
    });
})();

Package Sidebar

Install

npm i dscom

Weekly Downloads

1

Version

1.0.51

License

MIT

Unpacked Size

204 kB

Total Files

5

Last publish

Collaborators

  • lucasdamianjohnson