1.0.30 • Published 2 years ago

@byte-this/js-cli v1.0.30

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

js-cli-scripting

Streamline the process of creating a CLI using javascript / typescript.

For a demo + instructions on how to use: https://bytethisstore.com/articles/pg/js-cli

Getting Started

This readme will outline how to use this project. If you'd like to view an example, or just jump in, the example-cli.ts script contains a basic cli application with a few sample commands.

How To Use

  1. Create one or more commands for the program to use.
  2. Setup the application to use these commands with optional arguments for logging and requesting user input.
  3. Let the CliApplication class orchestrate the rest.
const TestCommand: iCliCommand = {
    name: "Test Command", //name for internal use
    displayText: "Print some test text to the console",
    tokens: ["test-print", "t-p"],
    requiredParams: [
        {
            name: "txt",
            displayText: "Text to print",
        },
    ],
    execute: async (
        params: { txt: string },
        cliOutputter: iCliOutputter
    ): Promise<void> => {
        cliOutputter.pushMessage("Txt from user ==>", params.txt);
    },
};

With this kind of definition, the program will request everything under requiredParams from the user, then execute the command and pass in those required commands.

Then, we setup our application runner:

const app = new CliApplication();

app.onQuit(() => {
    process.exit(0);
});

app.startApp(
    {
        startup: {
            initialOutput: "Welcome to the example application",
        },
    },
    new ArrayCliCommandsCollection(commands),
    [...process.argv].slice(2),
    new ConsoleOutputter(),
    new ConsoleUserInputRequestor(new ConsoleOutputter())
);
1.0.30

2 years ago

1.0.29

3 years ago

1.0.26

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago