dscom
v1.0.51
Published
A tool to create command line applications.
Downloads
5
Maintainers
Readme
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
Vist The Wiki
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);
});
})();