npm

This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@bizhermit/cli-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.0.0-rc.0 • Public • Published

CLI SDK

CLI SDK.

Install

npm i @bizhermit/cli-sdk

Example

import Cli, { getKeyArgs } from "@bizhermit/cli-sdk";

const func = async () => {
  const command = Cli.getArg();
  const dest = Cli.getKeyArg("-d");
  const excludes = getKeyArgs("-excludes");
  const text = await Cli.rl("input > ");
  await Cli.wl(text);
};
func();

Methods

  • rl(message?: string) => Promise<string>
    read input text line.

    const text = await rl("input > ");
    # console
    input > _
  • wl(message?: string) => void
    write text for console.

    wl("hoge");
    # console
    hoge
  • getArg(index?: number) => string | undefined
    get arg value.

    node cli hoge fuga piyo
    console.log(getArg()); // => "hoge"
    console.log(getArg(2)); // => "piyo"
    console.log(getArg(5)); // => undefined
  • getArgs() => Array<string>
    get arg values.

    node cli hoge fuga piyo
    console.log(getArgs()); // => ["hoge", "fuga", "piyo"]
  • hasKeyArg(key: string, subKey?: string) => boolean
    return has key arg.

    node cli --hoge
    console.log(hasKeyArg("--hoge")); // => true
    console.log(hasKeyArg("--fuga")); // => false
  • getKeyArg(key: string, subKey?: string) => string | undefined
    return arg value.

    node cli -hoge 1 2 3 4 -fuga 5 -piyo -foo
    console.log(getKeyArg("-hoge")); // => "1"
    console.log(getKeyArg("-fuga")); // => "5"
    console.log(getKeyArg("-piyo")); // => undefined
    console.log(getKeyArg("-none")); // => undefined
  • getKeyArgs(key: string, subKey?: string) => Array<string>
    return arg values. continue get value until value start with hyphen or end.

    node cli -hoge 1 2 3 -fuga 4 -piyo -foo
    console.log(getKeyArgs("-hoge")); // => ["1", "2", "3"]
    console.log(getKeyArgs("-fuga")); // => ["4"]
    console.log(getKeyArgs("-piyo")); // => []
    console.log(getKeyArgs("-foo"));  // => []
    console.log(getKeyArgs("-none")); // => []

Package Sidebar

Install

npm i @bizhermit/cli-sdk

Weekly Downloads

0

Version

2.0.0-rc.0

License

MIT

Unpacked Size

6.28 kB

Total Files

5

Last publish

Collaborators

  • bizhermit