Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kearisp/cli

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kearisp/cli

Command line interface for node.js

  • 2.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
95
increased by1.06%
Maintainers
0
Weekly downloads
 
Created
Source

@kearisp/cli

Description

Command line interface for node.js

Installation

npm install @kearisp/cli

Usage

Command

import {Cli} from "@kearisp/cli";


const cli = new Cli();

cli.command("foo")
    .action(() => {
        return "Foo result";
    });

cli.run(process.argv).then((res) => {
    process.stdout.write(res);
}).catch((err) => {
    process.stderr.write(err.message);
});

Command argument

<bar> - required argument

[bar] - not required argument

ℹ️ The spread is not stable now

<...bars> - required spread argument

[...bars] - not required spread argument

cli.command("foo <foo1> [foo2]")
    .action((input: CommandInput) => {
        return `Foo result, with arguments foo1=${input.argument("foo1")} foo2=${input.argument("foo2")}`;
    });
cli.command("bar [...bars]")
    .action((input: CommandInput) => {
        return "Bar result, Bars: " + input.argument("bars").join(", ");
    });

Command option

Types:

  • string
  • boolean
  • number
cli.command("foo")
    .option("bar", {
        type: "string",
        alias: "b"
    })
    .option("init", {
        type: "boolean",
        alias: "i"
    })
    .action((input: CommandInput) => {
        const {
            bar = "",
            init = false
        } = input.options();

        return `Foo result, with options bar=${bar} init=${init.toString()}`;
    });

Help

cli.command("foo")
    .help({
        description: "Foo description"
    })
    .option("option", {
        alias: "o",
        description: "Option description"
    })
    .action((input) => {
        const {
            option = ""
        } = input.options();

        return `option=${option}`;
    });
./cli.js foo -h

Response:

Help:
Foo description

--option, -o - Option description

Completion

cli.command("foo <bar>")
    .completion("bar", () => ["value1", "value2", "value3"])
    .action((input) => {
        const {
            bar = ""
        } = input.arguments();

        return `Foo result, with argument bar=${bar}`;
    });

cli.command("completion script")
    .action(() => {
        return cli.completionScript();
    });
Bash completion
source <(your-script.js completion script)

Keywords

FAQs

Package last updated on 07 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc